algorithmgraphgeometrycomputational-geometryplanar-graph

Compute dual graph from polygons


Task

Compute the dual graph from a set of non-overlapping (but touching) polygons.

Example

Polygons A, B and C, their partially shared coordinates 1—22 (yellow) and the dual graph (blue).

Polygons and their dual graph

Data

I have a set S of polygons. Every polygon Pi is represented as ordered list of coordinates. The edge ab of a polygon Pi is denoted by Pi,(a,b)

Idea

The polygons represent the faces and hence the nodes of the dual graph. To identify adjacent faces of the polygon Pi just compare every edge of Pi with every edge of every other polygon Pj. If the edge is shared by the other polygon then Pi and Pj are adjacent.

This will create a significant amount of multiple edges which can be removed later.

Problem

The algorithm is not very efficient as it runs in O(E2) where E denotes the number of edges of the set S of polygons.

Improvement ideas

Create an edge-index in a first-step. This will reduce running-time to O(2×E) = O(E)

Remove every node with degree 2. (I think this won't affect the dual graph?)

Questions


Solution

  • You can create a map from edge (as key) to polygon in O(n) time. Iterate all edges of all polygons (order is not important) and insert values into the map. When inserting a new value, if the key already exists, you've found an adjacent polygon - put this polygon pair in a set. When you're done, the set holds all adjacent polygon pairs.