How to order points anti clockwise

后端 未结 5 1665
梦毁少年i
梦毁少年i 2021-02-20 04:22

Lets take thess points.

pt={{-4.65371,0.1},{-4.68489,0.103169},{-4.78341,0.104834},{-4.83897,0.100757},
{-4.92102,0.0949725},{-4.93456,0.100181},{-4.89166,0.1226         


        
5条回答
  •  粉色の甜心
    2021-02-20 04:53

    Why don't you just sort the points?:

    center = Mean[pt];
    pts = SortBy[pt, Function[p, {x, y} = p - center; ArcTan[x, y]]]
    Show[ListPlot[pt], ListPlot[pts, Joined -> True]]
    

    Note that the polygon in your last plot is concave, so the points are not ordered clockwise!

提交回复
热议问题