面域转多段线
面域转多段线,只支持直线和圆弧构成的面域转多段线,主要是圆弧的那个地方还是有点模糊,希望高手指点。另外提个问题,圆弧的标注如何控制标注在圆弧内。
private Polyline RegionToPolyline(Region reg)
{
DBObjectCollection segments = new DBObjectCollection();
reg.Explode(segments);
Polyline pl = new Polyline();
DBObject Fristobj = segments;
Curve FristCurve = (Curve)Fristobj;
Point3d FristPoint = FristCurve.StartPoint;
Point3d TmpPoint = FristCurve.EndPoint;
switch (FristCurve.GetType().Name)
{
case "Line":
Line line = (Line)FristCurve;
pl.AddVertexAt(0, new Point2d(line.StartPoint.X, line.StartPoint.Y), 0, 0, 0);
//TmpPoint = line.EndPoint;
break;
case "Arc":
Arc arc = (Arc) FristCurve;
double dltAng = arc.EndAngle - arc.StartAngle;
if (dltAng < 0.0) dltAng += Math.PI * 2; //圆弧的结束角比开始角大时
double bulge =Math.Tan(dltAng/4.0);
pl.AddVertexAt(0, new Autodesk.AutoCAD.Geometry.Point2d(arc.StartPoint.X, arc.StartPoint.Y), bulge,0, 0);
//TmpPoint = arc.EndPoint;
break;
}
var j = 1;
while (!TmpPoint.Equals(FristPoint))
{
for (int i = 1; i <= segments.Count-1; i++)
{
DBObject obj = segments;
Curve thisCurve = (Curve)obj;
switch (thisCurve.GetType().Name)
{
case "Line":
{
Line line = (Line)obj;
if (line.StartPoint.Equals(TmpPoint))
{
pl.AddVertexAt(j, new Point2d(line.StartPoint.X, line.StartPoint.Y), 0, 0, 0);
TmpPoint = line.EndPoint;
break;
}
if (line.EndPoint.Equals(TmpPoint))
{
pl.AddVertexAt(j, new Point2d(line.EndPoint.X, line.EndPoint.Y), 0, 0, 0);
TmpPoint = line.StartPoint;
break;
}
}
break;
case "Arc":
Arc arc = (Arc)obj;
if (arc.StartPoint.Equals(TmpPoint))
{
double dltAng = arc.EndAngle - arc.StartAngle;
if (dltAng < 0.0) dltAng += Math.PI * 2; //圆弧的结束角比开始角大时
double bulge = Math.Tan(dltAng / 4.0);
pl.AddVertexAt(0,
new Autodesk.AutoCAD.Geometry.Point2d(arc.StartPoint.X, arc.StartPoint.Y),
bulge, 0, 0);
j = j + 1;
pl.AddVertexAt(1, new Autodesk.AutoCAD.Geometry.Point2d(arc.EndPoint.X, arc.EndPoint.Y),
0, 0, 0);
TmpPoint = arc.EndPoint;
break;
}
if (arc.EndPoint.Equals(TmpPoint))
{
double dltAng = -1*(arc.EndAngle - arc.StartAngle);
// if (dltAng < 0.0) dltAng += Math.PI * 2; //圆弧的结束角比开始角大时
double bulge = dltAng; //Math.Tan(dltAng / 4.0);
pl.AddVertexAt(0,new Autodesk.AutoCAD.Geometry.Point2d(arc.EndPoint.X, arc.EndPoint.Y),
bulge, 0, 0);
j = j + 1;
pl.AddVertexAt(1, new Autodesk.AutoCAD.Geometry.Point2d(arc.StartPoint.X, arc.StartPoint.Y),
0, 0, 0);
TmpPoint = arc.StartPoint;
break;
}
break;
}
}
}
pl.Closed = true;
return pl;
} 我也很关心这个问题,不知楼主解决了没有。另有没有解决这个问题的lisp程序
页:
[1]