1

I have a set of coordinates that represents a closed shape. The data seems to be in random order. When I plot the data in points, it shows a closed shape. But when I plot it with lines, The lines are plotted all over the place. The data I use is as following:

[[-43.2812, -45.9857, 104.0], [-43.2812, -45.9857, 104.0], [-43.2812, -44.9857, 104.0], [-43.2812, -43.9857, 104.0], [-43.2812, -42.9857, 104.0], [-43.2812, -41.9857, 104.0], [-43.2812, -40.9857, 104.0], [-43.2812, -39.9857, 104.0], [-43.2812, -38.9857, 104.0], [-43.2812, -37.9857, 104.0], [-43.2812, -36.9857, 104.0], [-43.2812, -35.9857, 104.0], [-43.2812, -34.9857, 104.0], [-43.2812, -33.9857, 104.0], [-43.2812, -32.9857, 104.0], [-43.2812, -31.9857, 104.0], [-43.2812, -30.9857, 104.0], [-43.2812, -29.9857, 104.0], [-43.2812, -28.9857, 104.0], [-43.2812, -27.9857, 104.0], [-43.2812, -26.9857, 104.0], [-43.2812, -25.9857, 104.0], [-43.2812, -24.9857, 104.0], [-43.2812, -23.9857, 104.0], [-43.2812, -22.9857, 104.0], [-43.2812, -21.9857, 104.0], [-43.2812, -20.9857, 104.0], [-42.9688, -20.375, 104.0], [-42.2812, -45.9857, 104.0], [-42.1875, -21.1563, 104.0], [-41.4062, -21.9375, 104.0], [-41.2812, -45.9857, 104.0], [-40.625, -21.9375, 104.0], [-40.2812, -45.9857, 104.0], [-39.8438, -22.7188, 104.0], [-39.2812, -45.9857, 104.0], [-39.0625, -23.5, 104.0], [-38.2812, -45.9857, 104.0], [-38.2812, -23.5, 104.0], [-37.5, -46.0944, 104.0], [-37.5, -24.2813, 104.0], [-36.7188, -46.2067, 104.0], [-36.7188, -25.0625, 104.0], [-35.9375, -46.2883, 104.0], [-35.9375, -25.8438, 104.0], [-35.1562, -46.3765, 104.0], [-35.1562, -25.8438, 104.0], [-34.375, -46.5072, 104.0], [-34.375, -26.625, 104.0], [-33.5938, -46.6558, 104.0], [-33.5938, -27.4063, 104.0], [-32.8125, -46.8131, 104.0], [-32.8125, -27.4063, 104.0], [-32.0312, -46.99, 104.0], [-32.0312, -28.1875, 104.0], [-31.25, -47.1963, 104.0], [-31.25, -28.9688, 104.0], [-30.4688, -47.4449, 104.0], [-30.4688, -28.9688, 104.0], [-29.6875, -47.7461, 104.0], [-29.6875, -29.75, 104.0], [-28.9062, -48.0825, 104.0], [-28.9062, -30.5313, 104.0], [-28.125, -48.3963, 104.0], [-28.125, -30.5313, 104.0], [-27.3438, -48.6363, 104.0], [-27.3438, -31.3125, 104.0], [-26.5625, -48.8008, 104.0], [-26.5625, -32.0938, 104.0], [-25.7812, -48.9242, 104.0], [-25.7812, -32.0938, 104.0], [-25.0, -49.041, 104.0], [-25.0, -32.875, 104.0], [-24.2188, -49.1659, 104.0], [-24.2188, -33.6563, 104.0], [-23.4375, -49.3011, 104.0], [-23.4375, -34.4375, 104.0], [-22.6562, -49.4438, 104.0], [-22.6562, -34.4375, 104.0], [-21.875, -49.5863, 104.0], [-21.875, -35.2188, 104.0], [-21.0938, -49.7496, 104.0], [-21.0938, -36.0, 104.0], [-20.3125, -49.9611, 104.0], [-20.3125, -36.0, 104.0], [-19.5312, -50.1867, 104.0], [-19.5312, -36.7813, 104.0], [-18.75, -50.3973, 104.0], [-18.75, -36.7813, 104.0], [-17.9688, -50.619, 104.0], [-17.9688, -36.7813, 104.0], [-17.1875, -50.8665, 104.0], [-17.1875, -37.5625, 104.0], [-16.4062, -51.1327, 104.0], [-16.4062, -37.5625, 104.0], [-15.625, -51.4081, 104.0], [-15.625, -38.3438, 104.0], [-14.8438, -51.6841, 104.0], [-14.8438, -38.3438, 104.0], [-14.0625, -51.9588, 104.0], [-14.0625, -38.3438, 104.0], [-13.2812, -52.2506, 104.0], [-13.2812, -39.125, 104.0], [-12.5, -52.6026, 104.0], [-12.5, -39.125, 104.0], [-11.7188, -53.0506, 104.0], [-11.7188, -39.125, 104.0], [-10.9375, -53.6015, 104.0], [-10.9375, -39.9063, 104.0], [-10.1562, -54.2475, 104.0], [-10.1562, -39.9063, 104.0], [-9.375, -54.9717, 104.0], [-9.375, -39.9063, 104.0], [-8.5938, -55.7477, 104.0], [-8.5938, -40.6875, 104.0], [-7.8125, -56.553, 104.0], [-7.8125, -40.6875, 104.0], [-7.0312, -57.3676, 104.0], [-7.0312, -40.6875, 104.0], [-6.25, -58.1727, 104.0], [-6.25, -40.6875, 104.0], [-5.4688, -58.9652, 104.0], [-5.4688, -40.6875, 104.0], [-4.6875, -59.7491, 104.0], [-4.6875, -40.6875, 104.0], [-3.9062, -60.5174, 104.0], [-3.9062, -40.6875, 104.0], [-3.125, -61.2621, 104.0], [-3.125, -40.6875, 104.0], [-2.3438, -61.9772, 104.0], [-2.3438, -40.6875, 104.0], [-1.5625, -62.6538, 104.0], [-1.5625, -40.6875, 104.0], [-0.7812, -63.2874, 104.0], [-0.7812, -40.6875, 104.0], [0.0, -63.8728, 104.0], [0.0, -40.6875, 104.0], [0.7812, -64.4057, 104.0], [0.7812, -40.6875, 104.0], [1.5625, -64.8889, 104.0], [1.5625, -40.6875, 104.0], [2.3438, -65.3276, 104.0], [2.3438, -40.6875, 104.0], [3.125, -65.7259, 104.0], [3.125, -40.6875, 104.0], [3.9062, -66.0813, 104.0], [3.9062, -40.6875, 104.0], [4.6875, -66.385, 104.0], [4.6875, -40.6875, 104.0], [5.4688, -66.6281, 104.0], [5.4688, -40.6875, 104.0], [6.25, -66.8054, 104.0], [6.25, -40.6875, 104.0], [7.0312, -66.9169, 104.0], [7.0312, -40.6875, 104.0], [7.8125, -66.9709, 104.0], [7.8125, -39.9063, 104.0], [8.5938, -66.9871, 104.0], [8.5938, -39.9063, 104.0], [9.375, -39.9063, 104.0], [9.5938, -66.9871, 104.0], [10.1562, -39.9063, 104.0], [10.5938, -66.9871, 104.0], [10.9375, -39.9063, 104.0], [11.5938, -66.9871, 104.0], [11.7188, -39.125, 104.0], [12.5, -39.125, 104.0], [12.5938, -66.9871, 104.0], [13.2812, -38.3438, 104.0], [13.5938, -66.9871, 104.0], [14.0625, -38.3438, 104.0], [14.5938, -66.9871, 104.0], [14.8438, -38.3438, 104.0], [15.5938, -66.9871, 104.0], [15.625, -37.5625, 104.0], [16.4062, -37.5625, 104.0], [16.5938, -66.9871, 104.0], [17.1875, -36.7813, 104.0], [17.5938, -66.9871, 104.0], [17.9688, -36.7813, 104.0], [18.5938, -66.9871, 104.0], [18.75, -36.0, 104.0], [19.5312, -36.0, 104.0], [19.5938, -66.9871, 104.0], [20.3125, -35.2188, 104.0], [20.5938, -66.9871, 104.0], [21.0938, -34.4375, 104.0], [21.5938, -66.9871, 104.0], [21.875, -34.4375, 104.0], [22.5938, -66.9871, 104.0], [22.6562, -33.6563, 104.0], [23.4375, -32.875, 104.0], [23.5938, -66.9871, 104.0], [24.2188, -32.875, 104.0], [24.5938, -66.9871, 104.0], [25.0, -32.0938, 104.0], [25.5938, -66.9871, 104.0], [25.7812, -31.3125, 104.0], [26.5625, -31.3125, 104.0], [26.5938, -66.9871, 104.0], [27.3438, -30.5313, 104.0], [27.5938, -66.9871, 104.0], [28.125, -29.75, 104.0], [28.5938, -66.9871, 104.0], [28.5938, -66.9871, 104.0], [28.5938, -65.9871, 104.0], [28.5938, -64.9871, 104.0], [28.5938, -63.9871, 104.0], [28.5938, -62.9871, 104.0], [28.5938, -61.9871, 104.0], [28.5938, -60.9871, 104.0], [28.5938, -59.9871, 104.0], [28.5938, -58.9871, 104.0], [28.5938, -57.9871, 104.0], [28.5938, -56.9871, 104.0], [28.5938, -55.9871, 104.0], [28.5938, -54.9871, 104.0], [28.5938, -53.9871, 104.0], [28.5938, -52.9871, 104.0], [28.5938, -51.9871, 104.0], [28.5938, -50.9871, 104.0], [28.5938, -49.9871, 104.0], [28.5938, -48.9871, 104.0], [28.5938, -47.9871, 104.0], [28.5938, -46.9871, 104.0], [28.5938, -45.9871, 104.0], [28.5938, -44.9871, 104.0], [28.5938, -43.9871, 104.0], [28.5938, -42.9871, 104.0], [28.5938, -41.9871, 104.0], [28.5938, -40.9871, 104.0], [28.5938, -39.9871, 104.0], [28.5938, -38.9871, 104.0], [28.5938, -37.9871, 104.0], [28.5938, -36.9871, 104.0], [28.5938, -35.9871, 104.0], [28.5938, -34.9871, 104.0], [28.5938, -33.9871, 104.0], [28.5938, -32.9871, 104.0], [28.5938, -31.9871, 104.0], [28.5938, -30.9871, 104.0], [28.5938, -29.9871, 104.0]]

Is there a way to sort these points, so that they are in order. When I plot the lines, I want a closed shape as a result.

I need the data to be in this specific order, because I want to export it. When I export the data right now, the data can't be used in an other program I'm using.

Thanks in advance.

theo lam
  • 25
  • 5
  • I think you are wanting what is known as the "[convex hull](https://en.wikipedia.org/wiki/Convex_hull_algorithms)" Try clicking on the link I've provided to see if that leads you to any useful algorithms. – Toothpick Anemone Nov 01 '19 at 14:42
  • Can you give any more information about the shape you expect the points to form; for example, is it guaranteed to be convex, or non-self-intersecting? – kaya3 Nov 01 '19 at 14:42
  • [Here](https://docs.scipy.org/doc/scipy-0.19.0/reference/generated/scipy.spatial.ConvexHull.html) is a link to python code which will calculate a convex hull. – Toothpick Anemone Nov 01 '19 at 14:43
  • From what I understand, a convex hull will not use all the coordinate points. I want to sort the data in a correct order. I expect the shape to exactly follow the coordinates. – theo lam Nov 01 '19 at 15:10

1 Answers1

1

In my comments posted on your question I mentioned a convex hull. The following algorithm does NOT necessarily yield a "convex" hull, but it does yield a hull (possibly concave) and may be suitable for your purposes.


1) Begin with a point cloud

this is placeholder text for  initial point cloud image


2) Calculate the centroid

this is placeholder text for the centroid picture


3) For each point calculate the angle θ

enter image description here


4) Order the points based on the angle θ

this is placeholder text for the picture


5) Draw in line segments

enter image description here

Community
  • 1
  • 1
Toothpick Anemone
  • 4,290
  • 2
  • 20
  • 42