Voronoi Diagrams and Delaunay Triangulations O’Rourke, Chapter 5 Outline • Preliminaries • Voronoi Diagrams / Delaunay Triangulations • Lloyd’s Algorithm Preliminaries Claim: Given a connected planar graph with 푉 vertices, 퐸 edges, and 퐹 faces*, the graph satisfies: 푉 − 퐸 + 퐹 = 2

*The “external” face also counts. (Can think of this as a graph on the sphere.) Preliminaries Proof: 1. Show that this is true for trees. 2. Show that this is true by induction. Preliminaries Proof (for Trees): If a graph is a connected tree, it satisfies: 푉 = 퐸 + 1. Since there is only one (external) face: 푉 − 퐸 + 퐹 = (퐸 + 1) − 퐸 + 1 = 2 Preliminaries Proof (by Induction): Suppose that we are given a graph 퐺.  If it’s a tree, we are done.  Otherwise, it has a cycle. Removing an edge on the cycle gives a graph 퐺′ with:  The same vertex set (푉′ = 푉)  One less edge (퐸′ = 퐸 − 1)  One less face (퐹′ = 퐹 − 1) By induction: 2 = 푉′ − 퐸′ + 퐹′ = 푉 − 퐸 + 퐹 Preliminaries Note: Given a planar graph 퐺, we can get a planar graph 퐺′ with faces:  Triangulate the interior polygons  Add a “virtual point” outside and triangulate the exterior polygon. Preliminaries Note: The new graph has:  푉′ = 푉 + 1, 퐸′ ≥ 퐸, 퐹′ ≥ 퐹  푉′ − 퐸′ + 퐹′ = 2  3퐸′ = 2퐹′ Preliminaries Note: The new graph has:  푉′ = 푉 + 1, 퐸′ ≥ 퐸, 퐹′ ≥ 퐹  푉′ − 퐸′ + 퐹′ = 2  3퐸′ = 2퐹′ This gives: 퐸′ = 3푉′ − 6 퐹′ = 2푉′ − 4 ⇓ ⇓ 퐸 ≤ 3푉 − 3 퐹 ≤ 2푉 − 2 The number of edges/faces of a planar graph is linear in the number of vertices. Preliminaries Definition: 푑 Given a set of points {푝1, … , 푝푛} ⊂ ℝ , the nearest- neighbor graph is the directed graph with an edge from 푝푖 to 푝푗, whenever: 푝푘 − 푝푖 ≥ 푝푗 − 푝푖 ∀1 ≤ 푘 ≤ 푛.

Naively, the nearest-neighbor can be computed in 푂(푛2) time by testing all possible neighbors. Outline • Preliminaries • Voronoi Diagrams / Delaunay Triangulations • Lloyd’s Algorithm Voronoi Diagrams Definition:

Given points 푃 = 푝1, … , 푝푛 , the Voronoi region of point 푝푖, 푉(푝푖) is the set of points at least as close to 푝푖 as to any other point in 푃: 푉 푝푖 = 푥 푝푖 − 푥 ≤ 푝푗 − 푥 ∀1 ≤ 푗 ≤ 푛 Voronoi Diagrams Definition: The set of points with more than one nearest neighbor in 푃 is the of 푃:  The set with two nearest neighbors make up the edges of the diagram.  The set with three or more nearest neighbors make up the vertices of the diagram.

The points 푃 are called the sites of the Voronoi diagram. Voronoi Diagrams 2 Points:

When 푃 = 푝1, 푝2 , the regions are defined by the perpendicular bisector:

퐻(푝2, 푝1) 푝2

푝1 퐻(푝1, 푝2) Voronoi Diagrams 3 Points:

When 푃 = 푝1, 푝2, 푝3 , the regions are defined by the three perpendicular bisectors:

푝2

푝2

푝3

푝1 푝1 Voronoi Diagrams 3 Points: The three bisectors intersect at a point WhenThe 푃 intersection= 푝1, 푝2, 푝can3 ,be the outside regions the triangle. are defined by theThe three point of perpendicular intersection is center bisectors: of the circle passing through the three points. 푝2

푝2

푝3

푝1 푝1 Voronoi Diagrams More Generally:

The Voronoi region associated to point 푝푖 is the intersection of the half-spaces defined by the perpendicular bisectors: 푉 푝푖 =∩푗≠푖 퐻(푝푖, 푝푗)

푝푖 Voronoi Diagrams More Generally:

The Voronoi region associated to point 푝푖 is the intersection of the half-spaces defined by the perpendicular bisectors: ⇒ Voronoi푉 푝regions푖 =∩ 푗are≠푖 convex퐻(푝푖, 푝polygons.푗)

푝푖 Voronoi Diagrams More Generally: Voronoi Diagrams More Generally:

Voronoi regions are in 1-to-1 correspondence with points. Most Voronoi vertices have valence 3. Voronoi faces can be unbounded. Voronoi Diagrams Properties:  Each Voronoi region is convex.

 푉 푝푖 is unbounded ⇔ 푝푖 is on the of 푃.  If 푣 is a at the junction of 푉(푝1),…, 푉(푝푘),with 푘 ≥ 3, then 푣 is the center of a circle, 퐶(푣), with 푝1, … , 푝푘 on the boundary.  The interior of 퐶(푣) contains no points. Delaunay Definition: The Delaunay triangulation is the straight-line dual of the Voronoi Diagram. Note: The Delaunay edges don’t have to cross their Voronoi duals. Delaunay Triangulation Properties:  The edges of 퐷(푃) don’t intersect.  퐷(푃) is a triangulation if no 4 points are co-circular.  The boundary of 퐷(푃) is the convex hull of 푃.  If 푝푗 is the nearest neighbor of 푝푖 then 푝푖푝푗 is a Delaunay edge.  There is a circle through 푝푖 and 푝푗 that does not contain any other points ⇔ 푝푖푝푗 is a Delaunay edge.  The circumcircle of 푝푖, 푝푗, and 푝푘 is empty ⇔ Δ푝푖푝푗푝푘 is Delaunay triangle. Delaunay Triangulation Note: Assuming that the edges of 퐷(푃) do not cross, we get a planar graph. ⇒ The number of edges/faces in a Delaunay Triangulation is linear in the number of vertices. ⇒ The number of edges/vertices in a Voronoi Diagram is linear in the number of faces. ⇒ The number of vertices/edges/faces in a Voronoi Diagram is linear in the number of sites. Delaunay Triangulation Properties:  The boundary of 퐷(푃) is the convex hull of 푃. Proof:

Suppose that 푝푖푝푗 is an edge of the hull of 푃. Consider circles with center on the bisector that intersect 푝푖 and 푝푗. As we move out along the bisector the circle converges to 푝푗 the half-space to the right of 푝푖푝푗.

푝푖 Delaunay Triangulation Properties:  The boundary of 퐷(푃) is the convex hull of 푃. Proof:

Suppose that 푝푖푝푗 is an edge of the hull of 푃. ⇒ There is an (infinite) region on the bisector that is closer to 푝푖 and 푝푗 than to any other points. ⇒ There is a Voronoi edge 푝푗 between 푝푖 and 푝푗. 푝 ⇒ The dual edge is in 퐷(푃). 푖 Delaunay Triangulation Properties:

 If 푝푗 is the nearest neighbor of 푝푖 then 푝푖푝푗 is a Delaunay edge. Proof:

푝푗 is the nearest neighbor of 푝푖 iff. the circle around 푝푖 with radius |푝푖 − 푝푗| is empty of other points.

⇒ The circle through (푝푖 + 푝푗)/2 with radius 푝 푝푖 − 푝푗 /2 is empty of other points. 푗 ⇒ (푝 + 푝 )/2 is on the Voronoi diagram. 푖 푗 푝푖

⇒ (푝푖 + 푝푗)/2 is on a Voronoi edge. Delaunay Triangulation Properties:

 If 푝푗 is the nearest neighbor of 푝푖 then 푝푖푝푗 is a Delaunay edge. Implications: The is a subset of the Delaunay triangulation. We will show that the Delaunay triangulation can be computed in 푂(푛 log 푛 ) time. ⇒ We can compute the nearest-neighbor graph in 푂 푛 log 푛 . Delaunay Triangulation Properties:

 There is a circle through 푝푖 and 푝푗 that does not contain any other points ⇔ 푝푖푝푗 is a Delaunay edge. Proof (⇐):

If 푝푖푝푗 is a Delaunay edge, then the Voronoi regions 푉(푝푖) and 푉(푝푗) intersect at an edge. Set 푣 to be some point on the interior of the edge.

푣 − 푝푖 = 푣 − 푝푗 = 푟 and 푣 − 푝푘 > 푟 ∀푘 ≠ 푖, 푗. The circle at 푣 with radius 푟 is empty of other points. Delaunay Triangulation Properties:

 There is a circle through 푝푖 and 푝푗 that does not contain any other points ⇔ 푝푖푝푗 is a Delaunay edge. Proof (⇒):

If there is a circle through 푝푖 and 푝푗, empty of other points, with center 푥, then 푥 ∈ 푉 푝푖 ∩ 푉 푝푗 . Since no other point is in or on the circle there is a neighborhood of centers around 푥 on the bisector with circles 푥 푝푗 through 푝푖 and 푝푗 empty of other points.

푥 is on a Voronoi edge. 푝푖 Delaunay Triangulation Properties:  The edges of 퐷(푃) don’t intersect. Proof:

Given an edge 푝푖푝푗 in 퐷(푃), there is a circle with 푝푖 and 푝푗 on its boundary and empty of other points.

Let be 푝푘푝푙 be an edge in 퐷(푝) that intersect 푝푖푝푗: 푝푘 and 푝푙 cannot be in the circle. ⇒ 푝푘 and 푝푙 are not in the triangle Δ푐푖푗푝푖푝푗 푝 ⇒ 푝푘푝푙 intersects either 푐푖푗푝푖 or 푐푖푗푝푗. 푐푖푗 푗 ⇒ 푝푖푝푗 intersects either 푐푘푙푝푘 or 푐푘푙푝푙. 푝푘 푝 푐푘푙 푝 푙 ⇒ One of 푐푖푗푝푖 or 푐푖푗푝푗 one of 푐푘푙푝푘 or 푐푘푙푝푙. 푖 Delaunay Triangulation Properties:  The edges of 퐷(푃) don’t intersect. Proof:

Given an edge 푝푖푝푗 in 퐷(푃), there is a circle with 푝푖 and 푝푗 on its boundary and empty of other points. But 푐푖푗푝푖 is in the Voronoi region of 푝푖 and 푐푘푙푝푘 is Let be 푝푘푝푙 be an edge in 퐷(푝) that intersect 푝푖푝푗: in the Voronoi region of 푝푘, so they cannot intersect. 푝푘 and 푝푙 cannot be in the circle. ⇒ 푝푘 and 푝푙 are not in the triangle Δ푐푖푗푝푖푝푗 푝 ⇒ 푝푘푝푙 intersects either 푐푖푗푝푖 or 푐푖푗푝푗. 푐푖푗 푗 ⇒ 푝푖푝푗 intersects either 푐푘푙푝푘 or 푐푘푙푝푙. 푝푘 푝 푐푘푙 푝 푙 ⇒ One of 푐푖푗푝푖 or 푐푖푗푝푗 one of 푐푘푙푝푘 or 푐푘푙푝푙. 푖 Outline • Preliminaries • Voronoi Diagrams / Delaunay Triangulations  Naive Algorithm  Fortune’s Algorithm • Lloyd’s Algorithm Naive Algorithm

Delaunay( {푝1, … , 푝푛} )  for 푖 ∈ 1, 푛 »for 푗 ∈ 1, 푖 – for 푘 ∈ [1, 푗) • (푐, 푟) ← Circumcircle( 푝푖 , 푝푗 , 푝푘 ) • isTriangle ← true • for 푙 ∈ [1, 푘) • if( 푝푙 − 푐 < 푟 ) isTriangle ← false • if( isTriangle ) Output( 푝푖 , 푝푗 , 푝푘 )

Complexity: 푂(푛4) Voronoi Diagrams and Cones Key Idea: We can think of generating Voronoi regions by expanding circles centered at points of 푃. When multiple circles overlap a point, track the one that is closer. Voronoi Diagrams and Cones Key Idea: We can visualize the Voronoi regions by drawing right cones over the points, with axes along the positive 푧-axis. Circles with radius 푟 are the projections of the intersections of the plane 푧 = 푟 plane with the cones, onto the 푥푦-plane. 푧 푟 푟 푟 푥 Voronoi Diagrams and Cones Key Idea: To track the closer circle, we can render the cones with an orthographic camera looking up the 푧-axis.

푥 Voronoi Diagrams and Cones Key Idea: To track the closer circle, we can render the cones with an orthographic camera looking up the 푧-axis.

Visualization Fortune’s Algorithm Approach: Sweep a line and maintain the solution for all points behind the line. Fortune’s Algorithm Why This Shouldn’t Work: The Voronoi region behind the line can depend on points that are in front of the line! (Looking up the 푧-axis, we see the cone before the apex.) Key Idea: We can finalize points behind the line that are closer to a site than to the line. Fortune’s Algorithm 푝 Given a site 푝 ∈ 푃 and the 푦 = 푦0 line with height 푦0, we can finalize the points satisfying: 2 2 (푥, 푦) 푦 − 푦0 > 푝 − (푥, 푦) Points on the boundary satisfy: 2 2 푦 − 푦0 = 푝 − (푥, 푦) Setting 푧 = 푝 − (푥, 푦) , this gives: 푧 = 푦 − 푦0 Fortune’s Algorithm 푝 Formally: 푦 = 푦0 ⇒ We can describe the points on the boundary as the 푥푦-coordinates of the points in 3D with: Points on the right cone, 1. 푧 = 푝 − (푥, 푦) centered at 푝, centered around the positive 푧-axis 2. 푧 = 푦 − 푦0 Points on the plane, Sweep the cones making a 45∘ angle with the 푥푦-plane, with a plane parallel passing through the line 푦 = 푦0 and 푧 = 0 to the 푥-axis making a 45∘ angle with the 푥푦-plane. Fortune’s Algorithm Fortune’s Algorithm

Sweep with a plane 휋푦, parallel to the 푥-axis, making a 45∘ angle with the 푥푦-plane. “Render” the cones and the plane with an orthographic camera looking up the 푧-axis. At each point, we see:

 The part of 휋푦 that is in front of the line (since it is below the 푥푦-plane and hence below the cones).  The part of the cones that are behind the line and below 휋푦. Fortune’s Algorithm As 푦 advances, the algorithm maintains a set of parabolic fronts (the projection of the intersections of 휋푦 with the cones). At any point, the Voronoi diagram is finalized behind the parabolic fronts. Fortune’s Algorithm As 푦 advances, the algorithm maintains a set of parabolic fronts (the projection of the intersections of 휋푦 with the cones). At any point, the Voronoi diagram is finalized behind the Implementationparabolic :fronts. • The fronts are maintained in order. • As 푦 intersects a site, its front is inserted. • Complexity 푂(푛 log 푛). Outline • Preliminaries • Voronoi Diagrams / Delaunay Triangulations • Lloyd’s Algorithm Lloyd’s Algorithm Challenge:

Solve for the position of points 푃 = {푝1, … , 푝푛} inside the unit square minimizing: 퐸 푃 = 푑2(푞, 푃) 푑푞 0,1 2

where 푑 푞, 푃 = min |푝푖 − 푞|. 푖 Lloyd’s Algorithm Approach: 1. Initialize the points to random positions. 2. Compute the Voronoi Diagram of the points, clipped to the unit square. 3. Set the positions of the points to the centers of mass of the corresponding Voronoi cells. 4. Go to step 2. Lloyd’s Algorithm Lloyd’s Algorithm 2. Compute the Voronoi Diagram of the points, clipped to the unit square. Since: 2 2 푑 (푞, 푃) 푑푞 = 푝푖 − 푞 푑푞 2 0,1 퐹푖 퐹푖∈푉 푃 this provides the assignment of points in 0,1 2 to points in 푃 that minimize the energy. Lloyd’s Algorithm 3. Set the positions of the points to the centers of mass of the corresponding Voronoi cells. Since: arg min 푝 − 푞 2푑푞 = 퐶(퐹) 푝∈ 0,1 2 퐹 with 퐶(퐹) the center of mass of face 퐹, repositioning to the center reduces the energy.