---
id: "voronoi-lloyd-relaxation"
title: "Voronoi Diagrams and Lloyd Relaxation"
aliases: [centroidal Voronoi tessellation, CVT, Lloyd's algorithm]
domain: "procgen"
stage: "procedural"
realtime: "interactive"
platforms: [cpu, python, webgl2, houdini, blender, unity, unreal, godot]
year_introduced: 1982
inputs: [point-cloud]
outputs: [mesh, graph, layout]
style: "both"
dynamic: "static"
cost: "cheap"
authority: "Lloyd, 1982"
url: "https://texelatlas.vercel.app/t/voronoi-lloyd-relaxation/"
sources_verified_at: "2026-11-29"
---
# Voronoi Diagrams and Lloyd Relaxation (Lloyd, 1982)

> Partition space by nearest seed (Voronoi), then repeatedly move each seed to the centroid of its cell. The cells become evenly sized and well-shaped, ideal for regions, provinces and tessellations.

## Reach for it when

- voronoi cells are wildly uneven in size
- need evenly shaped map regions or provinces
- crack or fragment patterns look too irregular
- relax random seeds into regular looking cells

## How it works

Given seeds, the Voronoi diagram gives each seed the region of points closer to it than to any other; its dual is the Delaunay triangulation, computable in O(n log n) with Fortune's sweep or incremental Delaunay. Lloyd's iteration computes each cell's centroid (area-weighted, optionally with a density function) and moves the seed there, then recomputes the diagram. Each step reduces a quantisation energy and the process converges to a centroidal Voronoi tessellation (CVT) with hexagon-like cells in 2D. A few iterations (2 to 5) suffice for visually even cells without losing all randomness. Clipping the diagram to a boundary needs care at the border.

## When to use it

Choose it for map regions, cracks and fragment shapes, cell-based terrain and mesh point distributions where regular but irregular-looking cells are wanted. Prefer [Poisson Disk Sampling (Bridson)](https://texelatlas.vercel.app/t/poisson-disk-sampling.md) when you only need points, [Worley (Cellular) Noise](https://texelatlas.vercel.app/t/worley-noise.md) for a per-pixel Voronoi texture with no explicit mesh, and [Wang Tiles (Aperiodic Tile Synthesis)](https://texelatlas.vercel.app/t/wang-tiles.md) for aperiodic tilings with stored tiles.

## Cost

cheap — One diagram construction per iteration; n log n each.
Measured GPU Weight: 702.95× baseline (extreme) — 23.1271 ms median / 23.4629 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 738.38× baseline (extreme) — 11.7402 ms median (1.97× faster on L4).
Ampere A100 scaling: 503.2× baseline (extreme) — 14.4922 ms median (1.6× faster on A100).

## Failure modes

- Too many iterations converge to a uniform hex grid that looks artificial; stop early
- Cells at domain boundaries are unbounded or clipped asymmetrically, so seeds drift outward
- Degenerate configurations (co-circular points) create zero-length edges and numerical instabilities
- Density-weighted CVT needs numeric integration, which is slow and noisy for sharp density changes

## Dataflow

- Inputs: point-cloud
- Outputs: mesh, graph, layout
- Platforms: cpu, python, webgl2, houdini, blender, unity, unreal, godot

## Presets

### Voronoi cells of random sites (left) vs one Lloyd relaxation step (right) (glsl-fragment; rendered 2026-11-29)

```json
{
  "CELLS": 7,
  "SAMP": 6
}
```

```glsl
// Voronoi of jittered sites: left = raw random sites, right = after one Lloyd step (sites moved to their cell centroids, sampled).
const float CELLS = 7.0;
const int SAMP = 6;
vec2 hash2(vec2 p) { return fract(sin(vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)))) * 43758.5453); }
vec2 site0(vec2 c) { return c + 0.08 + 0.84 * hash2(c); }
vec2 relaxed(vec2 c) {
    vec2 s = site0(c), sum = vec2(0.0); float n = 0.0;
    for (int j = 0; j < SAMP; j++) for (int i = 0; i < SAMP; i++) {
        vec2 q = s + (vec2(float(i), float(j)) + 0.5) / float(SAMP) * 2.4 - 1.2;
        vec2 qc = floor(q);
        float bd = 1e9; vec2 bs = vec2(0);
        for (int b = -1; b <= 1; b++) for (int a = -1; a <= 1; a++) {
            vec2 sc = site0(qc + vec2(a, b));
            float d = distance(q, sc);
            if (d < bd) { bd = d; bs = sc; }
        }
        if (distance(bs, s) < 1e-4) { sum += q; n += 1.0; }
    }
    return n > 0.0 ? sum / n : s;
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    vec2 uv = fragCoord / iResolution.xy;
    bool R = uv.x > 0.5;
    vec2 p = uv * CELLS, ip = floor(p);
    float d1 = 1e9, d2 = 1e9; vec2 best = vec2(0); vec2 bc = vec2(0);
    for (int j = -1; j <= 1; j++) for (int i = -1; i <= 1; i++) {
        vec2 c = ip + vec2(i, j);
        vec2 s = R ? relaxed(c) : site0(c);
        float d = distance(p, s);
        if (d < d1) { d2 = d1; d1 = d; best = s; bc = c; } else if (d < d2) d2 = d;
    }
    vec3 col = 0.45 + 0.4 * cos(6.2831 * (hash2(bc).x + vec3(0.0, 0.33, 0.67)));
    col *= 0.8 + 0.2 * smoothstep(0.0, 0.1, d2 - d1);
    col = mix(col, vec3(0.05), smoothstep(0.05, 0.0, d2 - d1) * 0.8);
    col = mix(col, vec3(0.05), smoothstep(0.1, 0.07, d1));
    col = mix(col, vec3(1.0), smoothstep(0.004, 0.0, abs(uv.x - 0.5)));
    fragColor = vec4(pow(col, vec3(0.8)), 1.0);
}

```

Attribution: written for this index

## Lineage

- extended by [Polygon Map Generation (Voronoi Islands)](https://texelatlas.vercel.app/t/voronoi-island-map-generation.md)

## Sources

1. [primary] S. Lloyd (1982) Least squares quantization in PCM. IEEE Transactions on Information Theory. https://doi.org/10.1109/tit.1982.1056489 (verified via crossref on 2026-11-29)
2. [primary] Qiang Du, Vance Faber, Max Gunzburger (1999) Centroidal Voronoi Tessellations: Applications and Algorithms. SIAM Review. https://doi.org/10.1137/s0036144599352836 (verified via crossref on 2026-11-29)
3. [implementation] d3 (2018) d3/d3-delaunay. https://github.com/d3/d3-delaunay License: ISC. (verified via github on 2026-11-29)

## Cite this entry

Texel. "Voronoi Diagrams and Lloyd Relaxation." https://texelatlas.vercel.app/t/voronoi-lloyd-relaxation/ (accessed 2026-12-01).
