How to order points anti clockwise

后端 未结 5 1668
梦毁少年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 05:03

    I posted the following comment below your question: I don't think you'll find a general solution. This answer tries to dig a little on that.

    Heike's solution seems fair, but FindShortestTour is based on the metric properties of the set, while your requirement is probably more on the topological side.

    Here is a comparison on two points sets and the methods available to FindShortestTour:

    pl[method_, k_] :=
      Module[{ptsorted, pt,s},
       little[x_] := {{1, 0}, {2, 1}, {1, 2}, {0, 1}}/x - (1/x) + 2;
       pt = Join[{{0, 0}, {4, 4}, {4, 0}, {0, 4}}, little[k]];
       ptsorted = Join[s = pt[[FindShortestTour[pt,Method->method][[2]]]], {s[[1]]}];
       ListPlot[ptsorted, Joined -> True, Frame -> True, 
                          PlotMarkers -> Automatic, 
                          PlotRange -> {{-1, 5}, {-1, 5}}, 
                          Axes -> False, AspectRatio -> 1, PlotLabel -> method]];
    GraphicsGrid@
     Table[pl[i, j],
           {i, {"AllTours", "CCA", "Greedy", "GreedyCycle", 
                "IntegerLinearProgramming", "OrOpt", "OrZweig", "RemoveCrossings",
                "SpaceFillingCurve", "SimulatedAnnealing", "TwoOpt"}}, 
           {j, {1, 1.8}}]
    

         Fat Star         Slim Star

    As you can see, several methods deliver the expected result on the left column, while only one does it on the right one. Moreover, the only useful method for the set on the right is completely off for the column on the left.

提交回复
热议问题