<?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: [VB.net] Calculate intersection between 2 lines in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/vb-net-calculate-intersection-between-2-lines/m-p/3704180#M52443</link>
    <description>&lt;P&gt;See &lt;A href="https://forums.autodesk.com/t5/NET/IntersectWith-became-obsolete-in-2012/m-p/3133690#M24822" target="_self"&gt;THIS&lt;/A&gt;&amp;nbsp;post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IntPtr.Zero is needed in place of the 0's&lt;/P&gt;</description>
    <pubDate>Mon, 19 Nov 2012 14:50:53 GMT</pubDate>
    <dc:creator>Jeff_M</dc:creator>
    <dc:date>2012-11-19T14:50:53Z</dc:date>
    <item>
      <title>[VB.net] Calculate intersection between 2 lines</title>
      <link>https://forums.autodesk.com/t5/net-forum/vb-net-calculate-intersection-between-2-lines/m-p/3704164#M52442</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using AutoCAD 2013 x64 and VS2012 Express with ObjectARX 2013.&lt;/P&gt;&lt;P&gt;Now I want to calculate the (projected) intersection point of 2 (intersecting) lines in vb.net&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After selecting the lines I have this code:&lt;/P&gt;&lt;PRE&gt;line1.IntersectWith(line2, Intersect.OnBothOperands, intpts, 0, 0)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In Visual studio express 2012 I get the following warning for the above line of code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;warning BC40000: 'Public Sub IntersectWith(entityPointer As Autodesk.AutoCAD.DatabaseServices.Entity, intersectType As Autodesk.AutoCAD.DatabaseServices.Intersect, points As Autodesk.AutoCAD.Geometry.Point3dCollection, thisGraphicSystemMarker As Long, otherGraphicSystemMarker As Long)' is obsolete: 'Use the overload taking IntPtr instead.'.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;BR /&gt;&lt;/EM&gt;So, if I'm reading this correctly, this method is outdated and I should use an other method to calculate the intersection.&lt;/P&gt;&lt;P&gt;But I really don't know what &lt;EM&gt;'Use the overload taking IntPtr instead' &lt;/EM&gt;means.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have searched on a lot of forums, but I can't seem to find an answer. All the answers I could find were essentially the same function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One of the things I found is a function that contains this line of code:&lt;/P&gt;&lt;PRE&gt;Dim inters As Point3d = line1.IntersectWith(line2)(0)&lt;/PRE&gt;&lt;P&gt;This one looks almost the same, but doesn't give me the warning when I compile the code, but this method crashes AutoCAD when there is no intersection between the lines. This is despite a try catch block that surrounds the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anybody point me in the right direction?&lt;/P&gt;&lt;P&gt;For now I just want to use lines, but I need to expand the code so it will also work with circles, arcs and polylines.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Nov 2012 14:41:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/vb-net-calculate-intersection-between-2-lines/m-p/3704164#M52442</guid>
      <dc:creator>R.Gerritsen4967</dc:creator>
      <dc:date>2012-11-19T14:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: [VB.net] Calculate intersection between 2 lines</title>
      <link>https://forums.autodesk.com/t5/net-forum/vb-net-calculate-intersection-between-2-lines/m-p/3704180#M52443</link>
      <description>&lt;P&gt;See &lt;A href="https://forums.autodesk.com/t5/NET/IntersectWith-became-obsolete-in-2012/m-p/3133690#M24822" target="_self"&gt;THIS&lt;/A&gt;&amp;nbsp;post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IntPtr.Zero is needed in place of the 0's&lt;/P&gt;</description>
      <pubDate>Mon, 19 Nov 2012 14:50:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/vb-net-calculate-intersection-between-2-lines/m-p/3704180#M52443</guid>
      <dc:creator>Jeff_M</dc:creator>
      <dc:date>2012-11-19T14:50:53Z</dc:date>
    </item>
    <item>
      <title>Re: [VB.net] Calculate intersection between 2 lines</title>
      <link>https://forums.autodesk.com/t5/net-forum/vb-net-calculate-intersection-between-2-lines/m-p/3704212#M52444</link>
      <description>&lt;P&gt;Wow that was quick!!!&lt;/P&gt;&lt;P&gt;And it works too! Thanks a lot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But can you(or anybody else) tell me what the difference is between the two lines of code I posted?&lt;/P&gt;&lt;P&gt;I mean, to my eye it is the same method, but why don't I get a warning on the second line of code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The second line of code crashes my AutoCAD when the picked lines have no intersectionpoints.&lt;/P&gt;&lt;P&gt;Would it better to check if the lines are parallel before the intersection check?&lt;/P&gt;&lt;P&gt;That's what I have done now to avoid the crash, but I'm sure there is another (maybe better) way.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Nov 2012 15:05:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/vb-net-calculate-intersection-between-2-lines/m-p/3704212#M52444</guid>
      <dc:creator>R.Gerritsen4967</dc:creator>
      <dc:date>2012-11-19T15:05:41Z</dc:date>
    </item>
    <item>
      <title>Re: [VB.net] Calculate intersection between 2 lines</title>
      <link>https://forums.autodesk.com/t5/net-forum/vb-net-calculate-intersection-between-2-lines/m-p/3704592#M52445</link>
      <description>&lt;P&gt;Not sure about that line of code, as it should give an error at compile time. Unless there was, at one time, on overload method which only accepted the one argument (perhaps the old COM method allowed optional arguments?)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you find a response which answers your question, &lt;FONT color="#008000"&gt;please be sure to accept the actual post which helped you as the solution&lt;/FONT&gt;. This will help future searchers quickly find answers to their own questions. Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 19 Nov 2012 18:04:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/vb-net-calculate-intersection-between-2-lines/m-p/3704592#M52445</guid>
      <dc:creator>Jeff_M</dc:creator>
      <dc:date>2012-11-19T18:04:19Z</dc:date>
    </item>
    <item>
      <title>Re: [VB.net] Calculate intersection between 2 lines</title>
      <link>https://forums.autodesk.com/t5/net-forum/vb-net-calculate-intersection-between-2-lines/m-p/3705276#M52446</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think the second line of code uses the Autodesk.AutoCAD.Geometry.LinearEntity3d.IntersectWith() method instead of Autodesk.AutoCAD.DatabaseServices.Entity.IntersectWith() one.&lt;/P&gt;&lt;P&gt;Usiing the Autodesk.AutoCAD.Geometry.LinearEntity3d (or Entity2d) underlaying derived classes for geometry calculation is cheaper (it's the way the API internaly does).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The LinearEntity3d.IntersectWith() method return a Point3d array or null (Nothing) if there's none intersection. to avoid the exception, you have to check if the returned value is not null (Nothing), IOW if the lines are parallel (or colinear).&lt;/P&gt;</description>
      <pubDate>Tue, 20 Nov 2012 07:12:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/vb-net-calculate-intersection-between-2-lines/m-p/3705276#M52446</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2012-11-20T07:12:40Z</dc:date>
    </item>
    <item>
      <title>Re: [VB.net] Calculate intersection between 2 lines</title>
      <link>https://forums.autodesk.com/t5/net-forum/vb-net-calculate-intersection-between-2-lines/m-p/3705314#M52447</link>
      <description>&lt;P&gt;Hi &lt;SPAN&gt;&lt;A href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424" target="_self"&gt;&lt;SPAN&gt;_gile&lt;/SPAN&gt;&lt;/A&gt;&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your answer.&lt;/P&gt;&lt;P&gt;I have tried to check if the function returns nothing, but unfortunately that does not matter.&lt;/P&gt;&lt;P&gt;AutoCAD just crashes if the lines are parallel.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the function I was using:&lt;/P&gt;&lt;PRE&gt;    Function LinesIntersect(ln1 As Line, ln2 As Line) As Point3d
        Try
            Dim line1 As New Line3d(ln1.StartPoint, ln1.EndPoint)
            Dim line2 As New Line3d(ln2.StartPoint, ln2.EndPoint)
            Dim inters As Point3d = line1.IntersectWith(line2)(0) 'Acad crashes at this line of code
            If Not inters = Nothing Then
                GSIntersect = inters
            Else
                msgbox("parallel?")
            End If

        Catch ex As Exception
            Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim ed As Editor = doc.Editor

            ed.WriteMessage("Something went wrong:" &amp;amp; vbLf &amp;amp; vbLf &amp;amp; ex.ToString())
        End Try

    End Function&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I get a FATAL ERROR: Unhandled Access Violation....&lt;/P&gt;&lt;P&gt;AutoCAD just crashes before I can even check if the result is nothing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I'm trying to achieve is a function that returns a points3DCollection with the coordinates of all the intersections of the two objects I select (lines,polylines, arcs and circles)&lt;/P&gt;</description>
      <pubDate>Tue, 20 Nov 2012 07:51:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/vb-net-calculate-intersection-between-2-lines/m-p/3705314#M52447</guid>
      <dc:creator>R.Gerritsen4967</dc:creator>
      <dc:date>2012-11-20T07:51:54Z</dc:date>
    </item>
    <item>
      <title>Re: [VB.net] Calculate intersection between 2 lines</title>
      <link>https://forums.autodesk.com/t5/net-forum/vb-net-calculate-intersection-between-2-lines/m-p/3705614#M52448</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As I said, IntersectWith returns a point3d array or null (Nothing), so you have to check if the array is null before trying to get its first item.&lt;/P&gt;&lt;P&gt;If you want to make a function, it may return a nullable&amp;lt;Point3d&amp;gt; (Nullable(Of Point3d) instead of a Point3d because the Point3d structure is not nullable in case there's none intersection.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following example retruns a Nullable(Of Point3d) (or null if none intersection):&lt;/P&gt;&lt;PRE&gt;		Private Function LinesIntersect(line1 As Line, line2 As Line) As Nullable(Of Point3d)
			Dim ls1 As New LineSegment3d(line1.StartPoint, line1.EndPoint)
			Dim ls2 As New LineSegment3d(line2.StartPoint, line2.EndPoint)
			Dim inters As Point3d() = ls1.IntersectWith(ls2)
			If inters Is Nothing Then
				Return Nothing
			Else
				Return inters(0)
			End If&lt;BR /&gt;                End Function&lt;/PRE&gt;&lt;P&gt;Using example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dim nPt As Nullable(Of Point3d) = LinesIntersect(line1, line2)&lt;/P&gt;&lt;P&gt;If nPt.HasValue Then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pt As Point3d = nPt.Value&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; '...&lt;/P&gt;&lt;P&gt;End If&lt;/P&gt;</description>
      <pubDate>Tue, 20 Nov 2012 12:43:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/vb-net-calculate-intersection-between-2-lines/m-p/3705614#M52448</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2012-11-20T12:43:20Z</dc:date>
    </item>
  </channel>
</rss>

