A little quiz: how many intersections between this xline and this polyline?
AutoCAD answer: 3
Test code:
[CommandMethod("TESTINTERSECTWITH")] public void TestIntersectWith() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; var peo = new PromptEntityOptions("\nSelect the Xline: "); peo.SetRejectMessage("\nThis entity is not an Xline."); peo.AddAllowedClass(typeof(Xline), true); PromptEntityResult per = ed.GetEntity(peo); if (PromptStatus.Cancel == per.Status) return; ObjectId xlineId = per.ObjectId; peo.Message = "\nSelect the polyline: "; peo.SetRejectMessage("\nThis entity is not a polyline."); peo.AddAllowedClass(typeof(Polyline), true); per = ed.GetEntity(peo); if (PromptStatus.Cancel == per.Status) return; ObjectId plineId = per.ObjectId; using (Transaction tr = db.TransactionManager.StartTransaction()) { var xline = (Xline) tr.GetObject(xlineId, OpenMode.ForRead); var pline = (Polyline)tr.GetObject(plineId, OpenMode.ForRead); var intersections = new Point3dCollection(); xline.IntersectWith(pline, Intersect.OnBothOperands, intersections, IntPtr.Zero, IntPtr.Zero); var currentSpace = (BlockTableRecord) tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); foreach (Point3d intersection in intersections) { var p = new DBPoint(intersection); currentSpace.AppendEntity(p); tr.AddNewlyCreatedDBObject(p, true); } tr.Commit(); } }
IntersectWith finds two points at the north intersection (tested on AutoCAD 2013 & 2014).
Solved! Go to Solution.
Solved by Alfred.NESWADBA. Go to Solution.
Hi,
can we have the drawing too?
I guess it depends on the polyline and where the ray crosses (how close to an existing vertex).
- alfred -
Oh yes, I've forgotten to attach the drawing. Sorry.
There is a vertex near the intersection. The distance is equal to 0.007 drawing units. It is a lot bigger than the precision used by AutoCAD.
In fact, there is one intersection with the segment of the polyline where the line passes and one other with the next segment of the polyline:
Hi,
sorry to say, but I searched all the time now for a thread where I mentioned that, it's some years ago and exactly what you found out ... the extension of a segment is another intersection point (and this didn't start with 2013, it was the same issue releases earlier too).
You can now (time consuming, I know) verify each intersection point if it's on the curve or not (distance between returned intersection point and the Curve.GetClosestPointTo(xxx)).
- alfred -
Alfred.NESWADBA a écrit :
You can now (time consuming, I know) verify each intersection point if it's on the curve or not (distance between returned intersection point and the Curve.GetClosestPointTo(xxx)).
Yes I know. In my case, I've found another way to resolve this problem. In fact, it's the tolerance used which is too large.