10 Spatial Coverage & Exploration · #43 of 46

Voronoi Coverage

How a swarm divides the world into fair shares with Lloyd's algorithm

Close-up of a honeycomb, its wax cells packed into a near-perfect hexagonal grid built by bees.
A swarm of bees, dividing space into fair shares. Nobody told them the math. · Vraj Acharya, CC BY-SA 4.0

Drop a hundred sensors on a field and the deepest question they can ask is brutally simple: whose job is this patch of dirt?

Answer it well and the swarm covers everything with nobody overlapping. Answer it badly and you get holes, fights, and a robot mowing a lawn its neighbor already mowed.

The clean answer was waiting in a math notebook from 1908, and a swarm of robots can rediscover it in about a dozen steps. Before we name it, let's watch it happen.

Watch the swarm find its fair shares

Below, each dot is a robot that "owns" the region of the field closest to it: its Voronoi cell. Every robot creeps toward the center of its own cell, the cells reshape, and the whole swarm settles into an even tiling. No leader, no central plan.

8 agents · coverage cost

drag a site to re-tessellate

this run seed 1 · cost

What changed between runs?

Lloyd's algorithm always lowers the coverage cost, but it only reaches a local optimum — the nearest balanced configuration to wherever the sites began. A centroidal Voronoi tessellation is not unique: each random start falls into a different basin, so you get a different valid tiling and a different final cost. Try "New random start" a few times and watch the cost readout settle to slightly different values.

Try this:

  1. Start crowded. Bunch the agent count up and hit play. Watch the dots shove each other apart, not by pushing, but by each one chasing the middle of its own shrinking territory.
  2. Read the boundaries. Every wall between two cells is the line of points exactly equidistant from those two robots. That's the whole definition of a Voronoi diagram, drawn for free.
  3. Block off a corner. Drop an obstacle and the cells deform around it. Robots re-center on the reachable part of their turf, and coverage repairs itself with zero replanning.
  4. Let it converge. Step until the dots stop moving. That stillness is a centroidal Voronoi tessellation: every robot sitting at its own center of mass.

Two rules, run on a loop: figure out whose turf is whose, then walk to the middle of yours. That loop is Lloyd's algorithm, and it is gradient descent in disguise.

Whose turf is this?

A Voronoi diagram carves a space into cells (one per robot) by a single rule: a point belongs to whichever robot is nearest. That's it. The borders fall out automatically as the set of points that can't decide, the ones perfectly balanced between two neighbors.

A Voronoi diagram: scattered seed points, each surrounded by the polygonal region of space closest to it.
The Voronoi diagram: whose turf is this? Each cell is the set of points nearer to its seed than to any other. · Balu Ertl, CC BY-SA 4.0

Vi={p:ppippj    ji}V_i = \{p : \|p - p_i\| \leq \|p - p_j\| \;\;\forall\, j \neq i\}

Read it aloud: cell V_i is every point p that is at least as close to robot i as to any other robot j. The whole field gets partitioned, no point left unclaimed, no point claimed twice.

The name stuck to Voronoy, but he was late to the party. Descartes sketched the same nearest-point regions informally back in 1644, carving up the heavens into zones of influence around stars. Two centuries later Peter Gustav Lejeune Dirichlet used the cells in earnest, in 2D and 3D, while studying quadratic forms in 1850. That is why the same picture has two other honest names: the Dirichlet tessellation in math, and Thiessen polygons in weather (after the American meteorologist Alfred H. Thiessen, who in 1911 used them to spread scattered rain-gauge readings across a watershed). One shape, four labels, three centuries of people reinventing it.

The two-step that fixes the swarm

Knowing the cells isn't enough. A robot parked in the corner of a huge cell is doing a bad job of covering it. So each robot takes one step toward the centroid of its cell, the center of mass of its territory:

ci=VipdpVidpc_i = \frac{\int_{V_i} p \, dp}{\int_{V_i} dp}

Then everyone recomputes their cells, because moving changed the boundaries, and steps again. This is Lloyd's update, picip_i \leftarrow c_i, looped to convergence. Each pass spreads the robots more evenly, and the swarm's worst-case coverage error (the farthest any point in the field is from its nearest robot)

E=maxpΩminippiE = \max_{p \in \Omega} \min_i \|p - p_i\|

drops monotonically until it can't drop anymore. No robot needs to know where the others are, only the edges of its own cell. Coordination without a coordinator.

Why does walking to the centroid actually minimize coverage error?

Lloyd's algorithm isn't a heuristic that happens to work. It's gradient descent on a real cost function. Define the swarm's coverage cost as the total squared distance from every point in the region to its nearest robot, weighted by an importance density ϕ(p)\phi(p):

H(p1,,pn)=i=1nVippi2ϕ(p)dp\mathcal{H}(p_1,\dots,p_n) = \sum_{i=1}^{n} \int_{V_i} \|p - p_i\|^2 \, \phi(p)\, dp

Take the gradient with respect to one robot's position. The cell boundaries shift as pip_i moves, but those boundary terms cancel (each border point is equidistant from two robots, so it contributes equally to both cells). What survives is clean:

Hpi=2MVi(pici)\frac{\partial \mathcal{H}}{\partial p_i} = 2 M_{V_i}\,(p_i - c_i)

where MViM_{V_i} is the mass of the cell and cic_i its centroid. The gradient is zero exactly when pi=cip_i = c_i, when every robot sits at its own centroid. That fixed point is the centroidal Voronoi tessellation, and stepping toward cic_i is literally stepping downhill on H\mathcal{H}. Swap in a non-uniform ϕ(p)\phi(p) (say, "the western half matters twice as much") and the same loop crowds robots into the important regions automatically.

Where this shows up

The pattern is always the same: a job too big for any one agent, divided into fair shares that the agents negotiate purely by looking at their own backyard.

Key takeaways

The bees never solved an integral. The giraffe never ran Lloyd's algorithm. The soap bubble doesn't know it's minimizing surface area. Yet they all land on the same honeycomb of fair shares, because efficient coverage has exactly one good shape and nature keeps stumbling into it.

When your robots tile a field and quietly settle into stillness, they aren't inventing anything. They're rejoining a very old club.

full glossary →