CAD中圆可转为带有凸度的多段线以方便后期数据计算、处理,效果如下:
白色为圆,红色为转换后的多段线(为区分,已手工偏移多段线)
public static void XX()
{
var curves = Z.db.SelectEntities<Entity>();
foreach (var item in curves)
{
if (item is Circle)
{
Circle temp = (Circle)item;
Point3d pt = temp.Center;
double leftx = pt.X - temp.Radius;
double rightx = pt.X + temp.Radius;
double topx = pt.X;
double bottomx = pt.X;
double lefty = pt.Y;
double righty = pt.Y;
double topy = pt.Y + temp.Radius;
double bottomy = pt.Y - temp.Radius;
Point2d left = new Point2d(leftx, lefty);
Point2d right = new Point2d(rightx, righty);
Point2d top = new Point2d(topx, topy);
Point2d bottom = new Point2d(bottomx, bottomy);
Polyline pl = new Polyline();
pl.AddVertexAt(0, bottom, 1, 0, 0);
pl.AddVertexAt(1, top, 1, 0, 0);
pl.AddVertexAt(2, bottom, 0, 0, 0);
pl.ColorIndex = 1;
Z.db.AddEntityToModeSpace(pl);
pl.Highlight();
// Debugger.Break();
}
//else
//{
// Z.db.Erase(item);
//}
}
}
圆弧转多段线方法如下:
public void XX()
{
List<Curve> ents = Z.db.SelectEntities<Curve>();
foreach (var item in ents)
{
if (item is Arc arc)
{
double ang = 0;
if (arc.StartAngle > arc.EndAngle)
{
double endangle;
endangle = arc.EndAngle + 2 * Math.PI;
ang = endangle - arc.StartAngle;
}
else
{
ang = arc.EndAngle - arc.StartAngle;
}
//Debugger.Break();
ang = ang/4;
double td = Math.Tan(ang);
// arc.Spline;
Polyline pl = new Polyline();
// if arc.StartAngle
pl.AddVertexAt(0,new Point2d(item.StartPoint.X,item.StartPoint.Y),td,0,0);
pl.AddVertexAt(1,new Point2d(item.EndPoint.X, item.EndPoint.Y),0, 0, 0);
pl.ColorIndex = 1;
Z.db.AddEntityToModeSpace(pl);
}
}
foreach (var item in ents)
{
if (item is Arc arc1)
{
Z.db.Erase(arc1);
}
}
}