I would like to ask how to arrange points to plot a closed polygon.
In my application I will have a collection of points that describe a shape that might be convex or concave - and I would like to draw the polygon. The problem is that the order of the points is such that a straightforward plot
command will not generate the polygon I want.
For example:
dtheta = pi/150;
theta = (-pi:dtheta:(pi-dtheta))';
X1 = cos(theta);
X2 = sin(theta);
[n1,In1]=sort(X1); % sort is intentional here
n2=X2(In1);
Now,
plot(n1,n2,'.')
gives me a circle shaped arrangement of points
However, using
plot(n1,n2)
the circle is not noticeable at all because of the order of how points are connected.
Is there a way of arranging (n1,n2)
such that when plot(n1,n2)
is called, a polygon can be plotted clearly, in this case a circle?