Note that there are some explanatory texts on larger screens.

plurals
  1. POordering shuffled points that can be joined to form a polygon (in python)
    primarykey
    data
    text
    <p>I have a collection of points that join to form a polygon in 2D cartesian space. It is in the form of a python list of tuples</p> <pre><code>[(x1, y1), (x2, y2), ... , (xn, yn)] </code></pre> <p>the problem is the join them and form a polygon in a graph. (I'm using matplotlib.path)</p> <p>I made a function to do this. It works as follows:</p> <p>it goes to first point ie (x1, y1) and joins a line to next point ie (x2, y2) and a line from (x2, y2) to (x3, y3) and so on .. till the end which is (xn, yn). It closes the polygon by joining (xn, yn) to (x1, y1). </p> <p>The problem is the list containing these points does not contain the points in the right order so that results in bad drawings like these(Every closed polygon is colored automatically).</p> <p><strong>Example:</strong></p> <p>for this list of vertices = `[(-0.500000050000005, -0.5), (-0.499999950000005, 0.5), (-0.500000100000005, -1.0), (-0.49999990000000505, 1.0), (0.500000050000005, -0.5), (-1.0000000250000025, -0.5), (1.0000000250000025, -0.5), (0.499999950000005, 0.5), (-0.9999999750000024, 0.5), (0.9999999750000024, 0.5), (0.500000100000005, -1.0), (0.49999990000000505, 1.0), (-1.0, 0.0), (-0.0, -1.0), (0.0, 1.0), (1.0, 0.0), (-0.500000050000005, -0.5)]</p> <p><strong>The points:</strong> <img src="https://i.stack.imgur.com/n9MIa.png" alt="enter image description here"></p> <p><strong>Bad order of points results in:</strong> <img src="https://i.stack.imgur.com/9B3W0.png" alt="enter image description here"></p> <p><strong>Correct way to join:</strong> <img src="https://i.stack.imgur.com/YkoLH.png" alt="enter image description here"></p> <p>Is there any good (and easy if possible) algorithm to reorder the points to correct order? `</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload