I have an arbitrary set of vertexes in 2D space. I'd like to generate edges nearly randomly between these vertexes such that the following three conditions hold true:
- Every vertex has at least one edge.
- No two edges intersect each other, except possibly at a common vertex.
- No new vertexes need to be added beyond the initial set.
I can't quite figure out how to solve this, in general. I originally tried to forcibly structure my vertexes into neat columns (though with arbitrary vertical spacing between vertexes in the same column), and then form the edges one column at a time, with vertexes only connecting to ones in the next column. I thought I'd be able to then check if a vertex higher up in the current row connects to a vertex lower down in the next row and, if so, prevent any edges that meet that condition. (In other words, if V[j,k] is "the k'th vertex from the top of column j", then I would prevent any edges between V[j,k1] and V[j+1,k2] if there exists an edge between any vertex V[j,k3] and V[j+1,k4], where k4>k2 and k3<k1.)
But it didn't seem to work, and even worse, it left some vertexes without any edges. How can I make this work out? (If possible, without that forced column structure at all; I'd like this to work on as general a set of vertexes as possible.)