<?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 Can't get intersection point using Entity.IntersectWith sometimes in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/can-t-get-intersection-point-using-entity-intersectwith/m-p/11981684#M8728</link>
    <description>&lt;P&gt;Hi! I'm new to AutoCAD .NET and trying to get the intersection point of 2 lines using Entity.IntersectWith method lately. Usually, it can find the intersection points. but sometimes it doesn't get it when there should be intersection point between 2 lines.&amp;nbsp; Can' t figured it out why. can someone help or give some suggestions? thx!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is my code for test. I iterate each 2 lines in all lines selected by user and draw a circle on every intersection point. I write in c#:&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;[CommandMethod("Test")]&lt;BR /&gt;public void Test()&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; &amp;nbsp; Active.UsingTransaction(tr =&amp;gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var lineResult = Selector.GetSelection("\nselect lines: ");&amp;nbsp; //get user selection&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (lineResult.Status != PromptStatus.OK) return;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var lines = new List&amp;lt;Line&amp;gt;();&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; foreach (var objId in lineResult.Value.GetObjectIds())&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lines.Add(objId.GetObject(OpenMode.ForRead) as Line);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (var i = 0; i &amp;lt; lines.Count; i++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (i + 1 == lines.Count) break;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (var j = i + 1; j &amp;lt; lines.Count; j++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Line line1 = lines[i], line2 = lines[j];&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var interPts = new Point3dCollection();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; line1.IntersectWith(line2, Intersect.OnBothOperands, interPts, IntPtr.Zero, IntPtr.Zero);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (interPts.Count &amp;gt; 0) Draw.DrawCircle(interPts[0], 1);&amp;nbsp; //draw a circle with radius 1 on intersection point&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;BR /&gt;&amp;nbsp; &amp;nbsp; });&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tomzhengGNS4G_1-1684816311353.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1217838i4D170FC7C57C5CD3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tomzhengGNS4G_1-1684816311353.png" alt="tomzhengGNS4G_1-1684816311353.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tomzhengGNS4G_2-1684816416224.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1217839i50B947DDF4F024FC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tomzhengGNS4G_2-1684816416224.png" alt="tomzhengGNS4G_2-1684816416224.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 23 May 2023 04:36:09 GMT</pubDate>
    <dc:creator>tom.zhengGNS4G</dc:creator>
    <dc:date>2023-05-23T04:36:09Z</dc:date>
    <item>
      <title>Can't get intersection point using Entity.IntersectWith sometimes</title>
      <link>https://forums.autodesk.com/t5/net-forum/can-t-get-intersection-point-using-entity-intersectwith/m-p/11981684#M8728</link>
      <description>&lt;P&gt;Hi! I'm new to AutoCAD .NET and trying to get the intersection point of 2 lines using Entity.IntersectWith method lately. Usually, it can find the intersection points. but sometimes it doesn't get it when there should be intersection point between 2 lines.&amp;nbsp; Can' t figured it out why. can someone help or give some suggestions? thx!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is my code for test. I iterate each 2 lines in all lines selected by user and draw a circle on every intersection point. I write in c#:&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;[CommandMethod("Test")]&lt;BR /&gt;public void Test()&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; &amp;nbsp; Active.UsingTransaction(tr =&amp;gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var lineResult = Selector.GetSelection("\nselect lines: ");&amp;nbsp; //get user selection&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (lineResult.Status != PromptStatus.OK) return;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var lines = new List&amp;lt;Line&amp;gt;();&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; foreach (var objId in lineResult.Value.GetObjectIds())&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lines.Add(objId.GetObject(OpenMode.ForRead) as Line);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (var i = 0; i &amp;lt; lines.Count; i++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (i + 1 == lines.Count) break;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (var j = i + 1; j &amp;lt; lines.Count; j++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Line line1 = lines[i], line2 = lines[j];&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var interPts = new Point3dCollection();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; line1.IntersectWith(line2, Intersect.OnBothOperands, interPts, IntPtr.Zero, IntPtr.Zero);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (interPts.Count &amp;gt; 0) Draw.DrawCircle(interPts[0], 1);&amp;nbsp; //draw a circle with radius 1 on intersection point&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;BR /&gt;&amp;nbsp; &amp;nbsp; });&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tomzhengGNS4G_1-1684816311353.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1217838i4D170FC7C57C5CD3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tomzhengGNS4G_1-1684816311353.png" alt="tomzhengGNS4G_1-1684816311353.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tomzhengGNS4G_2-1684816416224.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1217839i50B947DDF4F024FC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tomzhengGNS4G_2-1684816416224.png" alt="tomzhengGNS4G_2-1684816416224.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2023 04:36:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/can-t-get-intersection-point-using-entity-intersectwith/m-p/11981684#M8728</guid>
      <dc:creator>tom.zhengGNS4G</dc:creator>
      <dc:date>2023-05-23T04:36:09Z</dc:date>
    </item>
    <item>
      <title>Re: Can't get intersection point using Entity.IntersectWith sometimes</title>
      <link>https://forums.autodesk.com/t5/net-forum/can-t-get-intersection-point-using-entity-intersectwith/m-p/11981859#M8729</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Try with LineSegment3d.IntersectWith instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        [CommandMethod("Test")]
        public void Test()
        {
            Active.UsingTransaction(tr =&amp;gt;
            {
                var lineResult = Selector.GetSelection("\nselect lines: ");  //get user selection
                if (lineResult.Status != PromptStatus.OK) return;

                var lineSegments = lineResult.Value
                    .GetObjectIds()
                    .Select(id =&amp;gt; (Line)id.GetObject(OpenMode.ForRead))
                    .Select(line =&amp;gt; new LineSegment3d(line.StartPoint, line.EndPoint))
                    .ToArray();

                for (var i = 0; i &amp;lt; lineSegments.Length - 1; i++)
                {
                    for (var j = i + 1; j &amp;lt; lineSegments.Length; j++)
                    {
                        var line1 = lineSegments[i];
                        var line2 = lineSegments[j];
                        var interPts = line1.IntersectWith(line2);
                        if (interPts != null) 
                            Draw.DrawCircle(interPts[0], 1);  //draw a circle with radius 1 on intersection point
                    }
                }
            });
        }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you post some code:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Use the 'Insert/Edit code sample' button.&lt;/LI&gt;
&lt;LI&gt;If the code calls method from external libraries, provide the libraries source or a link to them.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2023 06:54:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/can-t-get-intersection-point-using-entity-intersectwith/m-p/11981859#M8729</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-05-23T06:54:40Z</dc:date>
    </item>
    <item>
      <title>Re: Can't get intersection point using Entity.IntersectWith sometimes</title>
      <link>https://forums.autodesk.com/t5/net-forum/can-t-get-intersection-point-using-entity-intersectwith/m-p/11981961#M8730</link>
      <description>&lt;P&gt;I should have started there.&lt;/P&gt;
&lt;P&gt;Are you sure there is an intersection between these lines (i.e. they are on the same plane)?&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2023 07:26:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/can-t-get-intersection-point-using-entity-intersectwith/m-p/11981961#M8730</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-05-23T07:26:52Z</dc:date>
    </item>
    <item>
      <title>Re: Can't get intersection point using Entity.IntersectWith sometimes</title>
      <link>https://forums.autodesk.com/t5/net-forum/can-t-get-intersection-point-using-entity-intersectwith/m-p/11982035#M8731</link>
      <description>&lt;P&gt;I checked all the 'Z' values of line's StartPoint/EndPoint are '0'. Does this mean they are on the same plane?&amp;nbsp; sorry I'm not familiar with AutoCAD.&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2023 08:01:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/can-t-get-intersection-point-using-entity-intersectwith/m-p/11982035#M8731</guid>
      <dc:creator>tom.zhengGNS4G</dc:creator>
      <dc:date>2023-05-23T08:01:44Z</dc:date>
    </item>
    <item>
      <title>Re: Can't get intersection point using Entity.IntersectWith sometimes</title>
      <link>https://forums.autodesk.com/t5/net-forum/can-t-get-intersection-point-using-entity-intersectwith/m-p/11982157#M8732</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/13088207"&gt;@tom.zhengGNS4G&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;I checked all the 'Z' values of line's StartPoint/EndPoint are '0'. Does this mean they are on the same plane?&amp;nbsp; sorry I'm not familiar with AutoCAD.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, that means all the lines lies on the XY plane.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another thing, if the lines are far away from the origin (about x0,000,000 units for x and/or y) there may be an accuracy issue. A workaround is moving all lines closer to the origin, get the intersections and move back the lines (and intsection points).&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2023 08:44:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/can-t-get-intersection-point-using-entity-intersectwith/m-p/11982157#M8732</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-05-23T08:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: Can't get intersection point using Entity.IntersectWith sometimes</title>
      <link>https://forums.autodesk.com/t5/net-forum/can-t-get-intersection-point-using-entity-intersectwith/m-p/11982199#M8733</link>
      <description>&lt;P&gt;Thanks for your suggestion! I found that some lines are not on the same plane. The property panel in AutoCAD shows that all lines are on the Z=0 plane. But when I get the position by code it shows that some line's Z value is not 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tomzhengGNS4G_0-1684831199720.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1217952i92F71A95BBA867D9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tomzhengGNS4G_0-1684831199720.png" alt="tomzhengGNS4G_0-1684831199720.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;in AutoCAD it shows that all the Z-value is 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tomzhengGNS4G_1-1684831415464.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1217953i6B97B4A777332229/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tomzhengGNS4G_1-1684831415464.png" alt="tomzhengGNS4G_1-1684831415464.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;get the position of same line by code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so I use a method to transform line to Z=0 plane if it is not.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;void transformZAxis(Line line)
{
    line.UpgradeOpen();

    if (line.StartPoint.Z != 0)
        line.StartPoint = line.StartPoint.TransformBy(Matrix3d.Displacement(new Vector3d(0, 0, -line.StartPoint.Z)));
    if (line.EndPoint.Z != 0)
        line.EndPoint = line.EndPoint.TransformBy(Matrix3d.Displacement(new Vector3d(0, 0, -line.EndPoint.Z)));

    line.DowngradeOpen();
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After all the lines transform to the same plane. it successfully get all the intersection points. Thanks again for your advice.&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2023 09:01:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/can-t-get-intersection-point-using-entity-intersectwith/m-p/11982199#M8733</guid>
      <dc:creator>tom.zhengGNS4G</dc:creator>
      <dc:date>2023-05-23T09:01:52Z</dc:date>
    </item>
    <item>
      <title>Re: Can't get intersection point using Entity.IntersectWith sometimes</title>
      <link>https://forums.autodesk.com/t5/net-forum/can-t-get-intersection-point-using-entity-intersectwith/m-p/11982252#M8734</link>
      <description>&lt;P&gt;You could simply do:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;void transformZAxis(Line line)
{
    line.UpgradeOpen();

    if (line.StartPoint.Z != 0)
        line.StartPoint = new Point3d(line.StartPoint.X, line.StartPoint.Y, 0.0);
    if (line.EndPoint.Z != 0)
        line.EndPoint = new Point3d(line.EndPoint.X, line.EndPoint.Y, 0.0);

    line.DowngradeOpen();
}&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 23 May 2023 09:22:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/can-t-get-intersection-point-using-entity-intersectwith/m-p/11982252#M8734</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-05-23T09:22:26Z</dc:date>
    </item>
  </channel>
</rss>

