CAD C#二次開發 圓和圓弧轉Polyline線
阿新 • • 發佈:2019-02-07
//假設現有實體ent Entity ent = item as Entity; //如果實體為圓弧 if (ent is Arc) { Arc arc = ent as Arc; double R = arc.Radius; Point3d startPoint = arc.StartPoint; Point3d endPoint = arc.EndPoint; Point2d p1, p2; p1 = new Point2d(startPoint.X, startPoint.Y); p2 = new Point2d(endPoint.X, endPoint.Y); Double L = p1.GetDistanceTo(p2); double H = R - Math.Sqrt(R * R - L * L / 4); Polyline poly = new Polyline(); poly.AddVertexAt(0, p1, 2 * H / L, 0, 0); poly.AddVertexAt(1, p2, 0, 0, 0); poly.Color = reg.Color; poly.LineWeight = reg.LineWeight; poly.LinetypeId = reg.LinetypeId; btr.AppendEntity(poly); trans.AddNewlyCreatedDBObject(poly, true); } //如果實體為圓 else if (ent is Circle) { Circle cir = ent as Circle; double r = cir.Radius; Point3d cc = cir.Center; Point2d p1 = new Point2d(cc.X + r, cc.Y); Point2d p2 = new Point2d(cc.X - r, cc.Y); Polyline poly = new Polyline(); poly.AddVertexAt(0, p1, 1, 0, 0); poly.AddVertexAt(1, p2, 1, 0, 0); poly.AddVertexAt(2, p1, 1, 0, 0); poly.Color = reg.Color; poly.LineWeight = reg.LineWeight; poly.LinetypeId = reg.LinetypeId; btr.AppendEntity(poly); trans.AddNewlyCreatedDBObject(poly, true); }