<?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: Check if the polyline segments are on the same side in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/check-if-the-polyline-segments-are-on-the-same-side/m-p/12399394#M6491</link>
    <description>&lt;LI-CODE lang="csharp"&gt;public static bool IsClockWise (this Point2d p1, Point2d p2, Point2d p3 )
{
    double num =(p1.Y - p3.Y) * (p3.X - p2.X) - (p3.Y - p2.Y) * (p1.X - p3.X);
    return num &amp;lt; 0;
}

var seg1 = pline.GetLineSegment2dAt(i);
var seg2 = pline.GetLineSegment2dAt(j);

var bool1 = seg2.StartPoint.IsClockWise(seg1.StartPoint, seg1.EndPoint);
var bool2 = seg1.EndPoint.IsClockWise(seg2.StartPoint, seg2.EndPoint);
string str = bool1 == bool2 ? "Same side" : "Other side";&lt;/LI-CODE&gt;</description>
    <pubDate>Sat, 25 Nov 2023 03:05:36 GMT</pubDate>
    <dc:creator>cuongtk2</dc:creator>
    <dc:date>2023-11-25T03:05:36Z</dc:date>
    <item>
      <title>Check if the polyline segments are on the same side</title>
      <link>https://forums.autodesk.com/t5/net-forum/check-if-the-polyline-segments-are-on-the-same-side/m-p/12398031#M6486</link>
      <description>&lt;P&gt;Hello guys, I'm having a bit of a problem determining the direction of a polyline segment, how do I know if the segments have the same direction or in different directions? How to determine if a polyline belongs to case 1 or case 2 ? thanks you&amp;nbsp;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_heart_eyes:"&gt;😍&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ChuotSieuNhan_0-1700817538088.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1296846i6EB8DC86C3BF4541/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ChuotSieuNhan_0-1700817538088.png" alt="ChuotSieuNhan_0-1700817538088.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Nov 2023 09:21:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/check-if-the-polyline-segments-are-on-the-same-side/m-p/12398031#M6486</guid>
      <dc:creator>ChuotSieuNhan</dc:creator>
      <dc:date>2023-11-24T09:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: Check if the polyline segments are on the same side</title>
      <link>https://forums.autodesk.com/t5/net-forum/check-if-the-polyline-segments-are-on-the-same-side/m-p/12398218#M6487</link>
      <description>&lt;P&gt;IsClockWise(p1, p2, p3) ==&amp;nbsp;IsClockWise(p2, p3, p4)&lt;/P&gt;</description>
      <pubDate>Fri, 24 Nov 2023 11:33:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/check-if-the-polyline-segments-are-on-the-same-side/m-p/12398218#M6487</guid>
      <dc:creator>cuongtk2</dc:creator>
      <dc:date>2023-11-24T11:33:11Z</dc:date>
    </item>
    <item>
      <title>Re: Check if the polyline segments are on the same side</title>
      <link>https://forums.autodesk.com/t5/net-forum/check-if-the-polyline-segments-are-on-the-same-side/m-p/12398275#M6488</link>
      <description>&lt;P&gt;anh cho em thêm chút thông tin keyword để tìm hiểu được không anh, em seach theo từ khoá của anh nhưng chưa ra thông tin&lt;/P&gt;</description>
      <pubDate>Fri, 24 Nov 2023 12:22:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/check-if-the-polyline-segments-are-on-the-same-side/m-p/12398275#M6488</guid>
      <dc:creator>ChuotSieuNhan</dc:creator>
      <dc:date>2023-11-24T12:22:40Z</dc:date>
    </item>
    <item>
      <title>Re: Check if the polyline segments are on the same side</title>
      <link>https://forums.autodesk.com/t5/net-forum/check-if-the-polyline-segments-are-on-the-same-side/m-p/12398956#M6489</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/14200335"&gt;@ChuotSieuNhan&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Show us how you are determining the segments ?&lt;BR /&gt;&lt;BR /&gt;You could compare the unitVectors of&lt;/P&gt;&lt;P&gt;startVertex =&amp;gt; secondVertex&lt;/P&gt;&lt;P&gt;with&lt;/P&gt;&lt;P&gt;secondlastVector =&amp;gt; lastVector&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Nov 2023 19:32:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/check-if-the-polyline-segments-are-on-the-same-side/m-p/12398956#M6489</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2023-11-24T19:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: Check if the polyline segments are on the same side</title>
      <link>https://forums.autodesk.com/t5/net-forum/check-if-the-polyline-segments-are-on-the-same-side/m-p/12399330#M6490</link>
      <description>&lt;P&gt;Thank you, I have found the solution according to your instructions &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/6638420"&gt;@cuongtk2&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Nov 2023 01:52:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/check-if-the-polyline-segments-are-on-the-same-side/m-p/12399330#M6490</guid>
      <dc:creator>ChuotSieuNhan</dc:creator>
      <dc:date>2023-11-25T01:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: Check if the polyline segments are on the same side</title>
      <link>https://forums.autodesk.com/t5/net-forum/check-if-the-polyline-segments-are-on-the-same-side/m-p/12399394#M6491</link>
      <description>&lt;LI-CODE lang="csharp"&gt;public static bool IsClockWise (this Point2d p1, Point2d p2, Point2d p3 )
{
    double num =(p1.Y - p3.Y) * (p3.X - p2.X) - (p3.Y - p2.Y) * (p1.X - p3.X);
    return num &amp;lt; 0;
}

var seg1 = pline.GetLineSegment2dAt(i);
var seg2 = pline.GetLineSegment2dAt(j);

var bool1 = seg2.StartPoint.IsClockWise(seg1.StartPoint, seg1.EndPoint);
var bool2 = seg1.EndPoint.IsClockWise(seg2.StartPoint, seg2.EndPoint);
string str = bool1 == bool2 ? "Same side" : "Other side";&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 25 Nov 2023 03:05:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/check-if-the-polyline-segments-are-on-the-same-side/m-p/12399394#M6491</guid>
      <dc:creator>cuongtk2</dc:creator>
      <dc:date>2023-11-25T03:05:36Z</dc:date>
    </item>
    <item>
      <title>Re: Check if the polyline segments are on the same side</title>
      <link>https://forums.autodesk.com/t5/net-forum/check-if-the-polyline-segments-are-on-the-same-side/m-p/12399440#M6492</link>
      <description>&lt;P&gt;Dạ vâng anh, em cảm ơn anh, em cũng đã tìm được giải pháp tương tự từ Gille ^^ Cảm ơn anh nhiều&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Nov 2023 04:03:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/check-if-the-polyline-segments-are-on-the-same-side/m-p/12399440#M6492</guid>
      <dc:creator>ChuotSieuNhan</dc:creator>
      <dc:date>2023-11-25T04:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: Check if the polyline segments are on the same side</title>
      <link>https://forums.autodesk.com/t5/net-forum/check-if-the-polyline-segments-are-on-the-same-side/m-p/12399590#M6493</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/14200335"&gt;@ChuotSieuNhan&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code suggested by&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/6638420"&gt;@cuongtk2&lt;/a&gt;&amp;nbsp;and @_gile is nice.&lt;/P&gt;&lt;P&gt;. . . a bit cleaner than what I'd imagined.&lt;/P&gt;&lt;P&gt;This was my Vector solution&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private bool DetermineSameLegDirection(LineSegment2d firstSegment,
                                       LineSegment2d lastSegment,
                                       Tolerance tolerance)
{
   var diff = firstSegment.EndPoint - firstSegment.StartPoint;
   Vector2d v1 = new Vector2d(diff.X, diff.Y);

   diff = lastSegment.StartPoint - lastSegment.EndPoint;
   Vector2d v2 = new Vector2d(diff.X, diff.Y);

   return v1.IsEqualTo(v2, tolerance);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Test usage:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;[CommandMethod("Answer_11_25_b")]
public void Answer_11_25_b()
{
   Document doc = CadApp.DocumentManager.MdiActiveDocument;
   Database db = doc.Database;
   Editor ed = doc.Editor;

   PromptEntityOptions peo = new PromptEntityOptions("\nSelect a polyline: ");
   peo.SetRejectMessage("Not a polyline.");
   peo.AddAllowedClass(typeof(Polyline), true);
   PromptEntityResult per = ed.GetEntity(peo);
   if (per.Status != PromptStatus.OK)
      return;

   using (Transaction tr = db.TransactionManager.StartTransaction())
   {
      Polyline pline = (Polyline)tr.GetObject(per.ObjectId, OpenMode.ForWrite);
      var firstIndex = 0;
      var lastIndex = 2;
      var firstSegment = pline.GetLineSegment2dAt(firstIndex);
      var lastSegment = pline.GetLineSegment2dAt(lastIndex);
      Tolerance t = new Tolerance(Tolerance.Global.EqualVector, 
                                 Tolerance.Global.EqualPoint);
      ed.WriteMessage($"\nTolerance =&amp;gt; {t.EqualVector}\n");
      bool result = DetermineSameLegDirection(firstSegment, lastSegment, t);
      tr.Commit();

      ed.WriteMessage(
         $"{(result ? "Legs same direction" : "Legs Different direction")}");
   }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&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;&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>Sat, 25 Nov 2023 07:48:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/check-if-the-polyline-segments-are-on-the-same-side/m-p/12399590#M6493</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2023-11-25T07:48:36Z</dc:date>
    </item>
    <item>
      <title>Re: Check if the polyline segments are on the same side</title>
      <link>https://forums.autodesk.com/t5/net-forum/check-if-the-polyline-segments-are-on-the-same-side/m-p/12400319#M6494</link>
      <description>&lt;P&gt;The complexity of my last post bothered me a bit, so I thought about it a little more&amp;nbsp; :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The LineSegment2d derives from LineEntity2d which has a Direction property which is a Vector2d.&lt;BR /&gt;and ,&lt;BR /&gt;The Vector2d Method&amp;nbsp; &amp;nbsp;&lt;EM&gt;v1.IsEqualTo(v2)&lt;/EM&gt;&amp;nbsp; defaults to using&amp;nbsp;&amp;nbsp;&lt;EM&gt;Tolerance.Global.EqualVector&amp;nbsp; &lt;/EM&gt;so I didn't need to include the Tolerance parameter in the call.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not needing to create 2 new &lt;EM&gt;Vector2d's&lt;/EM&gt; and a new &lt;EM&gt;Tolerance&lt;/EM&gt; cleaned up the functionality considerably.&lt;/P&gt;&lt;P&gt;. . . in effect , to a simple one-line statement.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This means the code actually doing the work can be reduced to :&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;bool result = pline.GetLineSegment2dAt(firstIndex).Direction.IsEqualTo(
               pline.GetLineSegment2dAt(lastIndex).Direction.Negate());&lt;/LI-CODE&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and the full transaction can now be :&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;&lt;LI-CODE lang="csharp"&gt;using (Transaction tr = db.TransactionManager.StartTransaction())
{
   Polyline pline = (Polyline)tr.GetObject(per.ObjectId, OpenMode.ForWrite);
   var firstIndex = 0;
   var lastIndex = 2;

   bool result = pline.GetLineSegment2dAt(firstIndex).Direction.IsEqualTo(
                  pline.GetLineSegment2dAt(lastIndex).Direction.Negate());

   ed.WriteMessage(
      $"{(result ? "Legs same direction" : "Legs Different direction")}\n");

   tr.Commit();
}&lt;/LI-CODE&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;&lt;P&gt;This, of course, assumes the orientation of the legs is intended to be 'parallel' ie&amp;nbsp;&lt;SPAN&gt;extending in the same direction, equidistant at all points, and never converging or diverging, not just on the same side of the center segment.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Sun, 26 Nov 2023 00:29:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/check-if-the-polyline-segments-are-on-the-same-side/m-p/12400319#M6494</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2023-11-26T00:29:54Z</dc:date>
    </item>
    <item>
      <title>Re: Check if the polyline segments are on the same side</title>
      <link>https://forums.autodesk.com/t5/net-forum/check-if-the-polyline-segments-are-on-the-same-side/m-p/12401780#M6495</link>
      <description>&lt;P&gt;Thank you for your interest in my article. Your solution applies well to the case where the angles are 90 degrees. In case the angle error is 1 to 2 degrees more, the result will be wrong. So I still use it the way &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/6638420"&gt;@cuongtk2&lt;/a&gt;&amp;nbsp;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;SPAN class=""&gt;Thank you very much&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="z4918884891094_455f33902f9c801672140c9490c9fb05.jpg" style="width: 999px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1297477i733637BA397AF01A/image-size/large?v=v2&amp;amp;px=999" role="button" title="z4918884891094_455f33902f9c801672140c9490c9fb05.jpg" alt="z4918884891094_455f33902f9c801672140c9490c9fb05.jpg" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2023 02:43:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/check-if-the-polyline-segments-are-on-the-same-side/m-p/12401780#M6495</guid>
      <dc:creator>ChuotSieuNhan</dc:creator>
      <dc:date>2023-11-27T02:43:38Z</dc:date>
    </item>
    <item>
      <title>Re: Check if the polyline segments are on the same side</title>
      <link>https://forums.autodesk.com/t5/net-forum/check-if-the-polyline-segments-are-on-the-same-side/m-p/12401817#M6496</link>
      <description>&lt;P&gt;Yes, that was the conditional . . .&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;[quote]This, of course, assumes the orientation of the legs is intended to be 'parallel' [/quote]&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2023 03:19:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/check-if-the-polyline-segments-are-on-the-same-side/m-p/12401817#M6496</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2023-11-27T03:19:25Z</dc:date>
    </item>
  </channel>
</rss>

