I have the following graph on the XY plane. Vertices are numbered. I have
struct Point {
double x;
double y;
}
std::vector<Point> points;
std::vector<std::pair<size_t, size_t> edges;
For example I may have 6 vertices and 5 edges
I wish to choose any vertex to start my traversal. Let's choose vertex 1. The traversal would be.
- 1
- 3
- 6
- 4
- 6
- 5
- 6
- 3
- 2
- 3
- 1
This is equivalent to treating the graph like a fence in a field and walking along the fence clockwise keeping the wall to your right hand side.
I believe this is the planar traversal as described in
However boost graph requires a precalculated planar embedding which requires pre-sorting all the edges around each vertex. I didn't see a way within the boost library to perform this sorting automatically. Is there one?


The way to automatically get the planar embedding is as the output from a planarity test. So you could wrap that in your own function:
Demo: Live On Coliru:
UPDATE: Clockwise ordering
After reading the comments, I figured out a way to apply a siilar clock-wise ordering:
Note how I didn't take the angle from a fixed starting point¹, instead actually sorting by the angle of each individual edge. I'll leave it to you to decide whether that's okay for you. It seemed to be enough for the given example.
Live On Coliru
Which now prints:
Now prints:
¹ I suppose the selection using
min_elementmay be ambiguous, by the way. It seems that in your question example both points 1 and 4 have equally minimal x?