<?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: How to know LINE (not polyline) direction? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-know-line-not-polyline-direction/m-p/12060246#M8350</link>
    <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;Thanks for your response.&amp;nbsp;&lt;BR /&gt;Actually Maximum times I am using lines because that is the requirement.&lt;/P&gt;&lt;P&gt;I am placing some objects on lines/polylines. using below piece of code I am inserting object.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;double angle = Vector3d.XAxis.GetAngleTo(li.StartPoint.GetVectorTo(li.EndPoint), Vector3d.ZAxis);
                double length = li.StartPoint.DistanceTo(li.EndPoint);
                pt = li.GetPointAtDist(length * 0.5);
                using (BlockReference br = new BlockReference(pt, ObjId))
                {
                    br.Rotation = angle;
                    BlockTableRecord blkTblRec = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                    ObjectId brId = blkTblRec.AppendEntity(br);
                    trans.AddNewlyCreatedDBObject(br, true);
                }&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;problem is objects position changing with direction of line.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="iPranavKulkarni_0-1687768146435.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1233033iD9326B4A428956F3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="iPranavKulkarni_0-1687768146435.png" alt="iPranavKulkarni_0-1687768146435.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;1.Line drawn CW direction so object placed at left side of line&lt;/P&gt;&lt;P&gt;2.line drawn CCW direction and object place at right side of line.&lt;/P&gt;&lt;P&gt;I need parameter from which I can get direction of line.&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>Mon, 26 Jun 2023 08:31:18 GMT</pubDate>
    <dc:creator>iPranavKulkarni</dc:creator>
    <dc:date>2023-06-26T08:31:18Z</dc:date>
    <item>
      <title>How to know LINE (not polyline) direction?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-know-line-not-polyline-direction/m-p/12059970#M8348</link>
      <description>&lt;P&gt;I created rectangle shape by line and I want to know the direction (clockwise or anticlockwise).&lt;BR /&gt;Can someone pls help.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="iPranavKulkarni_0-1687758827359.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1232962i6860616CDF686197/image-size/medium?v=v2&amp;amp;px=400" role="button" title="iPranavKulkarni_0-1687758827359.png" alt="iPranavKulkarni_0-1687758827359.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2023 05:53:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-know-line-not-polyline-direction/m-p/12059970#M8348</guid>
      <dc:creator>iPranavKulkarni</dc:creator>
      <dc:date>2023-06-26T05:53:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to know LINE (not polyline) direction?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-know-line-not-polyline-direction/m-p/12060184#M8349</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Clockwise and counterclockwise does not make sense for a single line.&lt;/P&gt;
&lt;P&gt;You should work with polyline or points (summits of the rectangle).&lt;/P&gt;
&lt;P&gt;You can check if a polygon (points sequence) is clockwise or counterclockwise by computing its signed area. If the area is negative, the polygon is clockwise.&lt;/P&gt;
&lt;P&gt;Here's an example which computes both the polygon centroid and signed area.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        public static Point2d GetPolygonCentroid(Point2dCollection polygon, out double area)
        {
            Point2d cen = new Point2d();
            double tmpArea;
            area = 0.0;
            int last = polygon.Count - 1;
            Point2d p0 = polygon[0];

            for (int i = 1; i &amp;lt; last; i++)
            {
                var p1 = polygon[i];
                var p2 = polygon[i + 1];
                tmpArea = GetTriangleSignedArea(p0, p1, p2);
                cen += (GetTriangleCentroid(p0, p1, p2) * tmpArea).GetAsVector();
                area += tmpArea;
            }
            return cen.DivideBy(area);
        }

        public static Point2d GetTriangleCentroid(Point2d pt0, Point2d pt1, Point2d pt2) =&amp;gt;
            (pt0 + pt1.GetAsVector() + pt2.GetAsVector()) / 3.0;

        public static double GetTriangleSignedArea(Point2d pt0, Point2d pt1, Point2d pt2) =&amp;gt;
            ((pt1.X - pt0.X) * (pt2.Y - pt0.Y) -
            (pt2.X - pt0.X) * (pt1.Y - pt0.Y)) / 2.0;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A testing command:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        [CommandMethod("CENTROID")]
        public static void Centroid()
        {
            var ed = Application.DocumentManager.MdiActiveDocument.Editor;

            var ppo = new PromptPointOptions("\nPick a point: ");
            ppo.AllowNone = true;
            var points = new Point2dCollection();
            while (true)
            {
                var ppr = ed.GetPoint(ppo);
                if (ppr.Status == PromptStatus.None) break;
                if (ppr.Status != PromptStatus.OK) return;
                points.Add(new Point2d(ppr.Value.X, ppr.Value.Y));
            }
            if (2 &amp;lt; points.Count)
            {
                var centroid = GetPolygonCentroid(points, out double area);
                ed.Command("_point", new Point3d(centroid.X, centroid.Y, 0.0));
                ed.WriteMessage($"\nArea = {Math.Abs(area)} ({(area &amp;lt; 0.0 ? "Clockwise" : "Counterclockwise")})");
            }
        }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2023 07:55:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-know-line-not-polyline-direction/m-p/12060184#M8349</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-06-26T07:55:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to know LINE (not polyline) direction?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-know-line-not-polyline-direction/m-p/12060246#M8350</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;Thanks for your response.&amp;nbsp;&lt;BR /&gt;Actually Maximum times I am using lines because that is the requirement.&lt;/P&gt;&lt;P&gt;I am placing some objects on lines/polylines. using below piece of code I am inserting object.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;double angle = Vector3d.XAxis.GetAngleTo(li.StartPoint.GetVectorTo(li.EndPoint), Vector3d.ZAxis);
                double length = li.StartPoint.DistanceTo(li.EndPoint);
                pt = li.GetPointAtDist(length * 0.5);
                using (BlockReference br = new BlockReference(pt, ObjId))
                {
                    br.Rotation = angle;
                    BlockTableRecord blkTblRec = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                    ObjectId brId = blkTblRec.AppendEntity(br);
                    trans.AddNewlyCreatedDBObject(br, true);
                }&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;problem is objects position changing with direction of line.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="iPranavKulkarni_0-1687768146435.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1233033iD9326B4A428956F3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="iPranavKulkarni_0-1687768146435.png" alt="iPranavKulkarni_0-1687768146435.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;1.Line drawn CW direction so object placed at left side of line&lt;/P&gt;&lt;P&gt;2.line drawn CCW direction and object place at right side of line.&lt;/P&gt;&lt;P&gt;I need parameter from which I can get direction of line.&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>Mon, 26 Jun 2023 08:31:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-know-line-not-polyline-direction/m-p/12060246#M8350</guid>
      <dc:creator>iPranavKulkarni</dc:creator>
      <dc:date>2023-06-26T08:31:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to know LINE (not polyline) direction?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-know-line-not-polyline-direction/m-p/12060267#M8351</link>
      <description>&lt;P&gt;As said upper the line 'direction' only make sense for clockwise or counterclockwise when it's compared to the other lines componing the polygon.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2023 08:42:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-know-line-not-polyline-direction/m-p/12060267#M8351</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-06-26T08:42:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to know LINE (not polyline) direction?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-know-line-not-polyline-direction/m-p/12060481#M8352</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/11543096"&gt;@iPranavKulkarni&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;1.Line drawn CW direction so object placed at left side of line&lt;/P&gt;&lt;P&gt;2.line drawn CCW direction and object place at right side of line.&lt;/P&gt;&lt;P&gt;I need parameter from which I can get direction of line.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;You do have the direction of the line. !!&lt;/P&gt;&lt;P&gt;Seems to me you're complaining about the programming language not being able to guess what you want.&lt;BR /&gt;As Gile explained, the location and rotation of the block is being determined by what you tell it to do.&lt;BR /&gt;If you want it to be different you will need to program it to be different.&lt;BR /&gt;Perhaps you will need to incorporate a prompt asking for the user to accept ( or mirror ) the block properties.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2023 10:28:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-know-line-not-polyline-direction/m-p/12060481#M8352</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2023-06-26T10:28:13Z</dc:date>
    </item>
  </channel>
</rss>

