- 积分
- 72
- 明经币
- 个
- 注册时间
- 2012-7-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
面域转多段线,只支持直线和圆弧构成的面域转多段线,主要是圆弧的那个地方还是有点模糊,希望高手指点。
另外提个问题,圆弧的标注如何控制标注在圆弧内。
private Polyline RegionToPolyline(Region reg)
{
DBObjectCollection segments = new DBObjectCollection();
reg.Explode(segments);
Polyline pl = new Polyline();
DBObject Fristobj = segments[0];
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[i];
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;
} |
|