.NET

Reply
Valued Contributor
FRFR1426
Posts: 87
Registered: ‎04-05-2012
Message 1 of 7 (335 Views)
Accepted Solution

IntersectWith bug

335 Views, 6 Replies
01-20-2014 12:20 AM

A little quiz: how many intersections between this xline and this polyline?

 

Intersect.png

 

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).

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 -

*Expert Elite*
Alfred.NESWADBA
Posts: 9,216
Registered: ‎06-29-2007
Message 2 of 7 (321 Views)

Re: IntersectWith bug

01-20-2014 01:24 AM in reply to: FRFR1426

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 -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Contributor
FRFR1426
Posts: 87
Registered: ‎04-05-2012
Message 3 of 7 (316 Views)

Re: IntersectWith bug

01-20-2014 01:32 AM in reply to: Alfred.NESWADBA

Oh yes, I've forgotten to attach the drawing. Sorry.

Valued Contributor
FRFR1426
Posts: 87
Registered: ‎04-05-2012
Message 4 of 7 (313 Views)

Re: IntersectWith bug

01-20-2014 01:38 AM in reply to: FRFR1426

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. 

Valued Contributor
FRFR1426
Posts: 87
Registered: ‎04-05-2012
Message 5 of 7 (310 Views)

Re: IntersectWith bug

01-20-2014 01:43 AM in reply to: FRFR1426

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:

 

2014-01-20_104304.png

*Expert Elite*
Alfred.NESWADBA
Posts: 9,216
Registered: ‎06-29-2007
Message 6 of 7 (302 Views)

Re: IntersectWith bug

01-20-2014 02:00 AM in reply to: FRFR1426

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
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Contributor
FRFR1426
Posts: 87
Registered: ‎04-05-2012
Message 7 of 7 (299 Views)

Re: IntersectWith bug

01-20-2014 02:07 AM in reply to: Alfred.NESWADBA

 

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.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.