-1

I'm designing a procedural city generator, and the first step of the generation process is the creation of city streets. These streets extend out in a straight line to a point, then they can either branch, rotate, or continue in the same direction. If a street would hit another street, it can either stop growing or attach to the nearest junction.

I've been thinking of the junctions as vertices and the streets as edges. From this, I should be able to break the network up into a collection of the smallest possible polygons -- i.e., a space enclosed on all sides by streets.

Dead-end streets can intrude into a polygon, but if a street has 2 junctions on either side, I would like to have that as the edge of a polygon. I can easily remove streets that are "dead ends" (vertices that only have one edge attaching to them) from consideration before processing, so they're not an issue.

So given a collection of vertices and edges, what is a good way to break them up into the smallest possible polygons? It doesn't matter if the polygon is convex or concave, as it would primarily be used as a way to load in bits of the city and mark an area as loaded or unloaded and selectively choose bits of the city for simulation.

Jay2645
  • 61
  • 5

1 Answers1

0

make sure your edges are ordered. e.g. if vertex A is connected to vertex B then there are two edges AB and BA.

1) choose a random vertex and call it A.

2) move to A so that it is your current vertex.

3) choose the rightmost vertex connected to the current vertex and call it B.

4) travel along it so that B is your current vertex.

5) remove the edge AB so that it cannot be traveled along again.

6) if we are not back at the starting vertex then go to step 3.

7) if we are back at the starting vertex then we have found a smallest polygon.

8) while there are still edges, go back to step 1