I know this sounds trivial, but my head is refusing to give an algorithm for this.
I have a bunch of points scattered on a 2-D plane and want to store them in a list such that they create a ring. The points do not belong on a cycle.
Start from the first point in the list (red in this pic) and sequentially add the rest based on their distance.
Since I cannot answer my question I will post here a possible answer.
This is an approach that seems to do the job. V.pos holds the positions of the nodes and distance() is just a function that returns the Euclidean distance between two points. A faster approach would also delete the next_node after appending it to the ring so that you don't have to go through the already connected points
ring = [nodes[0]]
while len(ring) < len(nodes):
minl=99999
for i in range(len(nodes)):
dist = distance(V.pos[ring[-1]],V.pos[nodes[i]])
if dist<minl and nodes[i] not in ring:
minl = dist
next_node = nodes[i]
ring.append(next_node)