.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

IntersectWith bug

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
FRFR1426
986 Views, 6 Replies

IntersectWith bug

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

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
Tags (1)
6 REPLIES 6
Message 2 of 7
Alfred.NESWADBA
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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 7
FRFR1426
in reply to: Alfred.NESWADBA

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

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
Message 4 of 7
FRFR1426
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. 

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
Message 5 of 7
FRFR1426
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

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
Message 6 of 7
Alfred.NESWADBA
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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 7 of 7
FRFR1426
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.

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost