Voronoi diagrams - UCLouvain

71
Voronoi diagrams J.-F. Remacle Universit´ e catholique de Louvain October 15, 2013 0

Transcript of Voronoi diagrams - UCLouvain

Page 1: Voronoi diagrams - UCLouvain

Voronoi diagrams

J.-F. Remacle

Universite catholique de Louvain

October 15, 2013

0

Page 2: Voronoi diagrams - UCLouvain

Voronoi diagrams

1

Page 3: Voronoi diagrams - UCLouvain

The Supermarket Problem

Suppose we aim at distributing N supermarkets in a given region insuch a way that it optimizes the number of customers they will attract.

For this you have to model the behavior of your potential customers:how do people decide where to do their shopping? To study thisquestion we make the following simplifying assumptions:

• the price of a particular good or service is the same at every site;

• the cost of acquiring the good or service is equal to the price plusthe cost of transportation to the site;

• the cost of transportation to a site equals the Euclidean distanceto the site times a fixed price per unit distance;

• consumers try to minimize the cost of acquiring the good or ser-vice.

2

Page 4: Voronoi diagrams - UCLouvain

The Supermarket Problem

The assumptions in the model induce a subdivision of the total areaunder consideration into regions such that the people who live in thesame region all go to the same site. Our assumptions imply that peoplesimply get their goods at the nearest site. The model where everypoint is assigned to the nearest site is called the Voronoi assignmentmodel. The subdivision induced by this model is called the Voronoidiagram of the set of sites.

7 Voronoi DiagramsThe Post Office Problem

Suppose you are on the advisory board for the planning of a supermarket chain,and there are plans to open a new branch at a certain location. To predict whetherthe new branch will be profitable, you must estimate the number of customers itwill attract. For this you have to model the behavior of your potential customers:how do people decide where to do their shopping? A similar question arises insocial geography, when studying the economic activities in a country: what isthe trading area of certain cities? In a more abstract setting we have a set of

Figure 7.1The trading areas of the capitals of thetwelve provinces in the Netherlands, aspredicted by the Voronoi assignmentmodel

central places—called sites—that provide certain goods or services, and we wantto know for each site where the people live who obtain their goods or servicesfrom that site. (In computational geometry the sites are traditionally viewedas post offices where customers want to post their letters—hence the subtitleof this chapter.) To study this question we make the following simplifyingassumptions:

the price of a particular good or service is the same at every site;the cost of acquiring the good or service is equal to the price plus the costof transportation to the site; 147

3

Page 5: Voronoi diagrams - UCLouvain

Definitions

Consider a set P of N distinct points P := p1, . . . ,pN in the plane

R2. These points are called the sites. We define the Voronoi diagram

of P as the subdivision of the plane into N cells, one for each site in

P , with the property that a point q lies in the cell corresponding to a

site pi if and only if

dist(q,pi) < dist(q,pj) ∀pj ∈ P, j 6= i.

Here, dist(a,b) is the euclidian distance between a and b.

We denote the Voronoi diagram of P by Vor(P ). The cell of Vor(P )

that corresponds to a site pi is denoted V(pi); we call it the Voronoi

cell of pi.

4

Page 6: Voronoi diagrams - UCLouvain

Orthogonal Bissectors

Consider two points p and q. We define the orthogonal bisector ofp and q as the perpendicular bisector of the line segment pq. Thisbisector splits the plane into two half-planes.

We denote the open half-plane that contains p by h(p,q) and the openhalf-plane that contains q by h(q,p). Notice that r ∈ h(p,q) if and onlyif dist(r,p) < dist(r,q).

We have

V(pi) =⋂

1≤j≤N,j 6=i

h(pi,pj).

Section 7.1DEFINITION AND BASIC PROPERTIES

say that a Voronoi diagram is connected we mean that the union of its edges andvertices forms a connected set. The cell of Vor(P) that corresponds to a site piis denoted V(pi); we call it the Voronoi cell of pi. (In the terminology of theintroduction to this chapter: V(pi) is the trading area of site pi.)

We now take a closer look at the Voronoi diagram. First we study thestructure of a single Voronoi cell. For two points p and q in the plane we definethe bisector of p and q as the perpendicular bisector of the line segment pq. Thisbisector splits the plane into two half-planes. We denote the open half-planethat contains p by h(p,q) and the open half-plane that contains q by h(q, p).Notice that r ∈ h(p,q) if and only if dist(r, p) < dist(r,q). From this we obtainthe following observation.

Observation 7.1 V(pi) =⋂

1! j!n, j "=i h(pi, p j).

Thus V(pi) is the intersection of n−1 half-planes and, hence, a (possiblyunbounded) open convex polygonal region bounded by at most n−1 verticesand at most n−1 edges.

What does the complete Voronoi diagram look like? We just saw that eachcell of the diagram is the intersection of a number of half-planes, so the Voronoidiagram is a planar subdivision whose edges are straight. Some edges are linesegments and others are half-lines. Unless all sites are collinear there will be noedges that are full lines:

Theorem 7.2 Let P be a set of n point sites in the plane. If all the sites arecollinear then Vor(P) consists of n − 1 parallel lines. Otherwise, Vor(P) isconnected and its edges are either segments or half-lines.

Proof. The first part of the theorem is easy to prove, so assume that not all sitesin P are collinear.

We first show that the edges of Vor(P) are either segments or half-lines. Wealready know that the edges of Vor(P) are parts of straight lines, namely parts ofthe bisectors between pairs of sites. Now suppose for a contradiction that thereis an edge e of Vor(P) that is a full line. Let e be on the boundary of the Voronoicells V(pi) and V(p j). Let pk ∈ P be a point that is not collinear with pi and p j.The bisector of p j and pk is not parallel to e and, hence, it intersects e. But then

pi p j

pke

the part of e that lies in the interior of h(pk, p j) cannot be on the boundary ofV(p j), because it is closer to pk than to p j, a contradiction.

It remains to prove that Vor(P) is connected. If this were not the casethen there would be a Voronoi cell V(pi) splitting the plane into two. BecauseVoronoi cells are convex, V(pi) would consist of a strip bounded by two parallelfull lines. But we just proved that the edges of the Voronoi diagram cannot befull lines, a contradiction.

Now that we understand the structure of the Voronoi diagram we investigateits complexity, that is, the total number of its vertices and edges. Since there aren sites and each Voronoi cell has at most n−1 vertices and edges, the complexityof Vor(P) is at most quadratic. It is not clear, however, whether Vor(P) canactually have quadratic complexity: it is easy to construct an example wherea single Voronoi cell has linear complexity, but can it happen that many cells 149

5

Page 7: Voronoi diagrams - UCLouvain

Complexity of Voronoi Diagrams

Since there are N sites and each Voronoi cell has at most N−1 vertices

and edges, the complexity of Vor(P ) is therefore at most quadratic.

If all the sites are collinear then Vor(P ) consists of N −1 parallel lines.

Otherwise, Vor(P ) is connected and its edges are either segments or

half-lines.

Theorem : For N ≥ 3, the number of vertices nv in the Voronoi

diagram of a set of N sites in the plane is at most 2N − 5 and the

number of edges ne is at most 3N − 6.

Euler’s formula : for any connected planar embedded graph with nv

nodes, ne edges and nf faces, the following relation holds:

nv − ne + nf = 2.

6

Page 8: Voronoi diagrams - UCLouvain

Complexity of Voronoi Diagrams

Create an augmented graph that is connected:

Chapter 7VORONOI DIAGRAMS

have linear complexity? The following theorem shows that this is not the caseand that the average number of vertices of the Voronoi cells is less than six.

Theorem 7.3 For n ! 3, the number of vertices in the Voronoi diagram of a setof n point sites in the plane is at most 2n−5 and the number of edges is at most3n−6.

Proof. If the sites are all collinear then the theorem immediately follows fromTheorem 7.2, so assume this is not the case. We prove the theorem using Euler’sformula, which states that for any connected planar embedded graph with mvnodes, me arcs, and m f faces the following relation holds:

mv −me +m f = 2.

We cannot apply Euler’s formula directly to Vor(P), because Vor(P) has half-

v∞infinite edges and is therefore not a proper graph. To remedy the situation weadd one extra vertex v∞ “at infinity” to the set of vertices and we connect allhalf-infinite edges of Vor(P) to this vertex. We now have a connected planargraph to which we can apply Euler’s formula. We obtain the following relationbetween nv, the number of vertices of Vor(P), ne, the number of edges of Vor(P),and n, the number of sites:

(nv +1)−ne +n = 2. (7.1)

Moreover, every edge in the augmented graph has exactly two vertices, so ifwe sum the degrees of all vertices we get twice the number of edges. Becauseevery vertex, including v∞, has degree at least three we get

2ne ! 3(nv +1). (7.2)

Together with equation (7.1) this implies the theorem.

We close this section with a characterization of the edges and vertices of theVoronoi diagram. We know that the edges are parts of bisectors of pairs of sitesand that the vertices are intersection points between these bisectors. There isa quadratic number of bisectors, whereas the complexity of the Vor(P) is onlylinear. Hence, not all bisectors define edges of Vor(P) and not all intersectionsare vertices of Vor(P). To characterize which bisectors and intersections definefeatures of the Voronoi diagram we make the following definition. For a pointq we define the largest empty circle of q with respect to P, denoted by CP(q),as the largest circle with q as its center that does not contain any site of P in

q

CP(q)

its interior. The following theorem characterizes the vertices and edges of theVoronoi diagram.

Theorem 7.4 For the Voronoi diagram Vor(P) of a set of points P the followingholds:(i) A point q is a vertex of Vor(P) if and only if its largest empty circle CP(q)

contains three or more sites on its boundary.(ii) The bisector between sites pi and p j defines an edge of Vor(P) if and only

if there is a point q on the bisector such that CP(q) contains both pi and p jon its boundary but no other site.150

Euler’s formula applied to that graph gives:

(nv + 1)− ne +N = 2

7

Page 9: Voronoi diagrams - UCLouvain

Complexity of Voronoi Diagrams

Every edge in the augmented graph has exactly two vertices, so if

we sum the degree of all vertices, we get twice the number of edges.

Moreover, the degree of one vertex is at least 3 because V(P ) is

composed of edges or half-lines. Then,

2ne ≥ 3(nv + 1).

This leads to

3(nv + 1) = 6 + 3ne − 3N ≤ 2ne → ne ≤ 3N − 6.

and

2(3N − 6) ≥ 3(nv + 1) → nv ≤ 2N − 5.

We conclude that the complexity will never be quadratic.

8

Page 10: Voronoi diagrams - UCLouvain

Empty circles

For a point q we define the largest empty circle of q with respect to

P , denoted by CP (q), as the largest circle with q as its center that

does not contain any site of P in its interior.

Chapter 7VORONOI DIAGRAMS

have linear complexity? The following theorem shows that this is not the caseand that the average number of vertices of the Voronoi cells is less than six.

Theorem 7.3 For n ! 3, the number of vertices in the Voronoi diagram of a setof n point sites in the plane is at most 2n−5 and the number of edges is at most3n−6.

Proof. If the sites are all collinear then the theorem immediately follows fromTheorem 7.2, so assume this is not the case. We prove the theorem using Euler’sformula, which states that for any connected planar embedded graph with mvnodes, me arcs, and m f faces the following relation holds:

mv −me +m f = 2.

We cannot apply Euler’s formula directly to Vor(P), because Vor(P) has half-

v∞infinite edges and is therefore not a proper graph. To remedy the situation weadd one extra vertex v∞ “at infinity” to the set of vertices and we connect allhalf-infinite edges of Vor(P) to this vertex. We now have a connected planargraph to which we can apply Euler’s formula. We obtain the following relationbetween nv, the number of vertices of Vor(P), ne, the number of edges of Vor(P),and n, the number of sites:

(nv +1)−ne +n = 2. (7.1)

Moreover, every edge in the augmented graph has exactly two vertices, so ifwe sum the degrees of all vertices we get twice the number of edges. Becauseevery vertex, including v∞, has degree at least three we get

2ne ! 3(nv +1). (7.2)

Together with equation (7.1) this implies the theorem.

We close this section with a characterization of the edges and vertices of theVoronoi diagram. We know that the edges are parts of bisectors of pairs of sitesand that the vertices are intersection points between these bisectors. There isa quadratic number of bisectors, whereas the complexity of the Vor(P) is onlylinear. Hence, not all bisectors define edges of Vor(P) and not all intersectionsare vertices of Vor(P). To characterize which bisectors and intersections definefeatures of the Voronoi diagram we make the following definition. For a pointq we define the largest empty circle of q with respect to P, denoted by CP(q),as the largest circle with q as its center that does not contain any site of P in

q

CP(q)

its interior. The following theorem characterizes the vertices and edges of theVoronoi diagram.

Theorem 7.4 For the Voronoi diagram Vor(P) of a set of points P the followingholds:(i) A point q is a vertex of Vor(P) if and only if its largest empty circle CP(q)

contains three or more sites on its boundary.(ii) The bisector between sites pi and p j defines an edge of Vor(P) if and only

if there is a point q on the bisector such that CP(q) contains both pi and p jon its boundary but no other site.150

9

Page 11: Voronoi diagrams - UCLouvain

Empty circles

Theorem : For the Voronoi diagram Vor(P ) of a set of points P thefollowing holds:

• A point q is a vertex of Vor(P ) if and only if its largest emptycircle CP (q) contains three or more sites on its boundary.

• The bisector between sites pi and pj defines an edge of Vor(P )if and only if there is a point q on the bisector such that CP (q)contains both pi and pj on its boundary but no other site.

Section 7.2COMPUTING THE VORONOI DIAGRAM

Proof. (i) Suppose there is a point q such that CP(q) contains three or more siteson its boundary. Let pi, p j, and pk be three of those sites. Since the interiorof CP(q) is empty q must be on the boundary of each of V(pi), V(p j), andV(pk), and q must be a vertex of Vor(P).

On the other hand, every vertex q of Vor(P) is incident to at least threeedges and, hence, to at least three Voronoi cells V(pi), V(p j), and V(pk).Vertex q must be equidistant to pi, p j, and pk and there cannot be anothersite closer to q, since otherwise V(pi), V(p j), and V(pk) would not meet at q.Hence, the interior of the circle with pi, p j, and pk on its boundary does notcontain any site.

(ii) Suppose there is a point q with the property stated in the theorem. SinceCP(q) does not contain any sites in its interior and pi and p j are on itsboundary, we have dist(q, pi) = dist(q, p j) ! dist(q, pk) for all 1 ! k ! n.It follows that q lies on an edge or vertex of Vor(P). The first part of thetheorem implies that q cannot be a vertex of Vor(P). Hence, q lies on an edgeof Vor(P), which is defined by the bisector of pi and p j.

Conversely, let the bisector of pi and p j define a Voronoi edge. Thelargest empty circle of any point q in the interior of this edge must contain piand p j on its boundary and no other sites.

7.2 Computing the Voronoi Diagram

In the previous section we studied the structure of the Voronoi diagram. Wenow set out to compute it. Observation 7.1 suggests a simple way to do this:for each site pi, compute the common intersection of the half-planes h(pi, p j),with j != i, using the algorithm presented in Chapter 4. This way we spendO(n logn) time per Voronoi cell, leading to an O(n2 logn) algorithm to computethe whole Voronoi diagram. Can’t we do better? After all, the total complexityof the Voronoi diagram is only linear. The answer is yes: the plane sweepalgorithm described below—commonly known as Fortune’s algorithm afterits inventor—computes the Voronoi diagram in O(n logn) time. You may betempted to look for an even faster algorithm, for example one that runs in lineartime. This turns out to be too much to ask: the problem of sorting n real numbersis reducible to the problem of computing Voronoi diagrams, so any algorithmfor computing Voronoi diagrams must take Ω(n logn) time in the worst case.Hence, Fortune’s algorithm is optimal.

The strategy in a plane sweep algorithm is to sweep a horizontal line—thesweep line—from top to bottom over the plane. While the sweep is performedinformation is maintained regarding the structure that one wants to compute.More precisely, information is maintained about the intersection of the structurewith the sweep line. While the sweep line moves downwards the informationdoes not change, except at certain special points—the event points.

Let’s try to apply this general strategy to the computation of the Voronoi diagramof a set P = p1, p2, . . . , pn of point sites in the plane. According to the plane 151

10

Page 12: Voronoi diagrams - UCLouvain

Computing Voronoi Diagrams

Many methods available :

• Explicit computation through intersection of half planes (voro++);

• Iterative computation (related to Sibson or natural interpolation);

• Sweep line (Fortune’s algorithm);

• Dual of the Delaunay triangulation;

• ...

11

Page 13: Voronoi diagrams - UCLouvain

Doubly connected edge list

(Partial) Voronoi diagram: The partial Voronoi diagram that has

been constructed so far will be stored in a DCEL. There is one techni-

cal difficulty caused by the fact that the diagram contains unbounded

edges. To handle this we will assume that the entire diagram is to be

stored within a large bounding box. (This box should be chosen large

enough that all of the Voronoi vertices fit within the box.)

The doubly connected edge list (DCEL) is a data structure to repre-

sent an embedding of a planar graph in the plane and polytopes in 3D.

This data structure provides efficient manipulation of the topological

information associated with the objects in question (vertices, edges,

faces). It is used in many algorithms of computational geometry to

handle polygonal subdivisions of the plane, commonly called planar

straigh-line graphs (PSLG).

12

Page 14: Voronoi diagrams - UCLouvain

Doubly connected edge list

Link together three sets of records: vertices, edges and faces.DoublyConnectedEdgeList(DCEL)

•  Mainideas:

–  Edgesareorientedcounterclockwiseinsideeachface

–  Sinceanedgeborderstwofaces,eachedgeisreplacedby

twohalf‐edges,oneforeachface

f1f2

f3

f4

f5

Edges are oriented counterclockwise inside each face. Since an edge

borders two faces, each edge is replaced by two half-edges, one for

each face.

13

Page 15: Voronoi diagrams - UCLouvain

Doubly connected edge listDoublyConnectedEdgeList(DCEL)

•  Thevertexrecordofavertexvstoresthe

coordinatesofv.Italsostoresapointer

IncidentEdge(v)toanarbitraryhalf‐edge

thathasvasitsorigin

•  Thefacerecordofafacefstoresapointer

tosomehalf‐edgeonitsboundarywhich

canbeusedasastartingpointtotraverse

fincounterclockwiseorder

e1e2

e3e4

e5

e6

origin(e1)

previous(e1)

next(e1)

IncidentFace(e1)

e4.twin

e3.twin

•  Thehalf‐edgerecordofahalf‐edgeestorespointerto:

•  Origin(e)

•  Twinofe,e.twinortwin(e)

•  Thefacetoitsleft(IncidentFace(e))

•  Next(e):nexthalf‐edgeontheboundaryofIncidentFace(e)

•  Previous(e):previoushalf‐edge

The vertex stores its coordinates as well as a pointer to one of the

half-edges it is connected to. The face stores a pointer to some of

its half-edges. The half-edges store pointers to its origin vertex, to its

twin, to the face to it is left, to the next and the previous half-edges

on its incident face.

Operations: walk around a face in CCW order, access a face adjacent

to a given one, visit all edges around a vertex.

14

Page 16: Voronoi diagrams - UCLouvain

Sibson interpolation

Provides smooth approximation F to f(x, y) :

F (x, y) =n∑

i=1

wif(xi, yi)

where the wi’s are the weights and f(xi, yi) are the known data at

(xi, yi). The weights, wi, are calculated by finding how much of each

of the surrounding areas is ”stolen” when inserting (x, y) into the

tessellation.

15

Page 17: Voronoi diagrams - UCLouvain

Explicit Computation of Voronoi Diagrams

• For each site pi, compute the common intersection of the half-

planes h(pi,pi), with j 6= i, using an algorithm that is O(NlogN)

time per Voronoi cell (as we will see)

• This leads to an O(N2logN) algorithm to compute the whole

Voronoi diagram.

16

Page 18: Voronoi diagrams - UCLouvain

Intersection of half-planes

A convex polytope is defined as the intersection of N half-planes in Rd.

Let us devise a divide and conquer method for effectively computing

the intersection of N half-planes in 2D.

• If N = 1, then just return this half-plane as the answer.

• Split the N half-planes of P into subsets P1 and P2 of sizes N/2.

• Compute the intersection of P1 and P2, each by calling this pro-

cedure recursively. Let C1 and C2 be the results.

• Intersect the convex polygons C1 and C2 (which might be un-

bounded) into a single convex polygon C, and return C.

17

Page 19: Voronoi diagrams - UCLouvain

Intersection of two convex polygons

Assume that it is possible to compute the intersection of N line seg-

ments in O((N + I) logN) time, where I is the number of intersecting

pairs.

Two convex polygons cannot intersect in more than I = O(N) pairs.

This follows from the observation that each edge of one polygon can

intersect at most two edges of the other polygon by convexity.

This would given O(N logN) algorithm for computing the intersection

and an O(N log2N) solution for the problem of intersection of half-

plane, which is not as good as we would like.

18

Page 20: Voronoi diagrams - UCLouvain

Intersection of two convex polygons

(2) Split the n halfplanes of H into subsets H1 and H2 of sizes bn/2c and dn/2e, respectively.

(3) Compute the intersection of H1 and H2, each by calling this procedure recursively. Let C1 and C2 be theresults.

(4) Intersect the convex polygons C1 and C2 (which might be unbounded) into a single convex polygon C,and return C.

The running time of the resulting algorithm is most easily described using a recurrence, that is, a recursivelydefined equation. If we ignore constant factors, and assume for simplicity that n is a power of 2, then the runningtime can be described as:

T (n) =

Ω1 if n = 1,2T (n/2) + S(n) if n > 1,

where S(n) is the time required to compute the intersection of two convex polygons whose total complexityis n. If we can show that S(n) = O(n), then by standard results in recurrences it will follow that the overallrunning time T (n) is O(n log n). (See CLR, for example.)

Intersecting Two Convex Polygons: The only nontrivial part of the process is implementing an algorithm that in-tersects two convex polygons, C1 and C2, into a single convex polygon. Note that these are somewhat specialconvex polygons because they may be empty or unbounded.

We know that it is possible to compute the intersection of line segments in O((n+ I) log n) time, where I is thenumber of intersecting pairs. Two convex polygons cannot intersect in more than I = O(n) pairs. (This followsfrom the observation that each edge of one polygon can intersect at most two edges of the other polygon byconvexity.) This would given O(n log n) algorithm for computing the intersection and an O(n log2 n) solutionfor T (n), which is not as good as we would like.

There are two common approaches for intersecting convex polygons. Both essentially involve merging the twoboundaries. One works by a plane-sweep approach. The other involves a simultaneous counterclockwise sweeparound the two boundaries. The latter algorithm is described in O’Rourke’s book. We’ll discuss the plane-sweepalgorithm.

We perform a left-to-right plane sweep to compute the intersection. We begin by breaking the boundaries of theconvex polygons into their upper and lower chains. By convexity, the sweep line intersects each convex polygonCi in at most two points, and hence, there are at most four points in the sweep line status at any time. Thus wedo not need a dictionary for storing the sweep line status, a simple 4-element list suffices. Also, our event queueneed only be of constant size. At any point there are at most 8 possible candidates for the next event, namely,the right endpoints of the four edges stabbed by the sweep line and the (up to four) intersection points of theseupper and lower edges of C1 with the upper and lower edges of C2. Since there are only a constant number ofpossible events, and each can be handled in O(1) time, the total running time is O(n).

C2

C1

potential next event

Figure 32: Convex polygon intersection.

Lecture Notes 36 CMSC 754

We perform a left-to-right plane sweep to compute the intersection.

By convexity, the sweep line intersects each convex polygon Ci in at

most two points, and hence, there are at most four points in the sweep

line status at any time.

Thus we do not need a dictionary for storing the sweep line status, a

simple 4-element list suffices.

19

Page 21: Voronoi diagrams - UCLouvain

Intersection of two convex polygons

(2) Split the n halfplanes of H into subsets H1 and H2 of sizes bn/2c and dn/2e, respectively.

(3) Compute the intersection of H1 and H2, each by calling this procedure recursively. Let C1 and C2 be theresults.

(4) Intersect the convex polygons C1 and C2 (which might be unbounded) into a single convex polygon C,and return C.

The running time of the resulting algorithm is most easily described using a recurrence, that is, a recursivelydefined equation. If we ignore constant factors, and assume for simplicity that n is a power of 2, then the runningtime can be described as:

T (n) =

Ω1 if n = 1,2T (n/2) + S(n) if n > 1,

where S(n) is the time required to compute the intersection of two convex polygons whose total complexityis n. If we can show that S(n) = O(n), then by standard results in recurrences it will follow that the overallrunning time T (n) is O(n log n). (See CLR, for example.)

Intersecting Two Convex Polygons: The only nontrivial part of the process is implementing an algorithm that in-tersects two convex polygons, C1 and C2, into a single convex polygon. Note that these are somewhat specialconvex polygons because they may be empty or unbounded.

We know that it is possible to compute the intersection of line segments in O((n+ I) log n) time, where I is thenumber of intersecting pairs. Two convex polygons cannot intersect in more than I = O(n) pairs. (This followsfrom the observation that each edge of one polygon can intersect at most two edges of the other polygon byconvexity.) This would given O(n log n) algorithm for computing the intersection and an O(n log2 n) solutionfor T (n), which is not as good as we would like.

There are two common approaches for intersecting convex polygons. Both essentially involve merging the twoboundaries. One works by a plane-sweep approach. The other involves a simultaneous counterclockwise sweeparound the two boundaries. The latter algorithm is described in O’Rourke’s book. We’ll discuss the plane-sweepalgorithm.

We perform a left-to-right plane sweep to compute the intersection. We begin by breaking the boundaries of theconvex polygons into their upper and lower chains. By convexity, the sweep line intersects each convex polygonCi in at most two points, and hence, there are at most four points in the sweep line status at any time. Thus wedo not need a dictionary for storing the sweep line status, a simple 4-element list suffices. Also, our event queueneed only be of constant size. At any point there are at most 8 possible candidates for the next event, namely,the right endpoints of the four edges stabbed by the sweep line and the (up to four) intersection points of theseupper and lower edges of C1 with the upper and lower edges of C2. Since there are only a constant number ofpossible events, and each can be handled in O(1) time, the total running time is O(n).

C2

C1

potential next event

Figure 32: Convex polygon intersection.

Lecture Notes 36 CMSC 754

Also, our event queue need only be of constant size. At any point

there are at most 8 possible candidates for the next event, namely,

the right endpoints of the four edges stabbed by the sweep line and

the (up to four) intersection points of these upper and lower edges of

C1 with the upper and lower edges of C2.

Since there are only a constant number of possible events, and each

can be handled in O(1) time, the total running time is O(N).

20

Page 22: Voronoi diagrams - UCLouvain

Intersection of line segments

The problem: Given n line segments in the plane, report all points

where a pair of line segments intersect.

Observe that n line segments can intersect in as few as 0 and as many

as(n2

)= O(n2) different intersection points.

We could settle for an O(n2) algorithm, claiming that it is worst-case

asymptotically optimal, but it would not be very useful in practice.

21

Page 23: Voronoi diagrams - UCLouvain

Intersection of line segments

either parallel or collinear. These special cases should be dealt with carefully. If the divisor is nonzero, then weget values for s and t as rational numbers (the ratio of two integers). We can approximate them as floating pointnumbers, or if we want to perform exact computations it is possible to simulate rational number algebra exactlyusing high-precision integers (and multiplying through by least common multiples). Once the values of s and thave been computed all that is needed is to check that both are in the interval [0, 1].

Plane Sweep Algorithm: Let S = s1, s2, . . . , sn denote the line segments whose intersections we wish to com-pute. The method is called plane sweep. Here are the main elements of any plane sweep algorithm, and how wewill apply them to this problem:

Sweep line: We will simulate the sweeping of a vertical line `, called the sweep line from left to right. (Our textuses a horizontal line, but there is obviously no significant difference.) We will maintain the line segmentsthat intersect the sweep line in sorted order (say from top to bottom).

Events: Although we might think of the sweep line as moving continuously, we only need to update datastructures at points of some significant change in the sweep-line contents, called event points.Different applications of plane sweep will have different notions of what event points are. For this appli-cation, event points will correspond to the following:

Endpoint events: where the sweep line encounters an endpoint of a line segment, andIntersection events: where the sweep line encounters an intersection point of two line segments.

Note that endpoint events can be presorted before the sweep runs. In contrast, intersection events will bediscovered as the sweep executes. For example, in the figure below, some of the intersection points lyingto the right of the sweep line have not yet been “discovered” as events. However, we will show that everyintersection point will be discovered as an event before the sweep line arrives here.

Event updates: When an event is encountered, we must update the data structures associated with the event.It is a good idea to be careful in specifying exactly what invariants you intend to maintain. For example,when we encounter an intersection point, we must interchange the order of the intersecting line segmentsalong the sweep line.

intersections detected

future event points

l

Figure 17: Plane sweep.

There are a great number of nasty special cases that complicate the algorithm and obscure the main points. Wewill make a number of simplifying assumptions. They can be overcome through a more careful handling ofthese cases.

(1) No line segment is vertical.

(2) If two segments intersect, then they intersect in a single point (that is, they are not collinear).

(3) No three lines intersect in a common point.

Lecture Notes 22 CMSC 754

Sweep line: We will simulate the sweeping of a vertical line l, called

the sweep line from left to right. We will maintain the line segments

that intersect the sweep line in sorted order (say from top to bottom).

Events: Although we might think of the sweep line as moving con-

tinuously, we only need to update data structures at points of some

significant change in the sweep-line contents, called event points.

22

Page 24: Voronoi diagrams - UCLouvain

Intersection of line segments

either parallel or collinear. These special cases should be dealt with carefully. If the divisor is nonzero, then weget values for s and t as rational numbers (the ratio of two integers). We can approximate them as floating pointnumbers, or if we want to perform exact computations it is possible to simulate rational number algebra exactlyusing high-precision integers (and multiplying through by least common multiples). Once the values of s and thave been computed all that is needed is to check that both are in the interval [0, 1].

Plane Sweep Algorithm: Let S = s1, s2, . . . , sn denote the line segments whose intersections we wish to com-pute. The method is called plane sweep. Here are the main elements of any plane sweep algorithm, and how wewill apply them to this problem:

Sweep line: We will simulate the sweeping of a vertical line `, called the sweep line from left to right. (Our textuses a horizontal line, but there is obviously no significant difference.) We will maintain the line segmentsthat intersect the sweep line in sorted order (say from top to bottom).

Events: Although we might think of the sweep line as moving continuously, we only need to update datastructures at points of some significant change in the sweep-line contents, called event points.Different applications of plane sweep will have different notions of what event points are. For this appli-cation, event points will correspond to the following:

Endpoint events: where the sweep line encounters an endpoint of a line segment, andIntersection events: where the sweep line encounters an intersection point of two line segments.

Note that endpoint events can be presorted before the sweep runs. In contrast, intersection events will bediscovered as the sweep executes. For example, in the figure below, some of the intersection points lyingto the right of the sweep line have not yet been “discovered” as events. However, we will show that everyintersection point will be discovered as an event before the sweep line arrives here.

Event updates: When an event is encountered, we must update the data structures associated with the event.It is a good idea to be careful in specifying exactly what invariants you intend to maintain. For example,when we encounter an intersection point, we must interchange the order of the intersecting line segmentsalong the sweep line.

intersections detected

future event points

l

Figure 17: Plane sweep.

There are a great number of nasty special cases that complicate the algorithm and obscure the main points. Wewill make a number of simplifying assumptions. They can be overcome through a more careful handling ofthese cases.

(1) No line segment is vertical.

(2) If two segments intersect, then they intersect in a single point (that is, they are not collinear).

(3) No three lines intersect in a common point.

Lecture Notes 22 CMSC 754

Different applications of plane sweep will have different notions of what

event points are. For this application, event points will correspond to

the following:

Endpoint events: where the sweep line encounters an endpoint of a

line segment, and

23

Page 25: Voronoi diagrams - UCLouvain

Intersection of line segments

either parallel or collinear. These special cases should be dealt with carefully. If the divisor is nonzero, then weget values for s and t as rational numbers (the ratio of two integers). We can approximate them as floating pointnumbers, or if we want to perform exact computations it is possible to simulate rational number algebra exactlyusing high-precision integers (and multiplying through by least common multiples). Once the values of s and thave been computed all that is needed is to check that both are in the interval [0, 1].

Plane Sweep Algorithm: Let S = s1, s2, . . . , sn denote the line segments whose intersections we wish to com-pute. The method is called plane sweep. Here are the main elements of any plane sweep algorithm, and how wewill apply them to this problem:

Sweep line: We will simulate the sweeping of a vertical line `, called the sweep line from left to right. (Our textuses a horizontal line, but there is obviously no significant difference.) We will maintain the line segmentsthat intersect the sweep line in sorted order (say from top to bottom).

Events: Although we might think of the sweep line as moving continuously, we only need to update datastructures at points of some significant change in the sweep-line contents, called event points.Different applications of plane sweep will have different notions of what event points are. For this appli-cation, event points will correspond to the following:

Endpoint events: where the sweep line encounters an endpoint of a line segment, andIntersection events: where the sweep line encounters an intersection point of two line segments.

Note that endpoint events can be presorted before the sweep runs. In contrast, intersection events will bediscovered as the sweep executes. For example, in the figure below, some of the intersection points lyingto the right of the sweep line have not yet been “discovered” as events. However, we will show that everyintersection point will be discovered as an event before the sweep line arrives here.

Event updates: When an event is encountered, we must update the data structures associated with the event.It is a good idea to be careful in specifying exactly what invariants you intend to maintain. For example,when we encounter an intersection point, we must interchange the order of the intersecting line segmentsalong the sweep line.

intersections detected

future event points

l

Figure 17: Plane sweep.

There are a great number of nasty special cases that complicate the algorithm and obscure the main points. Wewill make a number of simplifying assumptions. They can be overcome through a more careful handling ofthese cases.

(1) No line segment is vertical.

(2) If two segments intersect, then they intersect in a single point (that is, they are not collinear).

(3) No three lines intersect in a common point.

Lecture Notes 22 CMSC 754

Intersection events: where the sweep line encounters an intersectionpoint of two line segments.

Note that endpoint events can be presorted before the sweep runs. Incontrast, intersection events will be discovered as the sweep executes.For example, in the figure, some of the intersection points lying tothe right of the sweep line have not yet been “discovered” as events.However, we will show that every intersection point will be discoveredas an event before the sweep line arrives here.

24

Page 26: Voronoi diagrams - UCLouvain

Intersection of line segments

either parallel or collinear. These special cases should be dealt with carefully. If the divisor is nonzero, then weget values for s and t as rational numbers (the ratio of two integers). We can approximate them as floating pointnumbers, or if we want to perform exact computations it is possible to simulate rational number algebra exactlyusing high-precision integers (and multiplying through by least common multiples). Once the values of s and thave been computed all that is needed is to check that both are in the interval [0, 1].

Plane Sweep Algorithm: Let S = s1, s2, . . . , sn denote the line segments whose intersections we wish to com-pute. The method is called plane sweep. Here are the main elements of any plane sweep algorithm, and how wewill apply them to this problem:

Sweep line: We will simulate the sweeping of a vertical line `, called the sweep line from left to right. (Our textuses a horizontal line, but there is obviously no significant difference.) We will maintain the line segmentsthat intersect the sweep line in sorted order (say from top to bottom).

Events: Although we might think of the sweep line as moving continuously, we only need to update datastructures at points of some significant change in the sweep-line contents, called event points.Different applications of plane sweep will have different notions of what event points are. For this appli-cation, event points will correspond to the following:

Endpoint events: where the sweep line encounters an endpoint of a line segment, andIntersection events: where the sweep line encounters an intersection point of two line segments.

Note that endpoint events can be presorted before the sweep runs. In contrast, intersection events will bediscovered as the sweep executes. For example, in the figure below, some of the intersection points lyingto the right of the sweep line have not yet been “discovered” as events. However, we will show that everyintersection point will be discovered as an event before the sweep line arrives here.

Event updates: When an event is encountered, we must update the data structures associated with the event.It is a good idea to be careful in specifying exactly what invariants you intend to maintain. For example,when we encounter an intersection point, we must interchange the order of the intersecting line segmentsalong the sweep line.

intersections detected

future event points

l

Figure 17: Plane sweep.

There are a great number of nasty special cases that complicate the algorithm and obscure the main points. Wewill make a number of simplifying assumptions. They can be overcome through a more careful handling ofthese cases.

(1) No line segment is vertical.

(2) If two segments intersect, then they intersect in a single point (that is, they are not collinear).

(3) No three lines intersect in a common point.

Lecture Notes 22 CMSC 754

Event updates: When an event is encountered, we must update

the data structures associated with the event. It is a good idea to be

careful in specifying exactly what invariants you intend to maintain.

For example, when we encounter an intersection point, we must in-

terchange the order of the intersecting line segments along the sweep

line.

25

Page 27: Voronoi diagrams - UCLouvain

Intersection of line segments

Detecting intersections: We mentioned that endpoint events are all known in advance. But how do we detect inter-section events. It is important that each event be detected before the actual event occurs. Our strategy will be asfollows. Whenever two line segments become adjacent along the sweep line, we will check whether they havean intersection occuring to the right of the sweep line. If so, we will add this new event (assuming that it has notalready been added).

A natural question is whether this is sufficient. In particular, if two line segments do intersect, is there necessarilysome prior placement of the sweep line such that they are adjacent. Happily, this is the case, but it requires aproof.

Lemma: Given two segments si and sj , which intersect in a single point p (and assuming no other line segmentpasses through this point) there is a placement of the sweep line prior to this event, such that si and sj areadjacent along the sweep line (and hence will be tested for intersection).

Proof: From our general position assumption it follows that no three lines intersect in a common point. There-fore if we consider a placement of the sweep line that is infinitessimally to the left of the intersectionpoint, lines si and sj will be adjacent along this sweepline. Consider the event point q with the largestx-coordinate that is strictly less than px. The order of lines along the sweep-line after processing q will beidentical the order of the lines along the sweep line just prior p, and hence si and sj will be adjacent at thispoint.

l

p

qs

js

i

Figure 18: Correctness of plane sweep.

Data structures: In order to perform the sweep we will need two data structures.

Event queue: This holds the set of future events, sorted according to increasing x-coordinate. Each eventcontains the auxiliary information of what type of event this is (segment endpoint or intersection) andwhich segment(s) are involved. The operations that this data structure should support are inserting anevent (if it is not already present in the queue) and extracting the minimum event.It seems like a heap data structure would be ideal for this, since it supports insertions and extract-min inO(log M) time, where M is the number of entries in the queue. (See Cormen, Leiserson, and Rivest fordetails). However, a heap cannot support the operation of checking for duplicate events.There are two ways to handle this. One is to use a more sophisticated data structure, such as a balancedbinary tree or skip-list. This adds a small constant factor, but can check that there are no duplicates easily.The second is use the heap, but when an extraction is performed, you may have to perform many extractionsto deal with multiple instances of the same event. (Our book recommends the prior solution.)If events have the same x-coordinate, then we can handle this by sorting points lexicographically by (x, y).(This results in events be processed from bottom to top along the sweep line, and has the same geometriceffect as imagining that the sweep line is rotated infinitesimally counterclockwise.)

Sweep line status: To store the sweep line status, we maintain a balanced binary tree or perhaps a skiplist whoseentries are pointers to the line segments, stored in increasing order of y-coordinate along the current sweepline.

Lecture Notes 23 CMSC 754

A natural question is whether this is sufficient. In particular, if twoline segments do intersect, is there necessarily some prior placementof the sweep line such that they are adjacent. Happily, this is the case,but it requires a proof.

Theorem: Given two segments si and sj , which intersect in a singlepoint p (and assuming no other line segment passes through this point)there is a placement of the sweep line prior to this event, such that siand sj are adjacent along the sweep line (and hence will be tested forintersection).

26

Page 28: Voronoi diagrams - UCLouvain

Intersection of line segments

Initialize event queue EQ = all segment endpoints;

Sort EQ by increasing x and y;

Initialize sweep line SL to be empty;

Initialize output intersection list IL to be empty;

While (EQ is nonempty)

Let E = the next event from EQ;

If (E is a left endpoint)

Let segE = E’s segment;

Add segE to SL;

Let segA = the segment Above segE in SL;

Let segB = the segment Below segE in SL;

If (I = Intersect( segE with segA) exists)

Insert I into EQ;

If (I = Intersect( segE with segB) exists)

Insert I into EQ;

27

Page 29: Voronoi diagrams - UCLouvain

Else If (E is a right endpoint)

Let segE = E’s segment;

Let segA = the segment Above segE in SL;

Let segB = the segment Below segE in SL;

Delete segE from SL;

If (I = Intersect( segA with segB) exists)

If (I is not in EQ already)

Insert I into EQ;

Else // E is an intersection event

Add E’s intersect point to the output list IL;

Let segE1 above segE2 be E’s intersecting segments in SL;

Swap their positions so that segE2 is now above segE1;

Let segA = the segment above segE2 in SL;

Let segB = the segment below segE1 in SL;

If (I = Intersect(segE2 with segA) exists)

If (I is not in EQ already)

Insert I into EQ;

If (I = Intersect(segE1 with segB) exists)

27

Page 30: Voronoi diagrams - UCLouvain

If (I is not in EQ already)

Insert I into EQ;

remove E from EQ;

return IL;

27

Page 31: Voronoi diagrams - UCLouvain

Fortune’s Algorithm

Plane sweep line strategy: a sweep horizontal line going from top to

bottom.

Some information is maintained about the intersection of the structure

with the sweep line.

While the sweep line l moves downwards the information does not

change, except at certain special points: the event points.

Application to compute Voronoi diagrams : Fortune’s algorithm.

28

Page 32: Voronoi diagrams - UCLouvain

Fortune’s Algorithm

Fortune’s Algorithm: Before discussing Fortune’s algorithm, it is interesting to consider why this algorithm was notinvented much earlier. In fact, it is quite a bit trickier than any plane sweep algorithm we have seen so far. Thekey to any plane sweep algorithm is the ability to discover all “upcoming” events in an efficient manner. Forexample, in the line segment intersection algorithm we considered all pairs of line segments that were adjacentin the sweep-line status, and inserted their intersection point in the queue of upcoming events. The problemwith the Voronoi diagram is that of predicting when and where the upcoming events will occur. Imagine thatyou are designing a plane sweep algorithm. Behind the sweep line you have constructed the Voronoi diagrambased on the points that have been encountered so far in the sweep. The difficulty is that a site that lies ahead ofthe sweep line may generate a Voronoi vertex that lies behind the sweep line. How could the sweep algorithmknow of the existence of this vertex until it sees the site. But by the time it sees the site, it is too late. It is theseunanticipated events that make the design of a plane sweep algorithm challenging. (See the figure below.)

unanticipatedevents

sweep line

Figure 60: Plane sweep for Voronoi diagrams. Note that the position of the indicated vertices depends on sites thathave not yet been encountered by the sweep line, and hence are unknown to the algorithm. (Note that the sweep linemoves from top to bottom.)

Fortune made the clever observation of rather than computing the Voronoi diagram through plane sweep in itsfinal form, instead to compute a “distorted” but topologically equivalent version of the diagram. This distortedversion of the diagram was based on a transformation that alters the way that distances are measured in theplane. The resulting diagram had the same topological structure as the Voronoi diagram, but its edges wereparabolic arcs, rather than straight line segments. Once this distorted diagram was generated, it was an easymatter to “undistort” it to produce the correct Voronoi diagram.Our presentation will be different from Fortune’s. Rather than distort the diagram, we can think of this algorithmas distorting the sweep line. Actually, we will think of two objects that control the sweeping process. First, therewill be a horizontal sweep line, moving from top to bottom. We will also maintain an x-monotonic curve called abeach line. (It is so named because it looks like waves rolling up on a beach.) The beach line is a monotone curveformed from pieces of parabolic arcs. As the sweep line moves downward, the beach line follows just behind.The job of the beach line is to prevent us from seeing unanticipated events until the sweep line encounters thecorresponding site.

The Beach Line: In order to make these ideas more concrete, recall that the problem with ordinary plane sweep isthat sites that lie below the sweep line may affect the diagram that lies above the sweep line. To avoid thisproblem, we will maintain only the portion of the diagram that cannot be affected by anything that lies belowthe sweep line. To do this, we will subdivide the halfplane lying above the sweep line into two regions: thosepoints that are closer to some site p above the sweep line than they are to the sweep line itself, and those pointsthat are closer to the sweep line than any site above the sweep line.What are the geometric properties of the boundary between these two regions? The set of points q that areequidistant from the sweep line to their nearest site above the sweep line is called the beach line. Observe thatfor any point q above the beach line, we know that its closest site cannot be affected by any site that lies below

Lecture Notes 70 CMSC 754

Difficulty: the part of Vor(P ) above l depends not only on the sites

that lie above l but also on sites below l.

Slight change of strategy: instead of maintaining the intersection of

the Voronoi diagram with the sweep line, we maintain information

about the part of the Voronoi diagram of the sites above l that cannot

be changed by sites below l.

29

Page 33: Voronoi diagrams - UCLouvain

Fortune’s Algorithm

Fortune’s Algorithm: Before discussing Fortune’s algorithm, it is interesting to consider why this algorithm was notinvented much earlier. In fact, it is quite a bit trickier than any plane sweep algorithm we have seen so far. Thekey to any plane sweep algorithm is the ability to discover all “upcoming” events in an efficient manner. Forexample, in the line segment intersection algorithm we considered all pairs of line segments that were adjacentin the sweep-line status, and inserted their intersection point in the queue of upcoming events. The problemwith the Voronoi diagram is that of predicting when and where the upcoming events will occur. Imagine thatyou are designing a plane sweep algorithm. Behind the sweep line you have constructed the Voronoi diagrambased on the points that have been encountered so far in the sweep. The difficulty is that a site that lies ahead ofthe sweep line may generate a Voronoi vertex that lies behind the sweep line. How could the sweep algorithmknow of the existence of this vertex until it sees the site. But by the time it sees the site, it is too late. It is theseunanticipated events that make the design of a plane sweep algorithm challenging. (See the figure below.)

unanticipatedevents

sweep line

Figure 60: Plane sweep for Voronoi diagrams. Note that the position of the indicated vertices depends on sites thathave not yet been encountered by the sweep line, and hence are unknown to the algorithm. (Note that the sweep linemoves from top to bottom.)

Fortune made the clever observation of rather than computing the Voronoi diagram through plane sweep in itsfinal form, instead to compute a “distorted” but topologically equivalent version of the diagram. This distortedversion of the diagram was based on a transformation that alters the way that distances are measured in theplane. The resulting diagram had the same topological structure as the Voronoi diagram, but its edges wereparabolic arcs, rather than straight line segments. Once this distorted diagram was generated, it was an easymatter to “undistort” it to produce the correct Voronoi diagram.Our presentation will be different from Fortune’s. Rather than distort the diagram, we can think of this algorithmas distorting the sweep line. Actually, we will think of two objects that control the sweeping process. First, therewill be a horizontal sweep line, moving from top to bottom. We will also maintain an x-monotonic curve called abeach line. (It is so named because it looks like waves rolling up on a beach.) The beach line is a monotone curveformed from pieces of parabolic arcs. As the sweep line moves downward, the beach line follows just behind.The job of the beach line is to prevent us from seeing unanticipated events until the sweep line encounters thecorresponding site.

The Beach Line: In order to make these ideas more concrete, recall that the problem with ordinary plane sweep isthat sites that lie below the sweep line may affect the diagram that lies above the sweep line. To avoid thisproblem, we will maintain only the portion of the diagram that cannot be affected by anything that lies belowthe sweep line. To do this, we will subdivide the halfplane lying above the sweep line into two regions: thosepoints that are closer to some site p above the sweep line than they are to the sweep line itself, and those pointsthat are closer to the sweep line than any site above the sweep line.What are the geometric properties of the boundary between these two regions? The set of points q that areequidistant from the sweep line to their nearest site above the sweep line is called the beach line. Observe thatfor any point q above the beach line, we know that its closest site cannot be affected by any site that lies below

Lecture Notes 70 CMSC 754

Denote the closed half-plane above l by l+. What is the part of the

Voronoi diagram above l that cannot be changed anymore? In other

words, for which points q ∈ l+ do we know for sure what their nearest

site is? The distance of a point q ∈ l+ to any site below l is greater

than the distance of q to l itself. Hence, the nearest site of q cannot

lie below l if q is at least as near to some site pi ∈ l+ as q is to l.

30

Page 34: Voronoi diagrams - UCLouvain

Fortune’s Algorithm

Chapter 7VORONOI DIAGRAMS

sweep paradigm we move a horizontal sweep line ! from top to bottom overthe plane. The paradigm involves maintaining the intersection of the Voronoidiagram with the sweep line. Unfortunately this is not so easy, because the partof Vor(P) above ! depends not only on the sites that lie above ! but also on sitesbelow !. Stated differently, when the sweep line reaches the topmost vertexof the Voronoi cell V(pi) it has not yet encountered the corresponding site pi.Hence, we do not have all the information needed to compute the vertex. We areforced to apply the plane sweep paradigm in a slightly different fashion: insteadof maintaining the intersection of the Voronoi diagram with the sweep line, wemaintain information about the part of the Voronoi diagram of the sites above !that cannot be changed by sites below !.

Denote the closed half-plane above ! by !+. What is the part of the Voronoidiagram above ! that cannot be changed anymore? In other words, for whichpoints q ∈ !+ do we know for sure what their nearest site is? The distance of

!

a point q ∈ !+ to any site below ! is greater than the distance of q to ! itself.Hence, the nearest site of q cannot lie below ! if q is at least as near to some sitepi ∈ !+ as q is to !. The locus of points that are closer to some site pi ∈ !+ thanto ! is bounded by a parabola. Hence, the locus of points that are closer to anysite above ! than to ! itself is bounded by parabolic arcs. We call this sequence

!

of parabolic arcs the beach line. Another way to visualize the beach line is thefollowing. Every site pi above the sweep line defines a complete parabola βi.The beach line is the function that—for each x-coordinate—passes through thelowest point of all parabolas.

Observation 7.5 The beach line is x-monotone, that is, every vertical lineintersects it in exactly one point.

It is easy to see that one parabola can contribute more than once to the beachline. We’ll worry later about how many pieces there can be. Notice that thebreakpoints between the different parabolic arcs forming the beach line lie onedges of the Voronoi diagram. This is not a coincidence: the breakpoints exactlytrace out the Voronoi diagram while the sweep line moves from top to bottom.These properties of the beach line can be proved using elementary geometricarguments.

So, instead of maintaining the intersection of Vor(P) with ! we maintainthe beach line as we move our sweep line !. We do not maintain the beach lineexplicitly, since it changes continuously as ! moves. For the moment let’s ignorethe issue of how to represent the beach line until we understand where and howits combinatorial structure changes. This happens when a new parabolic arcappears on it, and when a parabolic arc shrinks to a point and disappears.

First we consider the events where a new arc appears on the beach line. Oneoccasion where this happens is when the sweep line ! reaches a new site. Theparabola defined by this site is at first a degenerate parabola with zero width: avertical line segment connecting the new site to the beach line. As the sweepline continues to move downward the new parabola gets wider and wider. Thepart of the new parabola below the old beach line is now a part of the new beach152

The locus of points that are closer to some site pi ∈ l+ than to l is

bounded by a parabola. Hence, the locus of points that are closer to

any site above l than to l itself is bounded by parabolic arcs. We call

this sequence of parabolic arcs the beach line.

31

Page 35: Voronoi diagrams - UCLouvain

Fortune’s Algorithm

Chapter 7VORONOI DIAGRAMS

sweep paradigm we move a horizontal sweep line ! from top to bottom overthe plane. The paradigm involves maintaining the intersection of the Voronoidiagram with the sweep line. Unfortunately this is not so easy, because the partof Vor(P) above ! depends not only on the sites that lie above ! but also on sitesbelow !. Stated differently, when the sweep line reaches the topmost vertexof the Voronoi cell V(pi) it has not yet encountered the corresponding site pi.Hence, we do not have all the information needed to compute the vertex. We areforced to apply the plane sweep paradigm in a slightly different fashion: insteadof maintaining the intersection of the Voronoi diagram with the sweep line, wemaintain information about the part of the Voronoi diagram of the sites above !that cannot be changed by sites below !.

Denote the closed half-plane above ! by !+. What is the part of the Voronoidiagram above ! that cannot be changed anymore? In other words, for whichpoints q ∈ !+ do we know for sure what their nearest site is? The distance of

!

a point q ∈ !+ to any site below ! is greater than the distance of q to ! itself.Hence, the nearest site of q cannot lie below ! if q is at least as near to some sitepi ∈ !+ as q is to !. The locus of points that are closer to some site pi ∈ !+ thanto ! is bounded by a parabola. Hence, the locus of points that are closer to anysite above ! than to ! itself is bounded by parabolic arcs. We call this sequence

!

of parabolic arcs the beach line. Another way to visualize the beach line is thefollowing. Every site pi above the sweep line defines a complete parabola βi.The beach line is the function that—for each x-coordinate—passes through thelowest point of all parabolas.

Observation 7.5 The beach line is x-monotone, that is, every vertical lineintersects it in exactly one point.

It is easy to see that one parabola can contribute more than once to the beachline. We’ll worry later about how many pieces there can be. Notice that thebreakpoints between the different parabolic arcs forming the beach line lie onedges of the Voronoi diagram. This is not a coincidence: the breakpoints exactlytrace out the Voronoi diagram while the sweep line moves from top to bottom.These properties of the beach line can be proved using elementary geometricarguments.

So, instead of maintaining the intersection of Vor(P) with ! we maintainthe beach line as we move our sweep line !. We do not maintain the beach lineexplicitly, since it changes continuously as ! moves. For the moment let’s ignorethe issue of how to represent the beach line until we understand where and howits combinatorial structure changes. This happens when a new parabolic arcappears on it, and when a parabolic arc shrinks to a point and disappears.

First we consider the events where a new arc appears on the beach line. Oneoccasion where this happens is when the sweep line ! reaches a new site. Theparabola defined by this site is at first a degenerate parabola with zero width: avertical line segment connecting the new site to the beach line. As the sweepline continues to move downward the new parabola gets wider and wider. Thepart of the new parabola below the old beach line is now a part of the new beach152

One parabola can contribute more than once to the beach line. We’llworry later about how many pieces there can be.

The breakpoints between the different parabolic arcs forming thebeach line lie on edges of the Voronoi diagram. This is not a coinci-dence: the breakpoints exactly trace out the Voronoi diagram whilethe sweep line moves from top to bottom. These properties of thebeach line can be proved using elementary geometric arguments.

32

Page 36: Voronoi diagrams - UCLouvain

Fortune’s Algorithm

Chapter 7VORONOI DIAGRAMS

sweep paradigm we move a horizontal sweep line ! from top to bottom overthe plane. The paradigm involves maintaining the intersection of the Voronoidiagram with the sweep line. Unfortunately this is not so easy, because the partof Vor(P) above ! depends not only on the sites that lie above ! but also on sitesbelow !. Stated differently, when the sweep line reaches the topmost vertexof the Voronoi cell V(pi) it has not yet encountered the corresponding site pi.Hence, we do not have all the information needed to compute the vertex. We areforced to apply the plane sweep paradigm in a slightly different fashion: insteadof maintaining the intersection of the Voronoi diagram with the sweep line, wemaintain information about the part of the Voronoi diagram of the sites above !that cannot be changed by sites below !.

Denote the closed half-plane above ! by !+. What is the part of the Voronoidiagram above ! that cannot be changed anymore? In other words, for whichpoints q ∈ !+ do we know for sure what their nearest site is? The distance of

!

a point q ∈ !+ to any site below ! is greater than the distance of q to ! itself.Hence, the nearest site of q cannot lie below ! if q is at least as near to some sitepi ∈ !+ as q is to !. The locus of points that are closer to some site pi ∈ !+ thanto ! is bounded by a parabola. Hence, the locus of points that are closer to anysite above ! than to ! itself is bounded by parabolic arcs. We call this sequence

!

of parabolic arcs the beach line. Another way to visualize the beach line is thefollowing. Every site pi above the sweep line defines a complete parabola βi.The beach line is the function that—for each x-coordinate—passes through thelowest point of all parabolas.

Observation 7.5 The beach line is x-monotone, that is, every vertical lineintersects it in exactly one point.

It is easy to see that one parabola can contribute more than once to the beachline. We’ll worry later about how many pieces there can be. Notice that thebreakpoints between the different parabolic arcs forming the beach line lie onedges of the Voronoi diagram. This is not a coincidence: the breakpoints exactlytrace out the Voronoi diagram while the sweep line moves from top to bottom.These properties of the beach line can be proved using elementary geometricarguments.

So, instead of maintaining the intersection of Vor(P) with ! we maintainthe beach line as we move our sweep line !. We do not maintain the beach lineexplicitly, since it changes continuously as ! moves. For the moment let’s ignorethe issue of how to represent the beach line until we understand where and howits combinatorial structure changes. This happens when a new parabolic arcappears on it, and when a parabolic arc shrinks to a point and disappears.

First we consider the events where a new arc appears on the beach line. Oneoccasion where this happens is when the sweep line ! reaches a new site. Theparabola defined by this site is at first a degenerate parabola with zero width: avertical line segment connecting the new site to the beach line. As the sweepline continues to move downward the new parabola gets wider and wider. Thepart of the new parabola below the old beach line is now a part of the new beach152

Instead of maintaining the intersection of Vor(P ) with l we maintainthe beach line as we move our sweep line l.

We do not maintain the beach line explicitly, since it changes con-tinuously as l moves. For the moment let’s ignore the issue of howto represent the beach line until we understand where and how itscombinatorial structure changes. This happens when a new parabolicarc appears on it, and when a parabolic arc shrinks to a point anddisappears.

33

Page 37: Voronoi diagrams - UCLouvain

Fortune’s Algorithm

Section 7.2COMPUTING THE VORONOI DIAGRAM

line. Figure 7.2 illustrates this process. We call the event where a new site isencountered a site event.

! ! !Figure 7.2A new arc appears on the beach linebecause a site is encountered

What happens to the Voronoi diagram at a site event? Recall that thebreakpoints on the beach line trace out the edges of the Voronoi diagram. At asite event two new breakpoints appear, which start tracing out edges. In fact,

!

the new breakpoints coincide at first, and then move in opposite directions totrace out the same edge. Initially, this edge is not connected to the rest of theVoronoi diagram above the sweep line. Later on—we will see shortly exactlywhen this will happen—the growing edge will run into another edge, and itbecomes connected to the rest of the diagram.

So now we understand what happens at a site event: a new arc appears onthe beach line, and a new edge of the Voronoi diagram starts to be traced out.Is it possible that a new arc appears on the beach line in any other way? Theanswer is no:

Lemma 7.6 The only way in which a new arc can appear on the beach line isthrough a site event.

Proof. Suppose for a contradiction that an already existing parabola β j definedby a site p j breaks through the beach line. There are two ways in which thiscould happen.

The first possibility is that β j breaks through in the middle of an arc of aparabola βi. The moment this is about to happen, βi and β j are tangent, that is,

!

β j

they have exactly one point of intersection. Let !y denote the y-coordinate of thesweep line at the moment of tangency. If p j := (p j,x, p j,y), then the parabola β jis given by

β j := y =1

2(p j,y − !y)

(x2 −2p j,xx+ p2

j,x + p2j,y − !2

y).

The formula for βi is similar, of course. Using that both p j,y and pi,y are largerthan !y, it is easy to show that it is impossible that βi and β j have only one pointof intersection. Hence, a parabola β j never breaks through in the middle of anarc of another parabola βi.

!

β j

The second possibility is that β j appears in between two arcs. Let thesearcs be part of parabolas βi and βk. Let q be the intersection point of βi andβk at which β j is about to appear on the beach line, and assume that βi is onthe beach line left of q and βk is on the beach line right of q, as in Figure 7.3.Then there is a circle C that passes through pi, p j, and pk, the sites definingthe parabolas. This circle is also tangent to the sweep line !. The cyclic order 153

First we consider the events where a new arc appears on the beach

line. One occasion where this happens is when the sweep line l reaches

a new site. The parabola defined by this site is at first a degenerate

parabola with zero width: a vertical line segment connecting the new

site to the beach line. As the sweep line continues to move downward

the new parabola gets wider and wider. The part of the new parabola

below the old beach line is now a part of the new beach line. We call

the event where a new site is encountered a site event.

34

Page 38: Voronoi diagrams - UCLouvain

What happens to Vor(P ) at a site event?

Section 7.2COMPUTING THE VORONOI DIAGRAM

line. Figure 7.2 illustrates this process. We call the event where a new site isencountered a site event.

! ! !Figure 7.2A new arc appears on the beach linebecause a site is encountered

What happens to the Voronoi diagram at a site event? Recall that thebreakpoints on the beach line trace out the edges of the Voronoi diagram. At asite event two new breakpoints appear, which start tracing out edges. In fact,

!

the new breakpoints coincide at first, and then move in opposite directions totrace out the same edge. Initially, this edge is not connected to the rest of theVoronoi diagram above the sweep line. Later on—we will see shortly exactlywhen this will happen—the growing edge will run into another edge, and itbecomes connected to the rest of the diagram.

So now we understand what happens at a site event: a new arc appears onthe beach line, and a new edge of the Voronoi diagram starts to be traced out.Is it possible that a new arc appears on the beach line in any other way? Theanswer is no:

Lemma 7.6 The only way in which a new arc can appear on the beach line isthrough a site event.

Proof. Suppose for a contradiction that an already existing parabola β j definedby a site p j breaks through the beach line. There are two ways in which thiscould happen.

The first possibility is that β j breaks through in the middle of an arc of aparabola βi. The moment this is about to happen, βi and β j are tangent, that is,

!

β j

they have exactly one point of intersection. Let !y denote the y-coordinate of thesweep line at the moment of tangency. If p j := (p j,x, p j,y), then the parabola β jis given by

β j := y =1

2(p j,y − !y)

(x2 −2p j,xx+ p2

j,x + p2j,y − !2

y).

The formula for βi is similar, of course. Using that both p j,y and pi,y are largerthan !y, it is easy to show that it is impossible that βi and β j have only one pointof intersection. Hence, a parabola β j never breaks through in the middle of anarc of another parabola βi.

!

β j

The second possibility is that β j appears in between two arcs. Let thesearcs be part of parabolas βi and βk. Let q be the intersection point of βi andβk at which β j is about to appear on the beach line, and assume that βi is onthe beach line left of q and βk is on the beach line right of q, as in Figure 7.3.Then there is a circle C that passes through pi, p j, and pk, the sites definingthe parabolas. This circle is also tangent to the sweep line !. The cyclic order 153

Breakpoints on the beach line trace out the edges of the Voronoi

diagram. At a site event two new breakpoints appear, which start

tracing out edges. In fact, the new breakpoints coincide at first, and

then move in opposite directions to trace out the same edge. Initially,

this edge is not connected to the rest of the Voronoi diagram above

the sweep line. Later on,the growing edge will run into another edge,

and it becomes connected to the rest of the diagram.

35

Page 39: Voronoi diagrams - UCLouvain

What happens to Vor(P ) at a site event?

Section 7.2COMPUTING THE VORONOI DIAGRAM

line. Figure 7.2 illustrates this process. We call the event where a new site isencountered a site event.

! ! !Figure 7.2A new arc appears on the beach linebecause a site is encountered

What happens to the Voronoi diagram at a site event? Recall that thebreakpoints on the beach line trace out the edges of the Voronoi diagram. At asite event two new breakpoints appear, which start tracing out edges. In fact,

!

the new breakpoints coincide at first, and then move in opposite directions totrace out the same edge. Initially, this edge is not connected to the rest of theVoronoi diagram above the sweep line. Later on—we will see shortly exactlywhen this will happen—the growing edge will run into another edge, and itbecomes connected to the rest of the diagram.

So now we understand what happens at a site event: a new arc appears onthe beach line, and a new edge of the Voronoi diagram starts to be traced out.Is it possible that a new arc appears on the beach line in any other way? Theanswer is no:

Lemma 7.6 The only way in which a new arc can appear on the beach line isthrough a site event.

Proof. Suppose for a contradiction that an already existing parabola β j definedby a site p j breaks through the beach line. There are two ways in which thiscould happen.

The first possibility is that β j breaks through in the middle of an arc of aparabola βi. The moment this is about to happen, βi and β j are tangent, that is,

!

β j

they have exactly one point of intersection. Let !y denote the y-coordinate of thesweep line at the moment of tangency. If p j := (p j,x, p j,y), then the parabola β jis given by

β j := y =1

2(p j,y − !y)

(x2 −2p j,xx+ p2

j,x + p2j,y − !2

y).

The formula for βi is similar, of course. Using that both p j,y and pi,y are largerthan !y, it is easy to show that it is impossible that βi and β j have only one pointof intersection. Hence, a parabola β j never breaks through in the middle of anarc of another parabola βi.

!

β j

The second possibility is that β j appears in between two arcs. Let thesearcs be part of parabolas βi and βk. Let q be the intersection point of βi andβk at which β j is about to appear on the beach line, and assume that βi is onthe beach line left of q and βk is on the beach line right of q, as in Figure 7.3.Then there is a circle C that passes through pi, p j, and pk, the sites definingthe parabolas. This circle is also tangent to the sweep line !. The cyclic order 153

Section 7.2COMPUTING THE VORONOI DIAGRAM

line. Figure 7.2 illustrates this process. We call the event where a new site isencountered a site event.

! ! !Figure 7.2A new arc appears on the beach linebecause a site is encountered

What happens to the Voronoi diagram at a site event? Recall that thebreakpoints on the beach line trace out the edges of the Voronoi diagram. At asite event two new breakpoints appear, which start tracing out edges. In fact,

!

the new breakpoints coincide at first, and then move in opposite directions totrace out the same edge. Initially, this edge is not connected to the rest of theVoronoi diagram above the sweep line. Later on—we will see shortly exactlywhen this will happen—the growing edge will run into another edge, and itbecomes connected to the rest of the diagram.

So now we understand what happens at a site event: a new arc appears onthe beach line, and a new edge of the Voronoi diagram starts to be traced out.Is it possible that a new arc appears on the beach line in any other way? Theanswer is no:

Lemma 7.6 The only way in which a new arc can appear on the beach line isthrough a site event.

Proof. Suppose for a contradiction that an already existing parabola β j definedby a site p j breaks through the beach line. There are two ways in which thiscould happen.

The first possibility is that β j breaks through in the middle of an arc of aparabola βi. The moment this is about to happen, βi and β j are tangent, that is,

!

β j

they have exactly one point of intersection. Let !y denote the y-coordinate of thesweep line at the moment of tangency. If p j := (p j,x, p j,y), then the parabola β jis given by

β j := y =1

2(p j,y − !y)

(x2 −2p j,xx+ p2

j,x + p2j,y − !2

y).

The formula for βi is similar, of course. Using that both p j,y and pi,y are largerthan !y, it is easy to show that it is impossible that βi and β j have only one pointof intersection. Hence, a parabola β j never breaks through in the middle of anarc of another parabola βi.

!

β j

The second possibility is that β j appears in between two arcs. Let thesearcs be part of parabolas βi and βk. Let q be the intersection point of βi andβk at which β j is about to appear on the beach line, and assume that βi is onthe beach line left of q and βk is on the beach line right of q, as in Figure 7.3.Then there is a circle C that passes through pi, p j, and pk, the sites definingthe parabolas. This circle is also tangent to the sweep line !. The cyclic order 153So now we understand what happens at a site event: a new arc appearson the beach line, and a new edge of the Voronoi diagram starts tobe traced out.

Is it possible that a new arc appears on the beach line in any otherway? The answer is no.

Theorem : The only way in which a new arc can appear on the beachline is through a site event.

Demonstration is skipped. An immediate consequence of the lemmais that the beach line consists of at most 2N − 1 parabolic arcs: eachsite encountered gives rise to one new arc and the splitting of at mostone existing arc into two, and there is no other way an arc can appearon the beach line.

36

Page 40: Voronoi diagrams - UCLouvain

Fortune’s algorithm

Chapter 7VORONOI DIAGRAMS

on C, starting at the point of tangency with ! and going clockwise, is pi, p j, pk,because β j is assumed to appear in between the arcs of βi and βk. Consider aninfinitesimal motion of the sweep line downward while keeping the circle Ctangent to !; see Figure 7.3. Then C cannot have empty interior and still pass

Figure 7.3The situation when β j would appear onthe beach line, and the circle when the

sweep line has proceeded

p j

pi

pk

q

βkβi

β j

!

C

p j

pipk

q

C

!

through p j: either pi or pk will penetrate the interior. Therefore, in a sufficientlysmall neighborhood of q the parabola β j cannot appear on the beach line whenthe sweep line moves downward, because either pi or pk will be closer to !than p j.

An immediate consequence of the lemma is that the beach line consists ofat most 2n−1 parabolic arcs: each site encountered gives rise to one new arcand the splitting of at most one existing arc into two, and there is no other wayan arc can appear on the beach line.

Figure 7.4An arc disappears from the beach line

!

q

pi

p j

pk

!

α ′α α ′′

p j

pkpi

!

p j

pkpi

q

The second type of event in the plane sweep algorithm is where an existing arcof the beach line shrinks to a point and disappears, as in Figure 7.4. Let α ′

be the disappearing arc, and let α and α ′′ be the two neighboring arcs of α ′

before it disappears. The arcs α and α ′′ cannot be part of the same parabola;this possibility can be excluded in the same way as the first possibility in theproof of Lemma 7.6 was excluded. Hence, the three arcs α , α ′, and α ′′ aredefined by three distinct sites pi, p j, and pk. At the moment α ′ disappears, theparabolas defined by these three sites pass through a common point q. Pointq is equidistant from ! and each of the three sites. Hence, there is a circlepassing through pi, p j, and pk with q as its center and whose lowest point lies154

The second type of event in the plane sweep algorithm is where an

existing arc of the beach line shrinks to a point and disappears.

The arcs α and α′′ cannot be part of the same parabola. Hence, the

three arcs α, α′, and α′′ are defined by three distinct sites pi, pj , and

pk. At the moment α′ disappears, the parabolas defined by these three

sites pass through a common point q. Point q is equidistant from l

and each of the three sites.

37

Page 41: Voronoi diagrams - UCLouvain

Fortune’s algorithmChapter 7

VORONOI DIAGRAMS

on C, starting at the point of tangency with ! and going clockwise, is pi, p j, pk,because β j is assumed to appear in between the arcs of βi and βk. Consider aninfinitesimal motion of the sweep line downward while keeping the circle Ctangent to !; see Figure 7.3. Then C cannot have empty interior and still pass

Figure 7.3The situation when β j would appear onthe beach line, and the circle when the

sweep line has proceeded

p j

pi

pk

q

βkβi

β j

!

C

p j

pipk

q

C

!

through p j: either pi or pk will penetrate the interior. Therefore, in a sufficientlysmall neighborhood of q the parabola β j cannot appear on the beach line whenthe sweep line moves downward, because either pi or pk will be closer to !than p j.

An immediate consequence of the lemma is that the beach line consists ofat most 2n−1 parabolic arcs: each site encountered gives rise to one new arcand the splitting of at most one existing arc into two, and there is no other wayan arc can appear on the beach line.

Figure 7.4An arc disappears from the beach line

!

q

pi

p j

pk

!

α ′α α ′′

p j

pkpi

!

p j

pkpi

q

The second type of event in the plane sweep algorithm is where an existing arcof the beach line shrinks to a point and disappears, as in Figure 7.4. Let α ′

be the disappearing arc, and let α and α ′′ be the two neighboring arcs of α ′

before it disappears. The arcs α and α ′′ cannot be part of the same parabola;this possibility can be excluded in the same way as the first possibility in theproof of Lemma 7.6 was excluded. Hence, the three arcs α , α ′, and α ′′ aredefined by three distinct sites pi, p j, and pk. At the moment α ′ disappears, theparabolas defined by these three sites pass through a common point q. Pointq is equidistant from ! and each of the three sites. Hence, there is a circlepassing through pi, p j, and pk with q as its center and whose lowest point lies154

When an arc disappears from the beach line and two breakpoints meet,

two edges of the Voronoi diagram meet as well. We call the event

where the sweep line reaches the lowest point of a circle through three

sites defining consecutive arcs on the beach line a circle event.

Theorem : The only way in which an existing arc can disappear

from the beach line is through a circle event.

38

Page 42: Voronoi diagrams - UCLouvain

Combinatorial structure of the beach line

We know where and how the combinatorial structure of the beach line

changes: at a site event a new arc appears, and at a circle event an

existing arc drops out.

We also know how this relates to the Voronoi diagram under construc-

tion: at a site event a new edge starts to grow, and at a circle event

two growing edges meet to form a vertex.

It remains to find the right data structures to maintain the necessary

information during the sweep. Our goal is to compute the Voronoi

diagram, so we need a data structure that stores the part of the

Voronoi diagram computed thus far. We also need the two standard

data structures for any sweep line algorithm: an event queue and a

structure that represents the status of the sweep line.

39

Page 43: Voronoi diagrams - UCLouvain

Sweep-line algorithm

Beach line: The beach line is represented using a dictionary e.g. a

balanced binary tree T . It is the status structure. Its leaves correspond

to the arcs of the beach line, which is x-monotone. Each leaf µ stores

the site that defines the arc it represents. The internal nodes of Trepresent the breakpoints of the beach line.

Notice that a site may appear multiple times on the beach line

40

Page 44: Voronoi diagrams - UCLouvain

Fortune’s algorithm

41

Page 45: Voronoi diagrams - UCLouvain

Algorithm

1.  Initialize •  Event queue Q " all site events •  Binary search tree T " ∅ •  Doubly linked list D " ∅

2.  While Q not ∅, •  Remove event (e) from Q with largest y-

coordinate •  HandleEvent(e, T, D)

41

Page 46: Voronoi diagrams - UCLouvain

Handling Site Events

1.  Locate the existing arc (if any) that is above the new site

2.  Break the arc by replacing the leaf node with a sub tree representing the new arc and its break points

3.  Add two half-edge records in the doubly linked list

4.  Check for potential circle event(s), add them to event queue if they exist

41

Page 47: Voronoi diagrams - UCLouvain

Locate the existing arc that is above the new site

pi pj pk pl

< pj, pk>

< pi, pj> < pk, pl>

•  The x coordinate of the new site is used for the binary search •  The x coordinate of each breakpoint along the root to leaf path is computed on the fly

pi pj

pk pl

l pm

41

Page 48: Voronoi diagrams - UCLouvain

Break the Arc

pi pj pk

< pj, pk>

< pi, pj> < pk, pl>

Corresponding leaf replaced by a new sub-tree

pi pj

pk pl

l pm

pm pl

< pl, pm>

< pm, pl>

pl Different arcs can be identified by the same site!

41

Page 49: Voronoi diagrams - UCLouvain

Add a new edge record in the doubly linked list

pi pj pk

< pj, pk>

< pi, pj> < pk, pl>

pm pl

< pl, pm>

< pm, pl>

pl

pi pj

pk pl

l pm

New Half Edge Record Endpoints " ∅

Pointers to two half-edge records

l pm

41

Page 50: Voronoi diagrams - UCLouvain

Checking for Potential Circle Events •  Scan for triple of consecutive arcs and

determine if breakpoints converge – Triples with new arc in the middle do not have

break points that converge

41

Page 51: Voronoi diagrams - UCLouvain

Checking for Potential Circle Events •  Scan for triple of consecutive arcs and

determine if breakpoints converge – Triples with new arc in the middle do not have

break points that converge

41

Page 52: Voronoi diagrams - UCLouvain

Checking for Potential Circle Events •  Scan for triple of consecutive arcs and

determine if breakpoints converge – Triples with new arc in the middle do not have

break points that converge

41

Page 53: Voronoi diagrams - UCLouvain

Converging break points may not always yield a circle event

•  Appearance of a new site before the circle event makes the potential circle non-empty

l

(The original circle event becomes a false alarm)

41

Page 54: Voronoi diagrams - UCLouvain

Handling Site Events

1.  Locate the leaf representing the existing arc that is above the new site

–  Delete the potential circle event in the event queue 2.  Break the arc by replacing the leaf node with a

sub tree representing the new arc and break points 3.  Add a new edge record in the doubly linked list 4.  Check for potential circle event(s), add them to

queue if they exist –  Store in the corresponding leaf of T a pointer to the

new circle event in the queue

41

Page 55: Voronoi diagrams - UCLouvain

Handling Circle Events

1.  Add vertex to corresponding edge record in doubly linked list

2.  Delete from T the leaf node of the disappearing arc and its associated circle events in the event queue

3.  Create new edge record in doubly linked list 4.  Check the new triplets formed by the former

neighboring arcs for potential circle events

41

Page 56: Voronoi diagrams - UCLouvain

A Circle Event

pi pj pk

< pj, pk>

< pi, pj> < pk, pl>

pi

pj

pk pl

l pm

pm pl

< pl, pm>

< pm, pl>

pl

41

Page 57: Voronoi diagrams - UCLouvain

Add vertex to corresponding edge record

pi pj pk

< pj, pk>

< pi, pj> < pk, pl>

pi

pj

pk pl

l pm

pm pl

< pl, pm>

< pm, pl>

pl

Half Edge Record Endpoints.add(x, y)

Half Edge Record Endpoints.add(x, y)

Link!

41

Page 58: Voronoi diagrams - UCLouvain

Deleting disappearing arc

pi pj pk

< pj, pk>

< pi, pj>

pi

pj

pk pl

l pm

pm pl

< pm, pl>

41

Page 59: Voronoi diagrams - UCLouvain

Deleting disappearing arc

pi pj pk

< pj, pk>

< pi, pj>

pi

pj

pk pl

l pm

pm pl

< pm, pl>

< pk, pm>

41

Page 60: Voronoi diagrams - UCLouvain

Create new edge record

pi pj pk

< pj, pk>

< pi, pj>

pi

pj

pk pl

l pm

pm pl

< pm, pl>

< pk, pm>

New Half Edge Record Endpoints.add(x, y)

A new edge is traced out by the new break point < pk, pm>

41

Page 61: Voronoi diagrams - UCLouvain

Check the new triplets for potential circle events

pi pj pk

< pj, pk>

< pi, pj>

pi

pj

pk pl

l pm

pm pl

< pm, pl>

< pk, pm>

Q y … new circle event

41

Page 62: Voronoi diagrams - UCLouvain

Minor Detail

•  Algorithm terminates when Q = ∅, but the beach line and its break points continue to trace the Voronoi edges – Terminate these half-infinite edges via a

bounding box

41

Page 63: Voronoi diagrams - UCLouvain

Algorithm Termination

pi pj pk

< pj, pk>

< pi, pj>

pi

pj

pk pl

l

pm pm pl

< pm, pl>

< pk, pm>

Q ∅

41

Page 64: Voronoi diagrams - UCLouvain

Algorithm Termination

pi pj

< pj, pm>

< pi, pj>

pi

pj

pk pl

l

pm

pm pl

< pm, pl>

Q ∅

41

Page 65: Voronoi diagrams - UCLouvain

Algorithm Termination

pi pj

< pj, pm>

< pi, pj>

pi

pj

pk pl

l

pm

pm pl

< pm, pl>

Q ∅

Terminate half-lines with a bounding box!

41

Page 66: Voronoi diagrams - UCLouvain

Handling Site Events 1.  Locate the leaf representing the existing arc

that is above the new site –  Delete the potential circle event in the event queue

2.  Break the arc by replacing the leaf node with a sub tree representing the new arc and break points

3.  Add a new edge record in the link list 4.  Check for potential circle event(s), add them to

queue if they exist –  Store in the corresponding leaf of T a pointer to the

new circle event in the queue

Running Time

O(log n)

O(1)

O(1)

O(1)

41

Page 67: Voronoi diagrams - UCLouvain

Handling Circle Events

1.  Delete from T the leaf node of the disappearing arc and its associated circle events in the event queue

2.  Add vertex record in doubly link list 3.  Create new edge record in doubly

link list 4.  Check the new triplets formed by the

former neighboring arcs for potential circle events

Running Time

O(log n)

O(1)

O(1)

O(1)

41

Page 68: Voronoi diagrams - UCLouvain

Total Running Time

•  Each new site can generate at most two new arcs ! beach line can have at most 2n – 1 arcs ! at most O(n) site and circle events in the queue

•  Site/Circle Event Handler O(log n)

! O(n log n) total running time

41

Page 69: Voronoi diagrams - UCLouvain

Is Fortunes Algorithm Optimal? •  We can sort numbers using any algorithm that

constructs a Voronoi diagram!

•  Map input numbers to a position on the number line. The resulting Voronoi diagram is doubly linked list that forms a chain of unbounded cells in the left-to-right (sorted) order.

-5 1 3 6 7

Number Line

41

Page 70: Voronoi diagrams - UCLouvain

Summary

•  Voronoi diagram is a useful planar subdivision of a discrete point set

•  Voronoi diagrams have linear complexity and can be constructed in O(n log n) time

•  Fortunes algorithm (optimal)

41

Page 71: Voronoi diagrams - UCLouvain

.

41