Delaunay triangulations and Voronoi diagrams
| Problem | Join scattered points in the plane into triangles that are as well shaped as possible, and divide the plane into the regions closest to each point |
| Devised by | Georgy Voronoy (1908), Boris Delaunay (1934); Charles Lawson (1977), edge flips; Adrian Bowyer and David Watson (1981), incremental insertion |
| Accuracy | Exact combinatorics from floating-point predicates with a rounding-error threshold; identical triangles to Qhull on random points, and Voronoi cell areas within (see the chapter overview) |
| Cost | in practice for the triangulation; the Voronoi cells more from it |
| Read first | Geometric types: points, vectors, shapes and shared tables |
| API | delaunay_triangulation, Triangulation (triangles, edges, locate, circumcenter, area, is_delaunay), voronoi_diagram, VoronoiDiagram, polygon_signed_area |
Overview
A triangulation of a point set divides its convex hull into triangles whose corners are the points. There are many; the Delaunay triangulation is the one in which no point lies inside the circle through any triangle’s three corners (its circumcircle). Of all triangulations it maximises the smallest angle, so it avoids long thin slivers. That is why it is the standard mesh for interpolating scattered data, for finite elements and for terrain models.
Its dual is the Voronoi diagram. The Voronoi cell of a point (a site) is the region of the plane closer to it than to any other site. Two sites have neighbouring cells exactly when they are joined by a Delaunay edge, and the cell corners are the triangles’ circumcentres. Voronoi cells answer “which is nearest?” for every location at once: nearest hospital, nearest mobile mast, the territory of a crystal grain.
Where it is used
Delaunay triangulations and Voronoi diagrams answer “which point is nearest to where?” and “how do I connect points into good triangles?”.
- Meshes for simulation. Finite-element and computer-graphics meshes use Delaunay triangulation because it avoids long, thin triangles.
- Terrain and mapping. Elevation surveys at scattered points become triangulated irregular networks (TINs).
- Facility location and wireless coverage. The Voronoi cell of a cell tower or hospital is the region closer to it than to any other.
- Natural sciences. Cells in tissue, grains in a metal and galaxies in a survey are analysed through their Voronoi neighbours.
History
Georgy Voronoy defined the cells in 1908, for quadratic forms in any dimension. René Descartes had drawn similar regions for the vortices of his cosmology in 1644, and John Snow used them in 1854 to tie a cholera outbreak to the Broad Street pump. Boris Delaunay, Voronoy’s student, gave the empty-circle triangulation in 1934. Algorithms came with computer graphics and finite elements. Charles Lawson (1977) showed that flipping edges that fail the empty-circle test always reaches the Delaunay triangulation. Adrian Bowyer and David Watson (1981) independently gave incremental insertion with a “cavity” of conflicting triangles. Steven Fortune’s sweep-line algorithm (1987) builds the Voronoi diagram directly in .
The idea
Delaunay triangulation
A set of points in the plane can be joined into triangles in many ways. The Delaunay triangulation is the one in which no point lies inside the circumcircle of any triangle (the circle through its three corners). Among all triangulations of the points it makes the smallest angle as large as possible, so it avoids thin sliver triangles wherever it can, which is why it is the standard choice for interpolation and for finite-element meshes.
The definition suggests a local test and a local repair. Two triangles and sharing the edge form a quadrilateral. The edge is legal if lies outside the circumcircle of . If it is illegal, replacing by the other diagonal (a flip) makes both new edges legal and raises the smaller of the two triangles’ smallest angles. A triangulation in which every edge is legal is Delaunay. Whether is inside the circle through , and (counter-clockwise) is the sign of one determinant:
The library inserts the points in lexicographic order of . Each new point is then outside everything triangulated so far. It is joined to every hull edge it can see, which adds a fan of triangles, and the edges opposite the new point are checked and flipped until all are legal again. Sorting removes the need to find which triangle contains a point. It also avoids the “super-triangle” around the data that Bowyer–Watson implementations use, whose finite corners can cut off sliver triangles at the hull.
Figure 24.3. Delaunay triangulation and Voronoi diagram.
Both predicates are computed in floating point. When four points are nearly on a circle, or three nearly on a line, the sign can come out wrong, and an algorithm that trusts it can loop or produce overlapping triangles. Here each determinant is compared with the sum of the magnitudes of its terms, which bounds its rounding error. Values below of that bound count as zero: as collinear for the hull, and as cocircular (no flip) for the empty-circle test. Exactly cocircular points, such as a square grid, have several Delaunay triangulations, and the library returns one of them.
A plain Bowyer–Watson insertion with a super-triangle fails both ways: 41 points on a shallow arc gave triangles overlapping to 2.4 times the hull’s area, and points close to a line lost the hull’s slivers to the super-triangle.
Table 24.2. Time to triangulate 30 000 points.
| 30 000 points | triangles | time |
|---|---|---|
| uniform in a square | 59968 | 81.8 ms |
| Gaussian cloud | 59986 | 86.1 ms |
| points on a circle | 29998 | 4.9 ms |
Figure 24.4. Delaunay timing.
The time per point grows slowly with , as sorting and hash lookups do. Points on a circle are fast: each is seen from just one hull edge, and no flips are needed.
Voronoi diagrams
The Voronoi diagram of a set of points (sites) divides the plane into cells, one per site: the cell of a site is the region closer to it than to any other. It is the dual of the Delaunay triangulation: two sites are joined by a Delaunay edge exactly when their cells share a boundary, and that boundary lies on the perpendicular bisector of the edge.
The library builds each cell directly from the triangulation. Start with the bounding box. For each Delaunay neighbour of site , keep the half-plane closer to , bounded by the perpendicular bisector of . A cell is the intersection of these half-planes, and only Delaunay neighbours contribute edges, so clipping by them alone gives the exact cell. Unbounded cells, on the hull, are closed off by the box.
Algorithm
Delaunay triangulation.
- Prepare. Discard points with non-finite coordinates and duplicates. Scale the rest into the unit square, so that the tolerances of the predicates are relative to the size of the data. Sort the points by , breaking ties by .
- Start. Take points from the sorted list for as long as they are collinear with the first two; they form a chain. The first point off that line, joined to each segment of the chain, gives the first fan of triangles. Their outer edges form the initial convex hull.
- Insert each further point in order. Because of the sorting, it lies outside the current hull. Find the hull edges it can “see” (those with the point on their outer side), starting the search beside the previously inserted point, which is nearby. Add a triangle on each visible edge, and replace those edges in the hull by the two edges from the new point to the ends of the visible chain.
- Legalise. Push the outer edge of each new triangle (the edge opposite the new point) on a stack. While the stack is not empty: pop an edge; find the vertex opposite it in the neighbouring triangle; if that vertex lies inside the circumcircle, and the two triangles form a convex quadrilateral, flip the edge and push the two outer edges of the new pair of triangles.
Sorting costs , and for points in general position the insertions and flips cost about the same in total.
Voronoi diagram. For each site:
- start with the bounding box as the cell;
- for each Delaunay neighbour of the site, cut the cell by the perpendicular bisector of the segment joining them, keeping the side that contains the site.
Implementation
// Lawson flips: edge (a, b) of triangle (a, b, c) is illegal if the triangle (b, a, d)
// across it has d inside the circle through a, b, c.
while let Some((a, b)) = stack.pop() {
let (Some(&t), Some(&u)) = (edge.get(&(a, b)), edge.get(&(b, a))) else { continue };
let c = tris[t].into_iter().find(|&v| v != a && v != b).unwrap();
let d = tris[u].into_iter().find(|&v| v != a && v != b).unwrap();
let (det, scale) = in_circle_bound(p[a], p[b], p[c], p[d]);
if det <= EPS * scale || left(c, a, d) <= 0 || left(c, d, b) <= 0 {
continue;
}
edge.remove(&(a, b));
edge.remove(&(b, a));
tris[t] = [c, a, d];
tris[u] = [c, d, b];
for (x, y, tri) in [(c, a, t), (a, d, t), (d, c, t), (c, d, u), (d, b, u), (b, c, u)] {
edge.insert((x, y), tri);
}
stack.push((a, d));
stack.push((d, b));
}
- Triangles are counter-clockwise index triples into the input.
edgeslists each edge once,locatefinds a triangle containing a point by scanning, andis_delaunaychecks the empty-circle property against every point, for tests. voronoi_diagramreturns the cells in input order (empty for duplicates), the triangulation and the circumcentres, which are the Voronoi vertices.
In practice
//! Delaunay triangulation and the Voronoi diagram of a few points.
use lib_jsl_geometry::algorithms::{delaunay_triangulation, polygon_signed_area, voronoi_diagram};
fn main() {
let points = [[0.0, 0.0], [4.0, 0.0], [4.0, 3.0], [0.0, 3.0], [1.5, 1.2], [2.8, 1.9], [2.0, 2.6]];
let t = delaunay_triangulation(&points).unwrap();
println!("{} triangles: {:?}", t.triangles.len(), t.triangles);
println!("area {} (the convex hull's), Delaunay: {}", t.area(&points), t.is_delaunay(&points, 1e-12));
println!("{} edges; the point (3, 0.5) is in triangle {:?}", t.edges().len(), t.locate(&points, [3.0, 0.5]));
let v = voronoi_diagram(&points, [-1.0, -1.0], [5.0, 4.0]).unwrap();
for (i, cell) in v.cells.iter().enumerate() {
println!("cell of {:?}: {} corners, area {:.3}", points[i], cell.len(), polygon_signed_area(cell));
}
println!("total {:.3} = the 6 × 5 box", v.cells.iter().map(|c| polygon_signed_area(c)).sum::<f64>());
}
8 triangles: [[3, 0, 4], [3, 4, 6], [1, 4, 0], [6, 4, 5], [1, 5, 4], [5, 1, 2], [6, 5, 2], [3, 6, 2]]
area 12 (the convex hull's), Delaunay: true
14 edges; the point (3, 0.5) is in triangle Some(4)
cell of [0.0, 0.0]: 5 corners, area 5.074
cell of [4.0, 0.0]: 6 corners, area 5.507
cell of [4.0, 3.0]: 5 corners, area 4.262
cell of [0.0, 3.0]: 5 corners, area 4.723
cell of [1.5, 1.2]: 5 corners, area 4.287
cell of [2.8, 1.9]: 4 corners, area 2.749
cell of [2.0, 2.6]: 5 corners, area 3.397
total 30.000 = the 6 × 5 box
The cells tile the box exactly, and the sites near the middle have the smallest cells.
Strengths
- Robust on degenerate input: collinear starts, cocircular points, duplicates and thin point sets.
- Voronoi cells as explicit polygons, clipped to a box.
Weaknesses
- Two dimensions only, and no constrained edges (forced boundaries) or point removal.
locatescans every triangle; repeated queries should walk from a nearby triangle or use a spatial tree.
Exercises
- Show that flipping an illegal edge increases the smallest of the six angles of the two triangles.
- Show that the incircle determinant is positive exactly when is inside the circle through counter-clockwise , , . (Lift the points onto the paraboloid .)
- Prove that every Delaunay edge has a circle through its endpoints containing no other point, and deduce the Voronoi duality.
- Use Euler’s formula to show that a triangulation of points with on the hull has triangles.
- Construct a point set where Lawson’s flips, started from an arbitrary triangulation, need flips.
Hints and answers
- For the two triangles on a quadrilateral, flipping a non-Delaunay diagonal lexicographically increases the sorted list of angles; in particular the smallest angle does not decrease (Lawson, Sibson).
- is inside the circle through iff its lift lies below the plane through the lifted on the paraboloid; that is the sign of the determinant with columns .
- An edge is Delaunay iff there is a circle through its endpoints with no other point inside; its centre is equidistant from the endpoints and farther from all other points, so it lies on a Voronoi edge: the dual relationship.
- Euler’s formula with , and (including the outer face) gives .
- Take a set of points on two skew lines (or a spiral) arranged so each flip enables another; each flip removes one crossing, and examples exist with flips.
Further reading
- B. Delaunay, “Sur la sphère vide”, Bulletin de l’Académie des Sciences de l’URSS 6 (1934) 793–800.
- C. L. Lawson, “Software for surface interpolation”, in Mathematical Software III, Academic Press, 1977, 161–194.
- M. de Berg, O. Cheong, M. van Kreveld and M. Overmars, Computational Geometry: Algorithms and Applications, 3rd ed., Springer, 2008, chapters 7 and 9.
- J. R. Shewchuk, “Adaptive precision floating-point arithmetic and fast robust geometric predicates”, Discrete & Computational Geometry 18 (1997) 305–363.