<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Bug with Entity.IntersectWith method in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/bug-with-entity-intersectwith-method/m-p/2641393#M66652</link>
    <description>Hello Tony,&lt;BR /&gt;
What I'm doing is traversing down a Civil3D alignment at each station, detecting &lt;BR /&gt;
if any plan view graphics would intersect with a line that is perpendicular &lt;BR /&gt;
at the station out a certain distance then doing some special coding. I've &lt;BR /&gt;
dropped all the problem entities down to plan Autocad entities and tested &lt;BR /&gt;
in plain Autocad 2010 and get the same result.&lt;BR /&gt;
&lt;BR /&gt;
This is working great except for a few places where intersections are detected &lt;BR /&gt;
where they don't exist. ADN said these show up sometimes when "Large Coordinates" &lt;BR /&gt;
are encountered. The Civil3D team now codes around this known bug by transforming &lt;BR /&gt;
copies of the objects in memory closer to the drawing origin (thus smaller &lt;BR /&gt;
coordinates) where the bug doesn't show itself.&lt;BR /&gt;
&lt;BR /&gt;
I've attached at dwg file that shows this behavior of Large Coordinates. &lt;BR /&gt;
The green line represents the station line and the yellow line is the plan &lt;BR /&gt;
graphic.&lt;BR /&gt;
&lt;BR /&gt;
Below is my method that takes in: a SelectionSet and the line representing &lt;BR /&gt;
the line perpendicular to the alignment at the current station&lt;BR /&gt;
It returns a ObjectIDCollection and Point3D collection of what and where &lt;BR /&gt;
it found intersections.&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
    Public Shared Sub GetIntersections(ByRef cPts As Point3dCollection, ByRef &lt;BR /&gt;
cObjs As ObjectIdCollection, ByVal ss As SelectionSet, ByVal db As Database, &lt;BR /&gt;
ByVal oLine As Line)&lt;BR /&gt;
        Dim ent As Autodesk.AutoCAD.DatabaseServices.Entity = Nothing&lt;BR /&gt;
        Dim tm As DBTransactionManager = db.TransactionManager&lt;BR /&gt;
        cObjs = New ObjectIdCollection&lt;BR /&gt;
        cPts = New Point3dCollection&lt;BR /&gt;
&lt;BR /&gt;
        Using ta As Transaction = tm.StartTransaction()&lt;BR /&gt;
            If Not ss Is Nothing Then&lt;BR /&gt;
                'see if the entities found intersect with the corridor frequency &lt;BR /&gt;
lines at the current station&lt;BR /&gt;
                For i As Integer = 0 To ss.Count&lt;BR /&gt;
                    Try&lt;BR /&gt;
                        ent = ta.GetObject(ss.Item(i).ObjectId, OpenMode.ForRead, &lt;BR /&gt;
False, True)&lt;BR /&gt;
                        Dim iPts As Point3dCollection = New Point3dCollection&lt;BR /&gt;
                        'create plane perpendicular to the alignment at the &lt;BR /&gt;
current station origin &lt;BR /&gt;
                        Dim xyPlane As Plane = New Plane(New Point3d(0, 0, &lt;BR /&gt;
0), New Vector3d(0, 0, 1))&lt;BR /&gt;
                        Dim int As Integer = 0&lt;BR /&gt;
                        Dim intPointer As IntPtr = int&lt;BR /&gt;
&lt;BR /&gt;
                        ent.IntersectWith(oLine, Intersect.OnBothOperands, &lt;BR /&gt;
xyPlane, iPts, System.IntPtr.Zero, System.IntPtr.Zero)&lt;BR /&gt;
                        If Not iPts Is Nothing Then 'intersection found&lt;BR /&gt;
                            For Each tPt As Point3d In iPts&lt;BR /&gt;
                                Dim bInserted As Boolean = False&lt;BR /&gt;
                                If cPts.Count &amp;gt; 0 Then&lt;BR /&gt;
                                    Dim j As Integer = 0&lt;BR /&gt;
                                    Dim sPt As Point3d = oLine.StartPoint&lt;BR /&gt;
                                    Dim tDist As Double = sPt.DistanceTo(tPt)&lt;BR /&gt;
                                    For j = 0 To cPts.Count&lt;BR /&gt;
                                        If tDist &amp;lt; sPt.DistanceTo(cPts(j)) &lt;BR /&gt;
Then&lt;BR /&gt;
                                            cPts.Insert(j, tPt)&lt;BR /&gt;
                                            cObjs.Insert(j, ent.ObjectId)&lt;BR /&gt;
                                            bInserted = True&lt;BR /&gt;
                                            Exit For&lt;BR /&gt;
                                        End If&lt;BR /&gt;
                                    Next&lt;BR /&gt;
                                End If&lt;BR /&gt;
                                If Not bInserted Then&lt;BR /&gt;
                                    cPts.Add(tPt)&lt;BR /&gt;
                                    cObjs.Add(ent.ObjectId)&lt;BR /&gt;
                                End If&lt;BR /&gt;
                            Next&lt;BR /&gt;
                        End If&lt;BR /&gt;
                    Catch&lt;BR /&gt;
                    End Try&lt;BR /&gt;
                Next&lt;BR /&gt;
            End If&lt;BR /&gt;
        End Using&lt;BR /&gt;
    End Sub&lt;BR /&gt;
{code}&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; {quote}&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; I'm detecting the intersection between a plane and a 3d line.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; {quote}&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; IntersectWith() operates on two entities.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; What kind of entity is the 'plane'?&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
&amp;gt; Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&amp;gt; http://www.acadxtabs.com&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&amp;gt;</description>
    <pubDate>Tue, 02 Mar 2010 17:55:56 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2010-03-02T17:55:56Z</dc:date>
    <item>
      <title>Bug with Entity.IntersectWith method</title>
      <link>https://forums.autodesk.com/t5/net-forum/bug-with-entity-intersectwith-method/m-p/2641388#M66647</link>
      <description>I've encountered a known bug with Autocad where the entity.intersectwith &lt;BR /&gt;
method returns intersection points where no intersection exists. (this has &lt;BR /&gt;
been verified via ADN: CR#662189). I'm detecting the intersection between &lt;BR /&gt;
a plane and a 3d line.&lt;BR /&gt;
&lt;BR /&gt;
Before I pull out the old geometry books to write my own methods, does anyone &lt;BR /&gt;
know of any work arounds for this problem? Of course at this point I'm in &lt;BR /&gt;
a time crunch or I wouldn't bring it up.&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Mike</description>
      <pubDate>Mon, 01 Mar 2010 17:49:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/bug-with-entity-intersectwith-method/m-p/2641388#M66647</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-03-01T17:49:18Z</dc:date>
    </item>
    <item>
      <title>Re: Bug with Entity.IntersectWith method</title>
      <link>https://forums.autodesk.com/t5/net-forum/bug-with-entity-intersectwith-method/m-p/2641389#M66648</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Here's a way using vectors dot product.&lt;BR /&gt;
&lt;BR /&gt;
{code}private bool IntersectPlaneLine(Plane plane, Line3d line, out Point3d intersPt)&lt;BR /&gt;
        {&lt;BR /&gt;
            Point3d org = plane.PointOnPlane;&lt;BR /&gt;
            Vector3d normal = plane.Normal;&lt;BR /&gt;
            Point3d pt = line.PointOnLine;&lt;BR /&gt;
            Vector3d dir = line.Direction;&lt;BR /&gt;
            double scl = dir.DotProduct(normal);&lt;BR /&gt;
            if (scl == 0)&lt;BR /&gt;
                return false;&lt;BR /&gt;
            scl = normal.DotProduct(pt - org) / scl;&lt;BR /&gt;
            intersPt = pt + dir.Negate().MultiplyBy(scl);&lt;BR /&gt;
            return true;&lt;BR /&gt;
        }{code}</description>
      <pubDate>Mon, 01 Mar 2010 19:07:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/bug-with-entity-intersectwith-method/m-p/2641389#M66648</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2010-03-01T19:07:36Z</dc:date>
    </item>
    <item>
      <title>Re: Bug with Entity.IntersectWith method</title>
      <link>https://forums.autodesk.com/t5/net-forum/bug-with-entity-intersectwith-method/m-p/2641390#M66649</link>
      <description>Hello _gile,&lt;BR /&gt;
Thanks I'll give it a try.&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; Hi,&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Here's a way using vectors dot product.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; {code}private bool IntersectPlaneLine(Plane plane, Line3d line, out&lt;BR /&gt;
&amp;gt; Point3d intersPt)&lt;BR /&gt;
&amp;gt; {&lt;BR /&gt;
&amp;gt; Point3d org = plane.PointOnPlane;&lt;BR /&gt;
&amp;gt; Vector3d normal = plane.Normal;&lt;BR /&gt;
&amp;gt; Point3d pt = line.PointOnLine;&lt;BR /&gt;
&amp;gt; Vector3d dir = line.Direction;&lt;BR /&gt;
&amp;gt; double scl = dir.DotProduct(normal);&lt;BR /&gt;
&amp;gt; if (scl == 0)&lt;BR /&gt;
&amp;gt; return false;&lt;BR /&gt;
&amp;gt; scl = normal.DotProduct(pt - org) / scl;&lt;BR /&gt;
&amp;gt; intersPt = pt + dir.Negate().MultiplyBy(scl);&lt;BR /&gt;
&amp;gt; return true;&lt;BR /&gt;
&amp;gt; }{code}</description>
      <pubDate>Mon, 01 Mar 2010 19:12:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/bug-with-entity-intersectwith-method/m-p/2641390#M66649</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-03-01T19:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: Bug with Entity.IntersectWith method</title>
      <link>https://forums.autodesk.com/t5/net-forum/bug-with-entity-intersectwith-method/m-p/2641391#M66650</link>
      <description>{quote}&lt;BR /&gt;
&lt;BR /&gt;
I'm detecting the intersection between a plane and a 3d line.&lt;BR /&gt;
&lt;BR /&gt;
{quote}&lt;BR /&gt;
&lt;BR /&gt;
IntersectWith() operates on two entities.&lt;BR /&gt;
&lt;BR /&gt;
What kind of entity is the 'plane'?&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");</description>
      <pubDate>Mon, 01 Mar 2010 20:00:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/bug-with-entity-intersectwith-method/m-p/2641391#M66650</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-03-01T20:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: Bug with Entity.IntersectWith method</title>
      <link>https://forums.autodesk.com/t5/net-forum/bug-with-entity-intersectwith-method/m-p/2641392#M66651</link>
      <description>Reading Tony's reply I realise I perhaps misunderstood the request.&lt;BR /&gt;
I read 3d line and plane, so I thaught you wanted the intersecion between a Line3d(unbounded) and a Plane (infinite), maybe due to my poor English...&lt;BR /&gt;
The method I gave works this way.&lt;BR /&gt;
It will always return true exept if the Line3d is parallel to the plane.</description>
      <pubDate>Mon, 01 Mar 2010 20:33:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/bug-with-entity-intersectwith-method/m-p/2641392#M66651</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2010-03-01T20:33:09Z</dc:date>
    </item>
    <item>
      <title>Re: Bug with Entity.IntersectWith method</title>
      <link>https://forums.autodesk.com/t5/net-forum/bug-with-entity-intersectwith-method/m-p/2641393#M66652</link>
      <description>Hello Tony,&lt;BR /&gt;
What I'm doing is traversing down a Civil3D alignment at each station, detecting &lt;BR /&gt;
if any plan view graphics would intersect with a line that is perpendicular &lt;BR /&gt;
at the station out a certain distance then doing some special coding. I've &lt;BR /&gt;
dropped all the problem entities down to plan Autocad entities and tested &lt;BR /&gt;
in plain Autocad 2010 and get the same result.&lt;BR /&gt;
&lt;BR /&gt;
This is working great except for a few places where intersections are detected &lt;BR /&gt;
where they don't exist. ADN said these show up sometimes when "Large Coordinates" &lt;BR /&gt;
are encountered. The Civil3D team now codes around this known bug by transforming &lt;BR /&gt;
copies of the objects in memory closer to the drawing origin (thus smaller &lt;BR /&gt;
coordinates) where the bug doesn't show itself.&lt;BR /&gt;
&lt;BR /&gt;
I've attached at dwg file that shows this behavior of Large Coordinates. &lt;BR /&gt;
The green line represents the station line and the yellow line is the plan &lt;BR /&gt;
graphic.&lt;BR /&gt;
&lt;BR /&gt;
Below is my method that takes in: a SelectionSet and the line representing &lt;BR /&gt;
the line perpendicular to the alignment at the current station&lt;BR /&gt;
It returns a ObjectIDCollection and Point3D collection of what and where &lt;BR /&gt;
it found intersections.&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
    Public Shared Sub GetIntersections(ByRef cPts As Point3dCollection, ByRef &lt;BR /&gt;
cObjs As ObjectIdCollection, ByVal ss As SelectionSet, ByVal db As Database, &lt;BR /&gt;
ByVal oLine As Line)&lt;BR /&gt;
        Dim ent As Autodesk.AutoCAD.DatabaseServices.Entity = Nothing&lt;BR /&gt;
        Dim tm As DBTransactionManager = db.TransactionManager&lt;BR /&gt;
        cObjs = New ObjectIdCollection&lt;BR /&gt;
        cPts = New Point3dCollection&lt;BR /&gt;
&lt;BR /&gt;
        Using ta As Transaction = tm.StartTransaction()&lt;BR /&gt;
            If Not ss Is Nothing Then&lt;BR /&gt;
                'see if the entities found intersect with the corridor frequency &lt;BR /&gt;
lines at the current station&lt;BR /&gt;
                For i As Integer = 0 To ss.Count&lt;BR /&gt;
                    Try&lt;BR /&gt;
                        ent = ta.GetObject(ss.Item(i).ObjectId, OpenMode.ForRead, &lt;BR /&gt;
False, True)&lt;BR /&gt;
                        Dim iPts As Point3dCollection = New Point3dCollection&lt;BR /&gt;
                        'create plane perpendicular to the alignment at the &lt;BR /&gt;
current station origin &lt;BR /&gt;
                        Dim xyPlane As Plane = New Plane(New Point3d(0, 0, &lt;BR /&gt;
0), New Vector3d(0, 0, 1))&lt;BR /&gt;
                        Dim int As Integer = 0&lt;BR /&gt;
                        Dim intPointer As IntPtr = int&lt;BR /&gt;
&lt;BR /&gt;
                        ent.IntersectWith(oLine, Intersect.OnBothOperands, &lt;BR /&gt;
xyPlane, iPts, System.IntPtr.Zero, System.IntPtr.Zero)&lt;BR /&gt;
                        If Not iPts Is Nothing Then 'intersection found&lt;BR /&gt;
                            For Each tPt As Point3d In iPts&lt;BR /&gt;
                                Dim bInserted As Boolean = False&lt;BR /&gt;
                                If cPts.Count &amp;gt; 0 Then&lt;BR /&gt;
                                    Dim j As Integer = 0&lt;BR /&gt;
                                    Dim sPt As Point3d = oLine.StartPoint&lt;BR /&gt;
                                    Dim tDist As Double = sPt.DistanceTo(tPt)&lt;BR /&gt;
                                    For j = 0 To cPts.Count&lt;BR /&gt;
                                        If tDist &amp;lt; sPt.DistanceTo(cPts(j)) &lt;BR /&gt;
Then&lt;BR /&gt;
                                            cPts.Insert(j, tPt)&lt;BR /&gt;
                                            cObjs.Insert(j, ent.ObjectId)&lt;BR /&gt;
                                            bInserted = True&lt;BR /&gt;
                                            Exit For&lt;BR /&gt;
                                        End If&lt;BR /&gt;
                                    Next&lt;BR /&gt;
                                End If&lt;BR /&gt;
                                If Not bInserted Then&lt;BR /&gt;
                                    cPts.Add(tPt)&lt;BR /&gt;
                                    cObjs.Add(ent.ObjectId)&lt;BR /&gt;
                                End If&lt;BR /&gt;
                            Next&lt;BR /&gt;
                        End If&lt;BR /&gt;
                    Catch&lt;BR /&gt;
                    End Try&lt;BR /&gt;
                Next&lt;BR /&gt;
            End If&lt;BR /&gt;
        End Using&lt;BR /&gt;
    End Sub&lt;BR /&gt;
{code}&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; {quote}&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; I'm detecting the intersection between a plane and a 3d line.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; {quote}&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; IntersectWith() operates on two entities.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; What kind of entity is the 'plane'?&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
&amp;gt; Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&amp;gt; http://www.acadxtabs.com&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&amp;gt;</description>
      <pubDate>Tue, 02 Mar 2010 17:55:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/bug-with-entity-intersectwith-method/m-p/2641393#M66652</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-03-02T17:55:56Z</dc:date>
    </item>
  </channel>
</rss>

