问题
I'm confronted with a rather unusual problem dealing with an directed geometric graph. Imagine the graph being borders of countries. I'm looking for a way to find the faces. My graph consists of directed edges which may form cycles (but not necessarily).
What I am looking for are the left and right faces as well as the predecessors and successors of the left and right faces for each edge.
Each face should be constructed anti-clockwise, meaning that the left face of an edge is always inside and the right face is outside of the specific face.
At the end of the day the nodes of the faces are geographic coordinates (lat and lon).
This is the information I am looking for (beginning from LeftFace..)
+------+-------+-------+----------+-----------+---------------------+--------------------+
| Edge | NodeA | NodeB | LeftFace | RightFace | PredecessorLeftFace | SuccessorRightFace |
+------+-------+-------+----------+-----------+---------------------+--------------------+
| E1 | P1 | P2 | A | C | E5 | E2 |
+------+-------+-------+----------+-----------+---------------------+--------------------+
| E2 | P2 | P3 | A | C | E1 | E6 |
+------+-------+-------+----------+-----------+---------------------+--------------------+
| E3 | P3 | P4 | A | B | E2 | E8 |
+------+-------+-------+----------+-----------+---------------------+--------------------+
| E4 | P4 | P5 | A | C | E3 | E5 |
+------+-------+-------+----------+-----------+---------------------+--------------------+
| E5 | P5 | P1 | A | C | E4 | E1 |
+------+-------+-------+----------+-----------+---------------------+--------------------+
| E6 | P3 | P6 | B | C | E3 | E7 |
+------+-------+-------+----------+-----------+---------------------+--------------------+
| E7 | P6 | P7 | B | C | E6 | E8 |
+------+-------+-------+----------+-----------+---------------------+--------------------+
| E8 | P7 | P4 | B | C | E7 | E4 |
+------+-------+-------+----------+-----------+---------------------+--------------------+
回答1:
For each directed edge add also opposite edge in a graph. Than, for each (directed) edge find face in that direction. That means, traverse face edges so that in every vertex choose leftmost neighboring edge, until path returns to starting vertex. To choose leftmost edge, 2D positions of vertices are needed.
Example of choosing leftmost edge: going from P3 to P4 (opposite of E3). In P4 there are two possibilities to continue path, P5 and P7. Now check angles on the left side of edges. P3-P4-P5 is ~90deg, and P3-P4-P7 is ~270deg. Angle P3-P4-P5 is smaller than P3-P4-P7, so next edge in path is E4, and next point in path is P5.
Algorithm:
For each directed edge add opposite edge
While there are edges in graph
Choose one directed edge
Find edges that enclose face (on left side) starting from that edge
Add face to list of faces
Remove face edges from graph
来源:https://stackoverflow.com/questions/25059141/finding-faces-in-a-geometric-directed-graph