- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 csharp 于 2014-6-11 23:35 编辑
public static class AlgerbraicArea
{
public static double GetArea(Point2d pt1, Point2d pt2, Point2d pt3)
{
return (((pt2.X - pt1.X) * (pt3.Y - pt1.Y)) -
((pt3.X - pt1.X) * (pt2.Y - pt1.Y))) / 2.0;
}
public static double GetArea(this CircularArc2d arc)
{
double rad = arc.Radius;
double ang = arc.IsClockWise ?
arc.StartAngle - arc.EndAngle :
arc.EndAngle - arc.StartAngle;
return rad * rad * (ang - Math.Sin(ang)) / 2.0;
}
public static double GetArea(this Polyline pline)
{
CircularArc2d arc = new CircularArc2d();
double area = 0.0;
int last = pline.NumberOfVertices - 1;
Point2d p0 = pline.GetPoint2dAt(0);
if (pline.GetBulgeAt(0) != 0.0)
{
area += pline.GetArcSegment2dAt(0).GetArea();
}
for (int i = 1; i < last; i++)
{
area += GetArea(p0, pline.GetPoint2dAt(i), pline.GetPoint2dAt(i + 1));
if (pline.GetBulgeAt(i) != 0.0)
{
area += pline.GetArcSegment2dAt(i).GetArea(); ;
}
}
if ((pline.GetBulgeAt(last) != 0.0) && pline.Closed)
{
area += pline.GetArcSegment2dAt(last).GetArea();
}
return area;
}
}
[CommandMethod("OFIN")]
public void OffsetInside()
{
OffsetPolyline(true);
}
[CommandMethod("OFOUT")]
public void OffsetOutside()
{
OffsetPolyline(false);
}
private void OffsetPolyline(bool inside)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptDistanceOptions pdo =
new PromptDistanceOptions("\nSpecify the offset distance: ");
pdo.AllowNegative = false;
pdo.AllowZero = false;
PromptDoubleResult pdr = ed.GetDistance(pdo);
if (pdr.Status != PromptStatus.OK)
return;
double offsetDist = inside ? pdr.Value : -pdr.Value;
PromptEntityOptions peo = new PromptEntityOptions("\nSelect a polyline: ");
peo.SetRejectMessage("Selected object is not a polyline.");
peo.AddAllowedClass(typeof(Polyline), true);
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTableRecord btr =
(BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
while (true)
{
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK)
break;
Polyline pline = (Polyline)tr.GetObject(per.ObjectId, OpenMode.ForRead);
DBObjectCollection offsets =
pline.GetOffsetCurves(pline.GetArea() < 0.0 ? offsetDist : -offsetDist);
foreach (DBObject obj in offsets)
{
Entity ent = (Entity)obj;
btr.AppendEntity(ent);
tr.AddNewlyCreatedDBObject(ent, true);
db.TransactionManager.QueueForGraphicsFlush();
}
}
tr.Commit();
}
}
|
|