1

I have the following points:

aa={{238.5, 394.5}, {195.5, 441.5}, {219.5, 397.5}, {216.5, 
 398.5}, {246.5, 397.5}, {265.5, 476.5}, {275.5, 450.5}, {273.5, 
 435.5}, {274.5, 461.5}, {212.5, 447.5}, {221.5, 457.5}}

Now, I want to draw a closed curve from those line. So I used the following code:

Graphics[{{Blue, Point[aa]}, JoinedCurve[Line[aa], CurveClosed -> True]}]

But, it gives me curve like this:

enter image description here

I want the curve like this way:

enter image description here

Please let me know, how to do it. And, I want it to do automatically, not point by point. Please let me know. Thanks.

Odrisso
  • 191
  • 6

3 Answers3

9
curve = FindCurvePath[aa]
ListLinePlot[aa[[curve[[1]]]], AspectRatio -> Automatic]

Mathematica graphics

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
8

Note that the above method doesn't always work. Here is an alternative:

aa = RandomReal[{-1, 1}, {20, 2}];
Graphics[Line[aa[[Last[FindShortestTour[aa]]]]]]

enter image description here

martin
  • 8,678
  • 4
  • 23
  • 70
4

Why not directly use ListCurvePathPlot?

ListCurvePathPlot@aa

enter image description here

xzczd
  • 65,995
  • 9
  • 163
  • 468
  • It appears that ListCurvePathPlot doesn't guarantee that the curve is closed. – VivaLaPanda May 08 '18 at 04:03
  • @AdrianSmith Yeah, actually it's mentioned in the Details and Options of the document: ListCurvePathPlot can generate disconnected curves in certain cases. But it at least works for OP's case. – xzczd May 08 '18 at 05:26