Getting all possible intersection points of multiple lines

Getting all possible intersection points of multiple lines

Anonymous
Not applicable
3,201 Views
3 Replies
Message 1 of 4

Getting all possible intersection points of multiple lines

Anonymous
Not applicable

Can it be possible to get all possible intersection points of multiple lines using Selection Sets or ObjectID collections by selecting lines?

 

Example this drawing below:

2.PNG

 

 

I wanna get the points indicated by the red circle. Can it be done?

0 Likes
Accepted solutions (1)
3,202 Views
3 Replies
Replies (3)
Message 2 of 4

_gile
Consultant
Consultant

Hi,

 

Yes, it's possible.

Have a look at the Curve.IntersectWith() method.

In your line collection, you'll have to check for intersections between each item and all the following ones. With 4 lines (l1, l2, l3, l4), you may search for intersections betwen l1 and l2, l1 and l3, l1 and l4, then l2 and l3 , l2 and l4, then l3 and l4 (this can asily be implemented with for loops).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 4

_gile
Consultant
Consultant
Accepted solution

Here's alittle sample

 

        [CommandMethod("CMD", CommandFlags.UsePickSet)]
        public void Cmd()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            var selResult = ed.GetSelection(new SelectionFilter(new[] { new TypedValue(0, "LINE") }));
            if (selResult.Status != PromptStatus.OK) return;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                var selection = selResult.Value;
                var lines = new Line[selection.Count];
                for (int i = 0; i < selection.Count; i++)
                {
                    lines[i] = (Line)tr.GetObject(selection[i].ObjectId, OpenMode.ForRead);
                }

                var space = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                var points = new Point3dCollection();

                for (int i = 0; i < lines.Length; i++)
                {
                    for (int j = i + 1; j < lines.Length; j++)
                    {
                        points.Clear();
                        lines[i].IntersectWith(lines[j], Intersect.OnBothOperands, points, new IntPtr(0), new IntPtr(0));
                        foreach (Point3d pt in points)
                        {
                            var point = new DBPoint(pt);
                            space.AppendEntity(point);
                            tr.AddNewlyCreatedDBObject(point, true);
                        }
                    }
                }
                tr.Commit();
            }
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 4

Anonymous
Not applicable
You did an array of lines, nice. Thanks man!
0 Likes