对于多段的单折线实体,我希望在每个交叉点创建一个间隙。理想情况下,需要能够指定间隙距离。
简单示例:
更复杂的示例:
基本代码大纲:
1 .从编辑器中获取折线实体。将多段线分解成单独的多段线。相互测试每条折线的交点(交点必须是“真实的”,例如,不能在两个连续的线段之间)
4。在每个特定半径的交叉点创建临时圆。对于每条折线,“修剪”圆内的内容*(从这一点开始有困难)*,从而删除交点
6。删除临时圆圈。对于每条现有的折线,如果可能的话,可以将它们连接起来,这样做
我面临的最大问题是在圆的交点处修剪每条折线-我只是不确定如何在代码中实现这一点
最终我希望能够将圆弧合并到折线中。
到目前为止我的代码(到第4点为止):
- [CommandMethod("SelfIntersectPline")]
- public static void SelfIntersectPline()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Editor ed = doc.Editor;
- PromptEntityOptions peo = new PromptEntityOptions(
- "\nSelect Curve: ");
- peo.SetRejectMessage("\nMust be a Curve...");
- PromptEntityResult per = ed.GetEntity(peo);
- if (per.Status != PromptStatus.OK) return;
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- BlockTableRecord ms = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
- //get curve and explode into entities, store curves in entities dbobjectcollection
- Curve curve = per.ObjectId.GetObject(OpenMode.ForRead) as Curve;
- DBObjectCollection origDBObjects = new DBObjectCollection();
- curve.Explode(origDBObjects);
- //erase original curve
- var originalCurve = (Entity)tr.GetObject(curve.ObjectId, OpenMode.ForWrite);
- originalCurve.Erase();
- //create temp dbcollection for circle entities
- DBObjectCollection circleDBObjects = new DBObjectCollection();
- //convert exploded curve entities to polylines
- for (int i = origDBObjects.Count - 1; i >= 0; i--)
- {
- Curve curveObj = origDBObjects[i] as Curve;
- origDBObjects.Add(ConvertToPolyline(curveObj));
- origDBObjects.RemoveAt(i);
- }
- //iterate through each polyline within entities collection
- for (int i = 0; i < origDBObjects.Count; ++i)
- {
- for (int j = i + 1; j < origDBObjects.Count; ++j)
- {
- Polyline pl1 = origDBObjects[i] as Polyline;
- Polyline pl2 = origDBObjects[j] as Polyline;
- Point3dCollection points = new Point3dCollection();
- //test for intersection(s)
- pl1.IntersectWith(pl2, Intersect.OnBothOperands, points, IntPtr.Zero, IntPtr.Zero);
- //validation for intersections
- foreach (Point3d point in points)
- {
- // Skip the start/end points since they are connected vertices
- if (point == pl1.StartPoint ||
- point == pl1.EndPoint)
- {
- if (point == pl2.StartPoint ||
- point == pl2.EndPoint)
- {
- // If two consecutive segments, then skip
- if (j == i + 1)
- {
- continue;
- }
- }
- }
- //if genuine intersection detected, create temporary circle of specified radius at intersection
- foreach (Point3d pt3d in points)
- {
- Circle c = new Circle();
- c.Center = pt3d;
- c.Radius = 0.5;
- circleDBObjects.Add(c);
- }
- }
- }
- }
本帖以下内容被隐藏保护;需要你回复后,才能看到! 游客,如果您要查看本帖隐藏内容请 回复 |