Algorithms

Delaunay triangulation: empty circles

A convex hull gives the outer boundary. Now connect all the points into triangles inside it. A circle through the three vertices tells us when to replace a diagonal.

Blue dashed: VoronoiYellow: circle testGreen: triangulation

Connect the points into a Delaunay triangulation. Circle tests: 0 · Flips: 0 · Triangles: 0

Empty-circle test

Outer boundary: —

Tested edge: —

Circumcircle through: —

Select a test step to inspect a circumcircle

Faces: —

Edit points

Press Play for the construction, or Show results. Drag points or use the coordinate editor. Editing keeps the completed mesh visible; Restart opens its construction. The dashed circle passes through three highlighted vertices; the purple point is tested against it. Red means inside: replace the shared diagonal of the convex quadrilateral. On-circle ties keep the existing diagonal. Voronoi opens the completed mesh; blue dots mark circumcentres, which may lie outside the drawing window.

Video walkthrough

What makes a triangulation Delaunay

A triangulation covers the convex hull with triangles whose interiors do not overlap. Every input point is a vertex, and edges meet only at shared endpoints. In a Delaunay triangulation, the open disk bounded by each triangle’s circumcircle contains no other input point. Points on the circle are allowed.

The condition does not say that every triangle is equilateral or that long edges disappear. The geometry of the input still matters. A skinny triangle can be unavoidable, particularly near a nearly straight boundary.

Start with any valid triangulation

First find the convex hull with the two scans from the previous article. Join its first vertex to the other hull vertices to make a fan. Insert the remaining points one at a time: an interior point splits its containing triangle into three. A point on an edge splits the one or two adjacent triangles, omitting zero-area pieces.

The mesh now includes all points. Its triangle interiors are disjoint and its outer boundary is the convex hull. This invariant remains true after each subsequent edge flip. During the initial fan, only part of the hull has been filled; the completed-mesh invariant starts at the All points included step.

One circle, one neighbouring vertex

Take an interior edge shared by two triangles. If their union is a convex quadrilateral, draw the circumcircle of one triangle and test the opposite vertex of the other. Strictly inside means that this diagonal violates the empty-circle condition. Replace it with the other diagonal. Outside means keep the edge. On the circle means both diagonals are allowed; this implementation keeps the current one.

After a flip, neighbouring edges may need another check. The player rebuilds the edge list and scans again from the start. A whole scan without a flip completes the Delaunay triangulation. Boundary edges have only one adjacent triangle, and a nonconvex pair cannot be flipped.

The connection to Voronoi diagrams

Enable the Voronoi layer to open the completed mesh with the nearest-site cell boundaries overlaid. Cells are clipped to the same rectangular drawing window, while the triangulation fills the convex hull. Blue dots are triangle circumcentres. A circumcentre can lie outside its triangle or outside the window.

In general position, the circumcentres of two adjacent Delaunay triangles are joined by a Voronoi edge perpendicular to their shared edge. With four cocircular points, two circumcentres can coincide: the chosen diagonal then has a dual of zero length. The layer computes cells by half-plane clipping, so it also shows these degeneracies and the unbounded cells clipped to the window.

Move the points and compare the steps

Seven points shows the hull fan, insertion and flips. Change the diagonal isolates a four-point example. On one circle shows a tie with no forced flip. Points on edges tests insertion on a shared diagonal and on the hull boundary. On one line produces a chain of adjacent points and no triangles.

Drag a point or edit its coordinates. During a drag the completed mesh is previewed, and releasing keeps that result. Restart opens the construction of the edited input. The coordinate editor gives keyboard access to selection, moving, adding and removing points. Invalid input keeps the previous session. Sharing preserves points, position, speed and the Voronoi setting on a clean player page. Video export records the full construction from the start, without sound.

Exact decisions on a bounded grid

The editor accepts 1–16 distinct points in x=0…100 and y=0…70, rounded to 0.1. Coincident rounded points are rejected. One point has no edges; collinear points have a chain but no two-dimensional triangulation. Four or more cocircular points can admit several correct triangulations. The chosen answer is deterministic for a fixed input order, without claiming a unique diagonal.

Orientation and incircle use integer ticks, ten per coordinate unit. Incircle assumes counterclockwise triangle vertices: a positive determinant means inside, zero means on the circle, negative means outside. In this bounded range all intermediate integers are below 2^53, so signs are exact without an epsilon. Circumcentres use floating-point arithmetic only for drawing. This guarantee does not extend to arbitrary coordinates; robust predicates are needed beyond the stated limits.

Counters, work and stored history

Circle tests counts only incircle evaluations for flippable interior edges. It does not count orientation tests used to build the hull, locate a point or check convexity. Flips counts replaced diagonals. Triangles counts current faces, so it changes during fan construction and insertion but not during a flip.

Without recording history, this teaching algorithm deliberately rescans the mesh. For n points and F flips, constructing the initial mesh costs O(n²), and rebuilding and sorting O(n) edges after each flip costs O((F+1)n log n), assuming O(k log k) sorting. Working memory is O(n). This is separate from faster Delaunay implementations.

For backward steps, seeking and export, every snapshot owns copies of its triangle and edge arrays. If there are C circle tests and F flips, there are O(n+C+F) snapshots with O(n) data each: history takes O(n(n+C+F)) space and copying work. Recording also rebuilds and sorts edges for each snapshot, adding O(n log n) work per snapshot. The 16-point limit keeps the scene and history manageable.

Executable edge-flip code

The function below performs the same legalization phase as the player. Pass points on the validated 0.1 grid and an initial triangulation containing every point, such as the All points included step. Faces are triples of point indices in counterclockwise order. The function copies the faces, flips only convex quadrilaterals and preserves cocircular ties. Hull construction and point insertion are the preceding phase described above.

Show the executable model
function legalizeDelaunay(points, initialTriangles) {
  const p = points.map(({x, y}) => ({x: Math.round(x * 10), y: Math.round(y * 10)}));
  const cross = (a, b, c) => (p[b].x-p[a].x)*(p[c].y-p[a].y)-(p[b].y-p[a].y)*(p[c].x-p[a].x);
  const ccw = (a,b,c) => cross(a,b,c)>0 ? [a,b,c] : [b,a,c];
  const incircle = (a,b,c,d) => {
    const ax=p[a].x-p[d].x, ay=p[a].y-p[d].y;
    const bx=p[b].x-p[d].x, by=p[b].y-p[d].y;
    const cx=p[c].x-p[d].x, cy=p[c].y-p[d].y;
    return (ax*ax+ay*ay)*(bx*cy-by*cx)
      -(bx*bx+by*by)*(ax*cy-ay*cx)
      +(cx*cx+cy*cy)*(ax*by-ay*bx);
  };
  let faces=initialTriangles.map(t=>[...t]);
  for (;;) {
    const edges=new Map();
    faces.forEach((t,index)=>{
      for(let k=0;k<3;k++) {
        const a=Math.min(t[k],t[(k+1)%3]), b=Math.max(t[k],t[(k+1)%3]);
        const key=a+":"+b, edge=edges.get(key)||{a,b,owners:[]};
        edge.owners.push({index,opposite:t[(k+2)%3]});edges.set(key,edge);
      }
    });
    let changed=false;
    for(const {a,b,owners} of [...edges.values()].sort((x,y)=>x.a-y.a||x.b-y.b)) {
      if(owners.length!==2) continue;
      const [left,right]=owners, c=left.opposite, d=right.opposite;
      if(cross(c,d,a)*cross(c,d,b)>=0) continue;
      const t=faces[left.index];
      if(incircle(t[0],t[1],t[2],d)<=0) continue;
      faces=faces.filter((_,i)=>i!==left.index&&i!==right.index);
      faces.push(ccw(c,d,a),ccw(d,c,b));changed=true;break;
    }
    if(!changed) return faces;
  }
}

Sources