1
$\begingroup$

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.

$\endgroup$
8
$\begingroup$

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

$\endgroup$
  • 1
    $\begingroup$ @Dr.belisarius Ah, didn't mean to sound competitive - just meant as an alternative! I am always learning from your answers anyway +1 :) $\endgroup$ – martin Mar 7 '16 at 22:36
  • 1
    $\begingroup$ Don't worry, I was joking $\endgroup$ – Dr. belisarius Mar 7 '16 at 22:39
  • 1
    $\begingroup$ it looks like a cute cat😃 $\endgroup$ – partida May 9 '16 at 13:48
  • $\begingroup$ This also guarantees the curve is closed which is a plus $\endgroup$ – Adrian Smith May 9 '18 at 17:48
9
$\begingroup$
curve = FindCurvePath[aa]
ListLinePlot[aa[[curve[[1]]]], AspectRatio -> Automatic]

Mathematica graphics

$\endgroup$
3
$\begingroup$

Why not directly use ListCurvePathPlot?

ListCurvePathPlot@aa

enter image description here

$\endgroup$
  • $\begingroup$ It appears that ListCurvePathPlot doesn't guarantee that the curve is closed. $\endgroup$ – Adrian Smith May 8 '18 at 4:03
  • $\begingroup$ @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. $\endgroup$ – xzczd May 8 '18 at 5:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.