MATLAB: Plotting a Circle from Unordered Data Points

  • Context: MATLAB 
  • Thread starter Thread starter Niles
  • Start date Start date
  • Tags Tags
    Matlab Plotting
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 3K views
Niles
Messages
1,834
Reaction score
0
Hi

I have a dataset which traces out a circle. The issue is that the data points are not ordered, so if I plot the set and make lines between adjacent (= "adjacent" in the sense that they are next to each other in the dataset) data points, then the plot does not look like a circle.

Is there a way to plot data in MatLAB such that the points closest to each other get marked up?


Niles.
 
Physics news on Phys.org
Hey Niles.

Have you considered a routine that sorts the points based on their distance and relationship to other points?

There is a technique that would work that sorts points for a convex polytype and this technique is called the convex hull: in 2D, the calculation is simplified using what is known as the Graham-Scan algorithm.

If you have any set of points that describe the outline of a convex polytype (in n-dimensions), then this algorithm (if implemented in n-dimensions) will give you an oriented list of objects. For 2D, you can an ordered list of points, for 3D an ordered list of planes (triangles) and so on.

See if someone has written a 2D convex hull algorithm for MATLAB, and check the computational geometry libraries in MATLAB, because convex-hull algorithms are basically computational geometry techniques, often used in scientific and game engine applications (as well as in rendering applications of any kind).
 
if your points are in x,y form then perhaps by converting to polar to get the theta angle then use it as a key to sort your data in ascending theta order before plotting.

You could plot without connecting a line between your points so that you get a dotted circle.