21. Voronoi Diagrams & Delaunay Triangulation

Partitioning space by proximity — the geometry behind giraffe skin, soap bubbles, and mesh generation

Look at a giraffe's hide. The dark borders form a network of irregular polygons, each patch a slightly different shade of brown. Crack a sheet of dried mud, and the fractures trace out a similar mosaic. Slice open a bone and the trabecular structure fans out in comparable cells. Zoom into a dragonfly wing and the veins partition the membrane into hundreds of tiny polygonal panes.

These patterns are all Voronoi diagrams — nature's answer to the question: given a set of points, how do you divide space so every location belongs to its nearest point?

The idea appeared independently in mathematics, geography, meteorology, and crystallography before Georgy Voronoi formalized it in 1908. The geographer Alfred Thiessen used identical constructions in 1911 to interpolate rainfall data. Physicist Wigner and Seitz used them to model crystal lattices. Today they appear everywhere from mesh generation to procedural textures to path-planning algorithms.

Definition

Given a set of seed points (also called sites or generators) {p1,p2,…,pn}\{p_1, p_2, \ldots, p_n\} in the plane, the Voronoi diagram partitions the plane into nn regions called cells. The cell V(pi)V(p_i) for seed pip_i contains every point closer to pip_i than to any other seed:

V(pi)={x∈R2:∥x−pi∥≤∥x−pj∥ for all j≠i}V(p_i) = \{x \in \mathbb{R}^2 : \lVert x - p_i \rVert \leq \lVert x - p_j \rVert \text{ for all } j \neq i\}

The key geometric properties:

  • Edges are segments of the perpendicular bisector between two neighboring seeds
  • Vertices are equidistant from exactly three seeds (generically)
  • Each cell is a convex polygon (or an unbounded convex region for seeds on the convex hull)
  • The diagram is uniquely determined by the seed positions (assuming no four seeds are cocircular)

Think of it physically: if each seed simultaneously started spreading ink outward at the same speed, the boundaries where two ink fronts meet would trace out the Voronoi edges.

Diagram

Voronoi Cell Construction

perpendicular bisector S1 S2 S3 S4 S5 Each cell contains all points nearest to its seed

The Dual: Delaunay Triangulation

There is a beautiful correspondence between Voronoi diagrams and triangulations. Take a Voronoi diagram and connect every pair of seeds whose cells share an edge. The result is a triangulation of the seed points — the Delaunay triangulation, named after Boris Delaunay (1934).

Duality

The Voronoi diagram and Delaunay triangulation are dual graphs of each other. Every Voronoi vertex (where three cells meet) corresponds to a Delaunay triangle. Every Voronoi edge (separating two cells) corresponds to a Delaunay edge connecting those two seeds. You can derive either one from the other in linear time.

The Delaunay triangulation has a defining property: the empty circumcircle condition. For every triangle in the triangulation, the circumscribed circle (the unique circle passing through all three vertices) contains no other seed point in its interior.

This property has a practical consequence: the Delaunay triangulation maximizes the minimum angle across all possible triangulations of the same point set. It avoids the long, skinny triangles that cause numerical problems in finite element analysis, interpolation, and rendering. That is why it is the default choice for mesh generation.

Diagram

Empty Circumcircle Property

A B C circumcircle no points inside outside outside outside

From Voronoi to Delaunay and back

Given a Voronoi diagram, the Delaunay triangulation is immediate: connect seeds whose cells share an edge. Going the other direction — given a Delaunay triangulation, the Voronoi diagram is also immediate: the circumcenter of each triangle is a Voronoi vertex, and connecting adjacent circumcenters traces the Voronoi edges.

Diagram

Voronoi–Delaunay Duality

S1 S2 S3 S4 S5 Delaunay edges Voronoi edges circumcenters seeds

Brute Force

The simplest way to render a Voronoi diagram: for every pixel on the canvas, compute the distance to every seed, and color the pixel according to the nearest one.

for each pixel (x, y):
    minDist = infinity
    nearest = -1
    for each seed i:
        d = distance((x, y), seed[i])
        if d < minDist:
            minDist = d
            nearest = i
    color(x, y) = palette[nearest]

The complexity is O(n⋅w⋅h)O(n \cdot w \cdot h) where nn is the number of seeds and w×hw \times h is the image resolution. For a handful of seeds on a moderate canvas, this is perfectly adequate — and it is dead simple to implement. It is also trivially parallelizable (each pixel is independent), which makes it well-suited to GPU shaders.

The brute-force approach has another advantage: you can easily modify the distance metric. Replace Euclidean distance with Manhattan distance (∣x1−x2∣+∣y1−y2∣\lvert x_1 - x_2 \rvert + \lvert y_1 - y_2 \rvert) or Chebyshev distance (max⁡(∣x1−x2∣,∣y1−y2∣)\max(\lvert x_1 - x_2 \rvert, \lvert y_1 - y_2 \rvert)) and you get completely different-looking diagrams with the same code.

Fortune's Algorithm

For applications where you need the actual Voronoi graph structure (vertices and edges, not just a pixel image), a sweep-line algorithm is more appropriate. Steven Fortune published his algorithm in 1986, running in O(nlog⁡n)O(n \log n) time and O(n)O(n) space.

The idea: sweep a horizontal line from top to bottom across the plane. As the sweep line moves, maintain a beach line — a curve made of parabolic arcs — that encodes the Voronoi diagram constructed so far.

Beach line

Each seed above the sweep line contributes a parabola. The parabola for seed pp is the locus of points equidistant from pp and from the sweep line. As the sweep line descends, each parabola widens. The beach line is the lower envelope of all these parabolas — the pointwise minimum.

Two types of events

  1. Site events — the sweep line reaches a new seed. A new parabolic arc is inserted into the beach line, potentially splitting an existing arc.

  2. Circle events — three consecutive arcs on the beach line converge to a single point. The middle arc shrinks to zero width and disappears. The point where it vanishes is a Voronoi vertex (equidistant from the three corresponding seeds). A new Voronoi edge begins.

Initialize event queue with all site events (sorted by y)
Initialize beach line as empty

while event queue is not empty:
    event = pop next event

    if event is a SITE EVENT for seed p:
        find the arc on the beach line directly above p
        split that arc and insert a new arc for p
        check for new circle events involving adjacent arcs
        remove any invalidated circle events

    if event is a CIRCLE EVENT:
        remove the vanishing arc from the beach line
        record the Voronoi vertex
        connect Voronoi edges
        check for new circle events from the newly adjacent arcs

Fortune's algorithm is elegant but notoriously tricky to implement correctly — numerical edge cases involving cocircular points, degenerate configurations, and floating-point precision make a robust implementation a significant engineering challenge.

Bowyer-Watson Algorithm

For the Delaunay triangulation specifically, the Bowyer-Watson algorithm (independently published by Adrian Bowyer and David Watson in 1981) is simpler to implement and understand. It builds the triangulation incrementally, inserting one point at a time.

The algorithm:

  1. Start with a super-triangle large enough to contain all points
  2. For each point to insert:
    • Find all existing triangles whose circumcircle contains the new point (these are "bad" triangles)
    • Remove the bad triangles, leaving a star-shaped polygonal hole
    • Connect the new point to every edge of the hole, creating new triangles
  3. After all points are inserted, remove any triangle that shares a vertex with the original super-triangle
function BowyerWatson(points):
    triangulation = { super-triangle }

    for each point p in points:
        badTriangles = []
        for each triangle t in triangulation:
            if p is inside circumcircle of t:
                add t to badTriangles

        polygon = []   // boundary edges of the hole
        for each triangle t in badTriangles:
            for each edge e of t:
                if e is not shared by any other bad triangle:
                    add e to polygon

        remove all badTriangles from triangulation

        for each edge e in polygon:
            create new triangle from e and p
            add it to triangulation

    remove triangles containing super-triangle vertices
    return triangulation

The expected running time is O(nlog⁡n)O(n \log n) for randomly distributed points, though worst-case is O(n2)O(n^2).

From Delaunay to Voronoi

Once you have the Delaunay triangulation, the Voronoi diagram follows directly: compute the circumcenter of every triangle — those are the Voronoi vertices. For each pair of triangles sharing an edge, connect their circumcenters — those are the Voronoi edges. The whole conversion is O(n)O(n).

The circumcircle test

The core primitive in Bowyer-Watson is testing whether a point lies inside a triangle's circumcircle. For a triangle with vertices AA, BB, CC (in counterclockwise order) and a test point DD, the point is inside the circumcircle if and only if:

∣Ax−DxAy−Dy(Ax−Dx)2+(Ay−Dy)2Bx−DxBy−Dy(Bx−Dx)2+(By−Dy)2Cx−DxCy−Dy(Cx−Dx)2+(Cy−Dy)2∣>0\begin{vmatrix} A_x - D_x & A_y - D_y & (A_x - D_x)^2 + (A_y - D_y)^2 \\ B_x - D_x & B_y - D_y & (B_x - D_x)^2 + (B_y - D_y)^2 \\ C_x - D_x & C_y - D_y & (C_x - D_x)^2 + (C_y - D_y)^2 \end{vmatrix} > 0

This determinant is positive when DD lies inside the circumcircle, zero when on the circle, and negative when outside. The sign depends on the vertices being in counterclockwise order — if they are clockwise, the inequality flips.

Try It: Voronoi Explorer

Click the canvas to place seed points. Toggle between Voronoi cells, Delaunay edges, or both overlaid. Try different color modes and watch how the diagram evolves as you add points. Enable animation to see the seeds drift and the geometry update in real time.

Click the canvas to place seed points

Lloyd Relaxation

Voronoi diagrams generated from random points look chaotic — cells vary wildly in size and shape. Lloyd relaxation (Stuart Lloyd, 1982) iteratively smooths the diagram by moving each seed to the centroid of its Voronoi cell:

repeat until convergence:
    compute Voronoi diagram for current seeds
    for each seed i:
        seed[i] = centroid of cell V(i)

Each iteration makes the cells more uniform in size and more regular in shape. After enough iterations, the seeds converge to a centroidal Voronoi tessellation (CVT) — a configuration where every seed sits exactly at its cell's center of mass.

The visual effect is striking. Random points produce jagged, uneven cells. After 10-20 Lloyd iterations, the cells become smooth, rounded, and roughly hexagonal — reminiscent of soap bubbles, basalt columns, or honeycomb.

Diagram

Lloyd Relaxation

Before → After Lloyd relaxation seeds → centroids ≈ hexagonal cells

Blue noise and stippling

Lloyd relaxation produces a point distribution with blue noise properties: the points are roughly evenly spaced, but without the rigid regularity of a grid. This is exactly the distribution artists seek for stippling — representing tonal values in an image using only the density of dots.

The algorithm for Voronoi stippling:

  1. Generate random points weighted by the darkness of an input image (more points in dark areas)
  2. Run Lloyd relaxation for several iterations
  3. The resulting points form a stippled rendering of the image

This technique, popularized by Adrian Secord (2002), produces beautiful halftone-like images from any photograph.

Applications

Voronoi diagrams and Delaunay triangulations are among the most widely used structures in computational geometry:

  • Mesh generation — the Delaunay triangulation is the starting point for finite element meshes in engineering simulation. Its angle-maximizing property avoids the ill-conditioned elements that cause numerical errors.
  • Nearest-neighbor queries — given a Voronoi diagram, finding the nearest seed to any query point reduces to locating which cell the point falls in.
  • Path planning — the Voronoi edges form a graph that maximizes clearance from obstacles, making it useful for robot navigation.
  • Procedural terrain — assigning random elevations to Voronoi cells produces convincing stylized landscapes (see every low-poly terrain generator).
  • Texture synthesis — Voronoi noise (distance to nearest seed) is a standard procedural texture in shaders, producing organic cell patterns.
  • Spatial indexing — in GIS and meteorology, Thiessen polygons assign each measurement station an "area of influence" for interpolation.
  • Crystallography — Wigner-Seitz cells (the Voronoi cells of a crystal lattice) define the first Brillouin zone in solid-state physics.
  • Biology — cell territories in epithelial tissue closely approximate Voronoi diagrams based on cell nucleus positions.

What's Next

We have partitioned space by proximity and triangulated point clouds with elegant geometric duality. Next we will explore signed distance functions and ray marching — rendering smooth, infinite-detail shapes without a single polygon, by marching rays through mathematical distance fields.