[Solved] Sort Points ad Clockwise C# [closed]


 var lstPnts = new List<PointF>();
            lstPnts.Add(new PointF(23.92f, 6));
            lstPnts.Add(new PointF(23.88f, 0));
            lstPnts.Add(new PointF(0, 0));
            lstPnts.Add(new PointF(0, 6));

            var avgPoint  = new PointF(lstPnts.Average(t=>t.X),lstPnts.Average(t=>t.Y));
            var ordered = lstPnts.OrderBy(t => Math.Atan2(avgPoint.Y - t.Y, avgPoint.X - t.X)).ToArray();

We found an average point. Then we calculated the angle between mid point and the other points and sorted our array with that angles. It may be in a reverse order. If it is so reversing the subtract operation will handle it.

solved Sort Points ad Clockwise C# [closed]