<?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: Sorting a list point of a polygon clockwise in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/10640199#M29728</link>
    <description>&lt;P&gt;Ok, let’s say by the highest point.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Sep 2021 16:00:03 GMT</pubDate>
    <dc:creator>mohamed_adel_ghazaly</dc:creator>
    <dc:date>2021-09-22T16:00:03Z</dc:date>
    <item>
      <title>Sorting a list point of a polygon clockwise</title>
      <link>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/7366469#M29717</link>
      <description>&lt;P&gt;I have a point array.&amp;nbsp;I want to sort &lt;SPAN&gt;point&lt;/SPAN&gt; of a polygon&amp;nbsp;to calculate the area.&lt;/P&gt;&lt;P&gt;This is my list point:&lt;/P&gt;&lt;PRE&gt;- Point3d 1  X: 16.9739362797234 Y: 1.15620205549732 Z: 0
- Point3d 2  X: 16.671656969313 Y: 1.16417151545853 Z: 0
- Point3d 3  X: 16.0185770382255 Y: 1.18138967820743 Z: 0
- Point3d 4  X: 16.9739362797234 Y: 1.45620205549783 Z: 0
- Point3d 5  X: 15.7386856391879 Y: 1.48876889081456 Z: 0
- Point3d 6  X: 3.51984642951532 Y: 1.51091316764773 Z: 0
- Point3d 7  X: 3.51984642951532 Y: 1.81091316764773 Z: 0
- Point3d 8  X: -10.2845662421009 Y: 1.98207932732037 Z: 0
- Point3d 9  X: -10.6449687487931 Y: 1.9954460528974 Z: 0
- Point3d 10  X: -10.7612815869122 Y: 1.99064617997511 Z: 0
- Point3d 11  X: -10.8658975847679 Y: 1.99013890212357 Z: 0
- Point3d 12  X: -11.620742475742 Y: 1.98928295827633 Z: 0
- Point3d 13  X: -10.2845662417003 Y: 1.68207932730779 Z: 0
- Point3d 14  X: -10.6449687486466 Y: 1.69544605290257 Z: 0
- Point3d 15  X: -10.761281586839 Y: 1.69064617997781 Z: 0
- Point3d 16  X: -10.865897584949 Y: 1.69013890212357 Z: 0
- Point3d 17  X: -11.6207424763237 Y: 1.68928295827587 Z: 0
- Point3d 18  X: -15.6175840485863 Y: 1.99120797569964 Z: 0
- Point3d 19  X: -16.1629232880395 Y: 1.99147062997825 Z: 0
- Point3d 20  X: -15.6175840485863 Y: 1.69120797569966 Z: 0
- Point3d 20  X: -15.6175840485863 Y: 1.69120797569966 Z: 0
- Point3d 21  X: -16.1629232880395 Y: 1.69147062997776 Z: 0&lt;/PRE&gt;&lt;P&gt;My code:&lt;/P&gt;&lt;PRE&gt; var sortList = ltsPoint.OrderBy(x =&amp;gt; Math.Atan2(x.Y, x.X)).ToList();&lt;/PRE&gt;&lt;P&gt;But not successful. Hope everybody help please, Thanks!&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2017 03:09:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/7366469#M29717</guid>
      <dc:creator>hoainamtdt</dc:creator>
      <dc:date>2017-09-09T03:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting a list point of a polygon clockwise</title>
      <link>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/7366855#M29718</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have to clarify what you mean with: "sort &lt;SPAN&gt;point&lt;/SPAN&gt; of a polygon".&lt;/P&gt;
&lt;P&gt;Are the point list you provided the polygon vertices?&lt;/P&gt;
&lt;P&gt;If so, you cannot change their order (except reversing them) without modifiing the polygon shape (and its area).&lt;/P&gt;
&lt;P&gt;If not, you have to explain further the relation between this point list and the polygon you expect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2017 12:50:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/7366855#M29718</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2017-09-09T12:50:19Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting a list point of a polygon clockwise</title>
      <link>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/7366884#M29719</link>
      <description>&lt;P&gt;Thanks for the reply _gile&lt;SPAN&gt;&amp;nbsp;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have a xy point list, I want to arrange the point into the top of the polygon to get its area.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2017 13:14:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/7366884#M29719</guid>
      <dc:creator>hoainamtdt</dc:creator>
      <dc:date>2017-09-09T13:14:36Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting a list point of a polygon clockwise</title>
      <link>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/7366885#M29720</link>
      <description>&lt;P&gt;If your point list describe the polygon vertices, you can get the signed polygon area (positive if points are CCW negative if they're CW) with the following code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        public double PolygonSignedArea(Point2d[] points)
        {
            Point2d p0 = points[0];
            double area = 0.0;

            double triangleSignedArea(Point2d p1, Point2d p2) =&amp;gt;
                (p1.X - p0.X) * (p2.Y - p0.Y) - (p2.X - p0.X) * (p1.Y - p0.Y);

            for (int i = 0; i &amp;lt; points.Length - 1; i++)
            {
                area += triangleSignedArea(points[i], points[i + 1]);
            }
            return area / 2.0;
        }&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Sep 2017 13:15:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/7366885#M29720</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2017-09-09T13:15:35Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting a list point of a polygon clockwise</title>
      <link>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/7366892#M29721</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 705px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/399544iFDA82BB13E774908/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2017 13:22:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/7366892#M29721</guid>
      <dc:creator>hoainamtdt</dc:creator>
      <dc:date>2017-09-09T13:22:53Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting a list point of a polygon clockwise</title>
      <link>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/7366912#M29722</link>
      <description>&lt;P&gt;Thanks _gile!&lt;/P&gt;&lt;P&gt;The code returns the correct area with the point aligned clockwise, and the list point is not sorted&amp;nbsp;returns the wrong area.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2017 13:54:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/7366912#M29722</guid>
      <dc:creator>hoainamtdt</dc:creator>
      <dc:date>2017-09-09T13:54:12Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting a list point of a polygon clockwise</title>
      <link>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/7366936#M29723</link>
      <description>&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;I do not understand what objective criteria allow you to retain certain points and to exclude others.&lt;/SPAN&gt;&lt;BR /&gt;For example, a 2D &lt;A href="https://en.wikipedia.org/wiki/Convex_hull" target="_blank"&gt;convex hull&lt;/A&gt; would have followed the green line (&lt;A href="https://www.theswamp.org/index.php?topic=31865.msg430599#msg430599" target="_blank"&gt;here's a code&lt;/A&gt; code to get the convex hull from a point list).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="polygon.png" style="width: 641px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/399549i6959A68C5E646432/image-size/large?v=v2&amp;amp;px=999" role="button" title="polygon.png" alt="polygon.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2017 14:22:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/7366936#M29723</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2017-09-09T14:22:38Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting a list point of a polygon clockwise</title>
      <link>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/7366954#M29724</link>
      <description>&lt;P&gt;Thanks , very grateful you have enthusiastically helped me,&lt;/P&gt;&lt;P&gt;I&amp;nbsp;am using civil3d, i get the promiscuous point list from materialsection, I&amp;nbsp;am looking to take the area of this point list&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 664px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/399558iEF475FDA03B361DF/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2017 15:09:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/7366954#M29724</guid>
      <dc:creator>hoainamtdt</dc:creator>
      <dc:date>2017-09-09T15:09:51Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting a list point of a polygon clockwise</title>
      <link>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/7367684#M29725</link>
      <description>&lt;P&gt;Ok,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get the "boundary point list", you can use the following ConvexHull() method passing it the "point list from section".&lt;/P&gt;
&lt;P&gt;You ca then get the "area" using the PolygonSignedArea() method passing it the point list returned by ConvexHull().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;double area = PolygonSignedArea(ConvexHull(pointListFromSection));&lt;/PRE&gt;
&lt;PRE&gt;        public List&amp;lt;Point2d&amp;gt; ConvexHull(IEnumerable&amp;lt;Point2d&amp;gt; source)
        {
            var p0 = source.OrderBy(p =&amp;gt; p.Y).ThenBy(p =&amp;gt; p.X).First();

            bool Clockwise(Point2d p1, Point2d p2, Point2d p3) =&amp;gt;
                DoubleSignedArea(p1, p2, p3) &amp;lt; 1e-9;

            double Cosine(Point2d pt)
            {
                double d = p0.GetDistanceTo(pt);
                return d == 0.0 ? 1.0 : Math.Round((pt.X - p0.X) / d, 9);
            }

            var pts = source.OrderByDescending(p =&amp;gt; Cosine(p)).ThenBy(p =&amp;gt; p0.GetDistanceTo(p)).ToList();
            for (int i = 1; i &amp;lt; pts.Count - 1; i++)
            {
                while (i &amp;gt; 0 &amp;amp;&amp;amp; Clockwise(pts[i - 1], pts[i], pts[i + 1]))
                {
                    pts.RemoveAt(i);
                    i--;
                }
            }
            return pts;
        }

        public double PolygonSignedArea(IEnumerable&amp;lt;Point2d&amp;gt; source)
        {
            var points = source.ToArray();
            Point2d p0 = points[0];
            double area = 0.0;

            for (int i = 0; i &amp;lt; points.Length - 1; i++)
            {
                area += DoubleSignedArea(p0, points[i], points[i + 1]);
            }
            return area / 2.0;
        }

        private double DoubleSignedArea(Point2d p1, Point2d p2, Point2d p3) =&amp;gt;
            (p2.X - p1.X) * (p3.Y - p1.Y) - (p2.Y - p1.Y) * (p3.X - p1.X);&lt;/PRE&gt;</description>
      <pubDate>Sun, 10 Sep 2017 08:50:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/7367684#M29725</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2017-09-10T08:50:44Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting a list point of a polygon clockwise</title>
      <link>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/10639971#M29726</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I need to order points clock wise without excluding any even the inside points, i tried to remove the for loop where removing happens but it did not work very well. any suggestion&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 14:36:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/10639971#M29726</guid>
      <dc:creator>mohamed_adel_ghazaly</dc:creator>
      <dc:date>2021-09-22T14:36:57Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting a list point of a polygon clockwise</title>
      <link>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/10640083#M29727</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/6272621"&gt;@mohamed_adel_ghazaly&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;order points clock wise without excluding any even the inside points&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This doesn't mean much if you don't specify a reference point. For example, depending on which point you start from (the lowest, the highest, the leftmost), the results are different.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="_gile_0-1632324109915.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/968357iD8C45604DFF51678/image-size/medium?v=v2&amp;amp;px=400" role="button" title="_gile_0-1632324109915.png" alt="_gile_0-1632324109915.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 15:22:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/10640083#M29727</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2021-09-22T15:22:02Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting a list point of a polygon clockwise</title>
      <link>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/10640199#M29728</link>
      <description>&lt;P&gt;Ok, let’s say by the highest point.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 16:00:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/10640199#M29728</guid>
      <dc:creator>mohamed_adel_ghazaly</dc:creator>
      <dc:date>2021-09-22T16:00:03Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting a list point of a polygon clockwise</title>
      <link>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/10640497#M29729</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/6272621"&gt;@mohamed_adel_ghazaly&lt;/a&gt; this should work:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        static Point3dCollection SortPointsClockwise(Point3dCollection points)
        {
            var result = new Point3dCollection();
            var topMost = points.Cast&amp;lt;Point3d&amp;gt;().Aggregate((p1, p2) =&amp;gt; p1.Y &amp;lt; p2.Y ? p2 : p1);
            points.Remove(topMost);
            result.Add(topMost);
            foreach (var pt in points
                .Cast&amp;lt;Point3d&amp;gt;()
                .OrderBy(p =&amp;gt; Vector3d.XAxis.GetAngleTo(topMost.GetVectorTo(p))))
            {
                result.Add(pt);
            }
            return result;
        }&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 22 Sep 2021 17:57:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/sorting-a-list-point-of-a-polygon-clockwise/m-p/10640497#M29729</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2021-09-22T17:57:05Z</dc:date>
    </item>
  </channel>
</rss>

