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

others
• Category

## Documents

• view

3

0

Embed Size (px)

### Transcript of Voronoi diagrams - UCLouvain

The Supermarket Problem
Suppose we aim at distributing N supermarkets in a given region in such 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 this question 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 plus the cost of transportation to the site;
• the cost of transportation to a site equals the Euclidean distance to the site times a fixed price per unit distance;
• consumers try to minimize the cost of acquiring the good or ser- vice.
2
The Supermarket Problem
The assumptions in the model induce a subdivision of the total area under consideration into regions such that the people who live in the same region all go to the same site. Our assumptions imply that people simply get their goods at the nearest site. The model where every point is assigned to the nearest site is called the Voronoi assignment model. The subdivision induced by this model is called the Voronoi diagram of the set of sites.
7 Voronoi Diagrams The Post O!ce 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 whether the new branch will be profitable, you must estimate the number of customers it will 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 in social geography, when studying the economic activities in a country: what is the trading area of certain cities? In a more abstract setting we have a set of
Figure 7.1 The trading areas of the capitals of the twelve provinces in the Netherlands, as predicted by the Voronoi assignment model
central places—called sites—that provide certain goods or services, and we want to know for each site where the people live who obtain their goods or services from that site. (In computational geometry the sites are traditionally viewed as post offices where customers want to post their letters—hence the subtitle of this chapter.) To study this question 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 plus the cost of transportation to the site; 147
3
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.
Orthogonal Bissectors
Consider two points p and q. We define the orthogonal bisector of p and q as the perpendicular bisector of the line segment pq. This bisector splits the plane into two half-planes.
We denote the open half-plane that 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).
We have
h(pi,pj).
Section 7.1 DEFINITION AND BASIC PROPERTIES
say that a Voronoi diagram is connected we mean that the union of its edges and vertices forms a connected set. The cell of Vor(P) that corresponds to a site pi is denoted V(pi); we call it the Voronoi cell of pi. (In the terminology of the introduction 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 the structure of a single Voronoi cell. For two points p and q in the plane we define the bisector of p and q as the perpendicular bisector of the line segment pq. This bisector splits the plane into two half-planes. We denote the open half-plane that 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 obtain the 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 (possibly unbounded) open convex polygonal region bounded by at most n#1 vertices and at most n#1 edges.
What does the complete Voronoi diagram look like? We just saw that each cell of the diagram is the intersection of a number of half-planes, so the Voronoi diagram is a planar subdivision whose edges are straight. Some edges are line segments and others are half-lines. Unless all sites are collinear there will be no edges that are full lines:
Theorem 7.2 Let P be a set of n point sites in the plane. 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.
Proof. The first part of the theorem is easy to prove, so assume that not all sites in P are collinear.
We first show that the edges of Vor(P) are either segments or half-lines. We already know that the edges of Vor(P) are parts of straight lines, namely parts of the bisectors between pairs of sites. Now suppose for a contradiction that there is an edge e of Vor(P) that is a full line. Let e be on the boundary of the Voronoi cells 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 of V(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 case then there would be a Voronoi cell V(pi) splitting the plane into two. Because Voronoi cells are convex, V(pi) would consist of a strip bounded by two parallel full lines. But we just proved that the edges of the Voronoi diagram cannot be full lines, a contradiction.
Now that we understand the structure of the Voronoi diagram we investigate its complexity, that is, the total number of its vertices and edges. Since there are n sites and each Voronoi cell has at most n#1 vertices and edges, the complexity of Vor(P) is at most quadratic. It is not clear, however, whether Vor(P) can actually have quadratic complexity: it is easy to construct an example where a single Voronoi cell has linear complexity, but can it happen that many cells 149
5
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.
Chapter 7 VORONOI DIAGRAMS
have linear complexity? The following theorem shows that this is not the case and 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 set of n point sites in the plane is at most 2n!5 and the number of edges is at most 3n!6.
Proof. If the sites are all collinear then the theorem immediately follows from Theorem 7.2, so assume this is not the case. We prove the theorem using Euler’s formula, which states that for any connected planar embedded graph with mv nodes, 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 we add one extra vertex v! “at infinity” to the set of vertices and we connect all half-infinite edges of Vor(P) to this vertex. We now have a connected planar graph to which we can apply Euler’s formula. We obtain the following relation between 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 if we sum the degrees of all vertices we get twice the number of edges. Because every 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 the Voronoi diagram. We know that the edges are parts of bisectors of pairs of sites and that the vertices are intersection points between these bisectors. There is a quadratic number of bisectors, whereas the complexity of the Vor(P) is only linear. Hence, not all bisectors define edges of Vor(P) and not all intersections are vertices of Vor(P). To characterize which bisectors and intersections define features of the Voronoi diagram we make the following definition. 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
q
CP(q)
its interior. The following theorem characterizes the vertices and edges of the Voronoi diagram.
Theorem 7.4 For the Voronoi diagram Vor(P) of a set of points P the following holds: (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 j on its boundary but no other site.150
Euler’s formula applied to that graph gives:
(nv + 1)− ne +N = 2
7
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).
and
We conclude that the complexity will never be quadratic.
8
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 7 VORONOI DIAGRAMS
have linear complexity? The following theorem shows that this is not the case and 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 set of n point sites in the plane is at most 2n!5 and the number of edges is at most 3n!6.
Proof. If the sites are all collinear then the theorem immediately follows from Theorem 7.2, so assume this is not the case. We prove the theorem using Euler’s formula, which states that for any connected planar embedded graph with mv nodes, 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 we add one extra vertex v! “at infinity” to the set of vertices and we connect all half-infinite edges of Vor(P) to this vertex. We now have a connected planar graph to which we can apply Euler’s formula. We obtain the following relation between 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 if we sum the degrees of all vertices we get twice the number of edges. Because every 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 the Voronoi diagram. We know that the edges are parts of bisectors of pairs of sites and that the vertices are intersection points between these bisectors. There is a quadratic number of bisectors, whereas the complexity of the Vor(P) is only linear. Hence, not all bisectors define edges of Vor(P) and not all intersections are vertices of Vor(P). To characterize which bisectors and intersections define features of the Voronoi diagram we make the following definition. 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
q
CP(q)
its interior. The following theorem characterizes the vertices and edges of the Voronoi diagram.
Theorem 7.4 For the Voronoi diagram Vor(P) of a set of points P the following holds: (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 j on its boundary but no other site.150
9
Empty circles
Theorem : For the Voronoi diagram Vor(P ) of a set of points P the following holds:
• 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.
• 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.2 COMPUTING THE VORONOI DIAGRAM
Proof. (i) Suppose there is a point q such that CP(q) contains three or more sites on its boundary. Let pi, p j, and pk be three of those sites. Since the interior of CP(q) is empty q must be on the boundary of each of V(pi), V(p j), and V(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 three edges 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 another site 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 not contain any site.
(ii) Suppose there is a point q with the property stated in the theorem. Since CP(q) does not contain any sites in its interior and pi and p j are on its boundary, 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 the theorem implies that q cannot be a vertex of Vor(P). Hence, q lies on an edge of 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. The largest empty circle of any point q in the interior of this edge must contain pi and 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. We now 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 spend O(n logn) time per Voronoi cell, leading to an O(n2 logn) algorithm to compute the whole Voronoi diagram. Can’t we do better? After all, the total complexity of the Voronoi diagram is only linear. The answer is yes: the plane sweep algorithm described below—commonly known as Fortune’s algorithm after its inventor—computes the Voronoi diagram in O(n logn) time. You may be tempted to look for an even faster algorithm, for example one that runs in linear time. This turns out to be too much to ask: the problem of sorting n real numbers is reducible to the problem of computing Voronoi diagrams, so any algorithm for 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—the sweep line—from top to bottom over the plane. While the sweep is performed information is maintained regarding the structure that one wants to compute. More precisely, information is maintained about the intersection of the structure with the sweep line. While the sweep line moves downwards the information does not change, except at certain special points—the event points.
Let’s try to apply this general strategy to the computation of the Voronoi diagram of a set P = {p1, p2, . . . , pn} of point sites in the plane. According to the plane 151
10
• Sweep line (Fortune’s algorithm);
• Dual of the Delaunay triangulation;
• ...
(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).
Doubly connected edge list
Link together three sets of records: vertices, edges and faces.Doubly Connected Edge List (DCEL)
• Main ideas:
– Edges are oriented counterclockwise inside each face
– Since an edge borders two faces, each edge is replaced by
two halfedges, one for each face
f1 f2
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.
• The vertex record of a vertex v stores the
coordinates of v. It also stores a pointer
IncidentEdge(v) to an arbitrary halfedge
that has v as its origin
• The face record of a face f stores a pointer
to some halfedge on its boundary which
can be used as a starting point to traverse
f in counterclockwise order
e5
e6
origin(e1)
previous(e1)
next(e1)
IncidentFace(e1)
e4.twin
e3.twin
• The halfedge record of a halfedge e stores pointer to:
• Origin (e)
• Next(e) : next halfedge on the boundary of IncidentFace(e)
• Previous(e) : previous halfedge
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
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
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.
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
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
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 the results.
(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 recursively defined equation. If we ignore constant factors, and assume for simplicity that n is a power of 2, then the running time 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 complexity is n. If we can show that S(n) = O(n), then by standard results in recurrences it will follow that the overall running 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 special convex 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 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 log n) algorithm for computing the intersection and an O(n log2 n) solution for 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 two boundaries. One works by a plane-sweep approach. The other involves a simultaneous counterclockwise sweep around the two boundaries. The latter algorithm is described in O’Rourke’s book. We’ll discuss the plane-sweep algorithm.
We perform a left-to-right plane sweep to compute the intersection. We begin by breaking the boundaries of the convex polygons into their upper and lower chains. 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. 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).
C2
C1
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.
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 the results.
(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 recursively defined equation. If we ignore constant factors, and assume for simplicity that n is a power of 2, then the running time 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 complexity is n. If we can show that S(n) = O(n), then by standard results in recurrences it will follow that the overall running 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 special convex 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 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 log n) algorithm for computing the intersection and an O(n log2 n) solution for 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 two boundaries. One works by a plane-sweep approach. The other involves a simultaneous counterclockwise sweep around the two boundaries. The latter algorithm is described in O’Rourke’s book. We’ll discuss the plane-sweep algorithm.
We perform a left-to-right plane sweep to compute the intersection. We begin by breaking the boundaries of the convex polygons into their upper and lower chains. 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. 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).
C2
C1
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
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 ( n 2
) = 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
Intersection of line segments
either parallel or collinear. These special cases should be dealt with carefully. If the divisor is nonzero, then we get values for s and t as rational numbers (the ratio of two integers). We can approximate them as floating point numbers, or if we want to perform exact computations it is possible to simulate rational number algebra exactly using high-precision integers (and multiplying through by least common multiples). Once the values of s and t have 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 we will 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 text uses a horizontal line, but there is obviously no significant difference.) 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 continuously, we only need to update data structures 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, and Intersection 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 be discovered as the sweep executes. For example, in the figure below, some of the intersection points lying to the right of the sweep line have not yet been “discovered” as events. However, we will show that every intersection 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 segments along the sweep line.
intersections detected
Figure 17: Plane sweep.
There are a great number of nasty special cases that complicate the algorithm and obscure the main points. We will make a number of simplifying assumptions. They can be overcome through a more careful handling of these 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
Intersection of line segments
either parallel or collinear. These special cases should be dealt with carefully. If the divisor is nonzero, then we get values for s and t as rational numbers (the ratio of two integers). We can approximate them as floating point numbers, or if we want to perform exact computations it is possible to simulate rational number algebra exactly using high-precision integers (and multiplying through by least common multiples). Once the values of s and t have 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 we will 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 text uses a horizontal line, but there is obviously no significant difference.) 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 continuously, we only need to update data structures 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, and Intersection 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 be discovered as the sweep executes. For example, in the figure below, some of the intersection points lying to the right of the sweep line have not yet been “discovered” as events. However, we will show that every intersection 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 segments along the sweep line.
intersections detected
Figure 17: Plane sweep.
There are a great number of nasty special cases that complicate the algorithm and obscure the main points. We will make a number of simplifying assumptions. They can be overcome through a more careful handling of these 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
Intersection of line segments
either parallel or collinear. These special cases should be dealt with carefully. If the divisor is nonzero, then we get values for s and t as rational numbers (the ratio of two integers). We can approximate them as floating point numbers, or if we want to perform exact computations it is possible to simulate rational number algebra exactly using high-precision integers (and multiplying through by least common multiples). Once the values of s and t have 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 we will 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 text uses a horizontal line, but there is obviously no significant difference.) 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 continuously, we only need to update data structures 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, and Intersection 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 be discovered as the sweep executes. For example, in the figure below, some of the intersection points lying to the right of the sweep line have not yet been “discovered” as events. However, we will show that every intersection 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 segments along the sweep line.
intersections detected
Figure 17: Plane sweep.
There are a great number of nasty special cases that complicate the algorithm and obscure the main points. We will make a number of simplifying assumptions. They can be overcome through a more careful handling of these 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 intersection point of two line segments.
Note that endpoint events can be presorted before the sweep runs. In contrast, intersection events will be discovered as the sweep executes. For example, in the figure, some of the intersection points lying to the right of the sweep line have not yet been “discovered” as events. However, we will show that every intersection point will be discovered as an event before the sweep line arrives here.
24
Intersection of line segments
either parallel or collinear. These special cases should be dealt with carefully. If the divisor is nonzero, then we get values for s and t as rational numbers (the ratio of two integers). We can approximate them as floating point numbers, or if we want to perform exact computations it is possible to simulate rational number algebra exactly using high-precision integers (and multiplying through by least common multiples). Once the values of s and t have 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 we will 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 text uses a horizontal line, but there is obviously no significant difference.) 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 continuously, we only need to update data structures 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, and Intersection 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 be discovered as the sweep executes. For example, in the figure below, some of the intersection points lying to the right of the sweep line have not yet been “discovered” as events. However, we will show that every intersection 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 segments along the sweep line.
intersections detected
Figure 17: Plane sweep.
There are a great number of nasty special cases that complicate the algorithm and obscure the main points. We will make a number of simplifying assumptions. They can be overcome through a more careful handling of these 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
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 as follows. Whenever two line segments become adjacent along the sweep line, we will check whether they have an intersection occuring to the right of the sweep line. If so, we will add this new event (assuming that it has not already been added).
A natural question is whether this is sufficient. In particular, if two line segments do intersect, is there necessarily some prior placement of the sweep line such that they are adjacent. Happily, this is the case, but it requires a proof.
Lemma: Given two segments si and sj , which intersect in a single point 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 si and sj are adjacent 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 intersection point, lines si and sj will be adjacent along this sweepline. Consider the event point q with the largest x-coordinate that is strictly less than px. The order of lines along the sweep-line after processing q will be identical the order of the lines along the sweep line just prior p, and hence si and sj will be adjacent at this point.
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 event contains the auxiliary information of what type of event this is (segment endpoint or intersection) and which segment(s) are involved. The operations that this data structure should support are inserting an event (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 in O(log M) time, where M is the number of entries in the queue. (See Cormen, Leiserson, and Rivest for details). 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 balanced binary 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 extractions to 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 geometric effect 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 whose entries are pointers to the line segments, stored in increasing order of y-coordinate along the current sweep line.
Lecture Notes 23 CMSC 754
A natural question is whether this is sufficient. In particular, if two line segments do intersect, is there necessarily some prior placement of 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 single point 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 si and sj are adjacent along the sweep line (and hence will be tested for intersection).
26
Initialize output intersection list IL to be empty;
While (EQ is nonempty) {
If (E is a left endpoint) {
Let segE = E’s segment;
If (I = Intersect( segE with segA) exists)
Insert I into EQ;
Insert I into EQ;
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;
Insert I into EQ;
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;
27
Insert I into EQ;
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
Fortune’s Algorithm
Fortune’s Algorithm: Before discussing Fortune’s algorithm, it is interesting to consider why this algorithm was not invented much earlier. In fact, it is quite a bit trickier than any plane sweep algorithm we have seen so far. The key to any plane sweep algorithm is the ability to discover all “upcoming” events in an efficient manner. For example, in the line segment intersection algorithm we considered all pairs of line segments that were adjacent in the sweep-line status, and inserted their intersection point in the queue of upcoming events. The problem with the Voronoi diagram is that of predicting when and where the upcoming events will occur. Imagine that you are designing a plane sweep algorithm. Behind the sweep line you have constructed the Voronoi diagram based on the points that have been encountered so far in the sweep. The difficulty is that a site that lies ahead of the sweep line may generate a Voronoi vertex that lies behind the sweep line. How could the sweep algorithm know 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 these unanticipated events that make the design of a plane sweep algorithm challenging. (See the figure below.)
unanticipated events
sweep line
Figure 60: Plane sweep for Voronoi diagrams. Note that the position of the indicated vertices depends on sites that have not yet been encountered by the sweep line, and hence are unknown to the algorithm. (Note that the sweep line moves from top to bottom.)
Fortune made the clever observation of rather than computing the Voronoi diagram through plane sweep in its final form, instead to compute a “distorted” but topologically equivalent version of the diagram. This distorted version of the diagram was based on a transformation that alters the way that distances are measured in the plane. The resulting diagram had the same topological structure as the Voronoi diagram, but its edges were parabolic arcs, rather than straight line segments. Once this distorted diagram was generated, it was an easy matter 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 algorithm as distorting the sweep line. Actually, we will think of two objects that control the sweeping process. First, there will be a horizontal sweep line, moving from top to bottom. We will also maintain an x-monotonic curve called a beach line. (It is so named because it looks like waves rolling up on a beach.) The beach line is a monotone curve formed 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 the corresponding site.
The Beach Line: In order to make these ideas more concrete, recall that the problem with ordinary plane sweep is that sites that lie below the sweep line may affect the diagram that lies above the sweep line. To avoid this problem, we will maintain only the portion of the diagram that cannot be affected by anything that lies below the sweep line. To do this, we will subdivide the halfplane lying above the sweep line into two regions: those points that are closer to some site p above the sweep line than they are to the sweep line itself, and those points that 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 are equidistant from the sweep line to their nearest site above the sweep line is called the beach line. Observe that for 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
Fortune’s Algorithm
Fortune’s Algorithm: Before discussing Fortune’s algorithm, it is interesting to consider why this algorithm was not invented much earlier. In fact, it is quite a bit trickier than any plane sweep algorithm we have seen so far. The key to any plane sweep algorithm is the ability to discover all “upcoming” events in an efficient manner. For example, in the line segment intersection algorithm we considered all pairs of line segments that were adjacent in the sweep-line status, and inserted their intersection point in the queue of upcoming events. The problem with the Voronoi diagram is that of predicting when and where the upcoming events will occur. Imagine that you are designing a plane sweep algorithm. Behind the sweep line you have constructed the Voronoi diagram based on the points that have been encountered so far in the sweep. The difficulty is that a site that lies ahead of the sweep line may generate a Voronoi vertex that lies behind the sweep line. How could the sweep algorithm know 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 these unanticipated events that make the design of a plane sweep algorithm challenging. (See the figure below.)
unanticipated events
sweep line
Figure 60: Plane sweep for Voronoi diagrams. Note that the position of the indicated vertices depends on sites that have not yet been encountered by the sweep line, and hence are unknown to the algorithm. (Note that the sweep line moves from top to bottom.)
Fortune made the clever observation of rather than computing the Voronoi diagram through plane sweep in its final form, instead to compute a “distorted” but topologically equivalent version of the diagram. This distorted version of the diagram was based on a transformation that alters the way that distances are measured in the plane. The resulting diagram had the same topological structure as the Voronoi diagram, but its edges were parabolic arcs, rather than straight line segments. Once this distorted diagram was generated, it was an easy matter 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 algorithm as distorting the sweep line. Actually, we will think of two objects that control the sweeping process. First, there will be a horizontal sweep line, moving from top to bottom. We will also maintain an x-monotonic curve called a beach line. (It is so named because it looks like waves rolling up on a beach.) The beach line is a monotone curve formed 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 the corresponding site.
The Beach Line: In order to make these ideas more concrete, recall that the problem with ordinary plane sweep is that sites that lie below the sweep line may affect the diagram that lies above the sweep line. To avoid this problem, we will maintain only the portion of the diagram that cannot be affected by anything that lies below the sweep line. To do this, we will subdivide the halfplane lying above the sweep line into two regions: those points that are closer to some site p above the sweep line than they are to the sweep line itself, and those points that 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 are equidistant from the sweep line to their nearest site above the sweep line is called the beach line. Observe that for 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
Chapter 7 VORONOI DIAGRAMS
sweep paradigm we move a horizontal sweep line ! from top to bottom over the plane. The paradigm involves maintaining the intersection of the Voronoi diagram with the sweep line. Unfortunately this is not so easy, because the part of Vor(P) above ! depends not only on the sites that lie above ! but also on sites below !. Stated differently, when the sweep line reaches the topmost vertex of 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 are forced to apply the plane sweep paradigm in a slightly different fashion: 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 ! that cannot be changed by sites below !.
!
!
of parabolic arcs the beach line. Another way to visualize the beach line is the following. 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 the lowest point of all parabolas.
Observation 7.5 The beach line is x-monotone, that is, every vertical line intersects it in exactly one point.
It is easy to see that one parabola can contribute more than once to the beach line. We’ll worry later about how many pieces there can be. Notice that the breakpoints between the different parabolic arcs forming the beach line lie on edges of the Voronoi diagram. This is not a coincidence: the breakpoints exactly trace out the Voronoi diagram while the sweep line moves from top to bottom. These properties of the beach line can be proved using elementary geometric arguments.
So, instead of maintaining the intersection of Vor(P) with ! we maintain the beach line as we move our sweep line !. We do not maintain the beach line explicitly, since it changes continuously as ! moves. For the moment let’s ignore the issue of how to represent the beach line until we understand where and how its combinatorial structure changes. This happens when a new parabolic arc appears 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. One occasion where this happens is when the sweep line ! 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 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
Chapter 7 VORONOI DIAGRAMS
sweep paradigm we move a horizontal sweep line ! from top to bottom over the plane. The paradigm involves maintaining the intersection of the Voronoi diagram with the sweep line. Unfortunately this is not so easy, because the part of Vor(P) above ! depends not only on the sites that lie above ! but also on sites below !. Stated differently, when the sweep line reaches the topmost vertex of 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 are forced to apply the plane sweep paradigm in a slightly different fashion: 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 ! that cannot be changed by sites below !.
!
!
of parabolic arcs the beach line. Another way to visualize the beach line is the following. 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 the lowest point of all parabolas.
Observation 7.5 The beach line is x-monotone, that is, every vertical line intersects it in exactly one point.
It is easy to see that one parabola can contribute more than once to the beach line. We’ll worry later about how many pieces there can be. Notice that the breakpoints between the different parabolic arcs forming the beach line lie on edges of the Voronoi diagram. This is not a coincidence: the breakpoints exactly trace out the Voronoi diagram while the sweep line moves from top to bottom. These properties of the beach line can be proved using elementary geometric arguments.
So, instead of maintaining the intersection of Vor(P) with ! we maintain the beach line as we move our sweep line !. We do not maintain the beach line explicitly, since it changes continuously as ! moves. For the moment let’s ignore the issue of how to represent the beach line until we understand where and how its combinatorial structure changes. This happens when a new parabolic arc appears 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. One occasion where this happens is when the sweep line ! 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 beach152
One parabola can contribute more than once to the beach line. We’ll worry later about how many pieces there can be.
The breakpoints between the different parabolic arcs forming the beach line lie on edges of the Voronoi diagram. This is not a coinci- dence: the breakpoints exactly trace out the Voronoi diagram while the sweep line moves from top to bottom. These properties of the beach line can be proved using elementary geometric arguments.
32
Chapter 7 VORONOI DIAGRAMS
sweep paradigm we move a horizontal sweep line ! from top to bottom over the plane. The paradigm involves maintaining the intersection of the Voronoi diagram with the sweep line. Unfortunately this is not so easy, because the part of Vor(P) above ! depends not only on the sites that lie above ! but also on sites below !. Stated differently, when the sweep line reaches the topmost vertex of 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 are forced to apply the plane sweep paradigm in a slightly different fashion: 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 ! that cannot be changed by sites below !.
!
!
of parabolic arcs the beach line. Another way to visualize the beach line is the following. 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 the lowest point of all parabolas.
Observation 7.5 The beach line is x-monotone, that is, every vertical line intersects it in exactly one point.
It is easy to see that one parabola can contribute more than once to the beach line. We’ll worry later about how many pieces there can be. Notice that the breakpoints between the different parabolic arcs forming the beach line lie on edges of the Voronoi diagram. This is not a coincidence: the breakpoints exactly trace out the Voronoi diagram while the sweep line moves from top to bottom. These properties of the beach line can be proved using elementary geometric arguments.
So, instead of maintaining the intersection of Vor(P) with ! we maintain the beach line as we move our sweep line !. We do not maintain the beach line explicitly, since it changes continuously as ! moves. For the moment let’s ignore the issue of how to represent the beach line until we understand where and how its combinatorial structure changes. This happens when a new parabolic arc appears 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. One occasion where this happens is when the sweep line ! 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 beach152
Instead of maintaining the intersection of Vor(P ) with l we maintain the 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 how to represent the beach line until we understand where and how its combinatorial structure changes. This happens when a new parabolic arc appears on it, and when a parabolic arc shrinks to a point and disappears.
33
Section 7.2 COMPUTING THE VORONOI DIAGRAM
!
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—we will see shortly exactly when this will happen—the growing edge will run into another edge, and it becomes connected to the rest of the diagram.
So now we understand what happens at a site event: a new arc appears on the 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? The answer is no:
Lemma 7.6 The only way in which a new arc can appear on the beach line is through a site event.
Proof. Suppose for a contradiction that an already existing parabola ! j defined by a site p j breaks through the beach line. There are two ways in which this could happen.
!
! j
they have exactly one point of intersection. Let !y denote the y-coordinate of the sweep line at the moment of tangency. If p j := (p j,x, p j,y), then the parabola ! j is given by
! j := y = 1
2(p j,y ! !y)
y " .
!
! j
The second possibility is that ! j appears in between two arcs. Let these arcs 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 on the 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 defining the 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
Section 7.2 COMPUTING THE VORONOI DIAGRAM
!
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—we will see shortly exactly when this will happen—the growing edge will run into another edge, and it becomes connected to the rest of the diagram.
So now we understand what happens at a site event: a new arc appears on the 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? The answer is no:
Lemma 7.6 The only way in which a new arc can appear on the beach line is through a site event.
Proof. Suppose for a contradiction that an already existing parabola ! j defined by a site p j breaks through the beach line. There are two ways in which this could happen.
!
! j
they have exactly one point of intersection. Let !y denote the y-coordinate of the sweep line at the moment of tangency. If p j := (p j,x, p j,y), then the parabola ! j is given by
! j := y = 1
2(p j,y ! !y)
y " .
!
! j
The second possibility is that ! j appears in between two arcs. Let these arcs 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 on the 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 defining the 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
Section 7.2 COMPUTING THE VORONOI DIAGRAM
!
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—we will see shortly exactly when this will happen—the growing edge will run into another edge, and it becomes connected to the rest of the diagram.
So now we understand what happens at a site event: a new arc appears on the 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? The answer is no:
Lemma 7.6 The only way in which a new arc can appear on the beach line is through a site event.
Proof. Suppose for a contradiction that an already existing parabola ! j defined by a site p j breaks through the beach line. There are two ways in which this could happen.
!
! j
they have exactly one point of intersection. Let !y denote the y-coordinate of the sweep line at the moment of tangency. If p j := (p j,x, p j,y), then the parabola ! j is given by
! j := y = 1
2(p j,y ! !y)
y " .
!
! j
The second possibility is that ! j appears in between two arcs. Let these arcs 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 on the 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 defining the parabolas. This circle is also tangent to the sweep line !. The cyclic order 153
Section 7.2 COMPUTING THE VORONOI DIAGRAM
!
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—we will see shortly exactly when this will happen—the growing edge will run into another edge, and it becomes connected to the rest of the diagram.
So now we understand what happens at a site event: a new arc appears on the 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? The answer is no:
Lemma 7.6 The only way in which a new arc can appear on the beach line is through a site event.
Proof. Suppose for a contradiction that an already existing parabola ! j defined by a site p j breaks through the beach line. There are two ways in which this could happen.
!
! j
they have exactly one point of intersection. Let !y denote the y-coordinate of the sweep line at the moment of tangency. If p j := (p j,x, p j,y), then the parabola ! j is given by
! j := y = 1
2(p j,y ! !y)
y " .
!
! j
The second possibility is that ! j appears in between two arcs. Let these arcs 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 on the 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 defining the 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 appears on the 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? The answer is no.
Theorem : The only way in which a new arc can appear on the beach line is through a site event.
Demonstration is skipped. An immediate consequence of the lemma is that the beach line consists of at most 2N − 1 parabolic arcs: each site encountered gives rise to one new arc and the splitting of at most one existing arc into two, and there is no other way an arc can appear on the beach line.
36
Chapter 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 an infinitesimal motion of the sweep line downward while keeping the circle C tangent to !; see Figure 7.3. Then C cannot have empty interior and still pass
Figure 7.3 The situation when ! j would appear on the beach line, and the circle when the
sweep line has proceeded
!
through p j: either pi or pk will penetrate the interior. Therefore, in a sufficiently small neighborhood of q the parabola ! j cannot appear on the beach line when the 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 of at most 2n!1 parabolic arcs: each site encountered gives rise to one new arc and the splitting of at most one existing arc into two, and there is no other way an arc can appear on the beach line.
Figure 7.4 An arc disappears from the beach line
!
pkpi
q
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, 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 the proof of Lemma 7.6 was excluded. Hence, the three arcs " , " ", and " "" are defined by three distinct sites pi, p j, and pk. At the moment " " disappears, the parabolas defined by these three sites pass through a common point q. Point q is equidistant from ! and each of the three sites. Hence, there is a circle passing 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
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 an infinitesimal motion of the sweep line downward while keeping the circle C tangent to !; see Figure 7.3. Then C cannot have empty interior and still pass
Figure 7.3 The situation when ! j would appear on the beach line, and the circle when the
sweep line has proceeded
!
through p j: either pi or pk will penetrate the interior. Therefore, in a sufficiently small neighborhood of q the parabola ! j cannot appear on the beach line when the 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 of at most 2n!1 parabolic arcs: each site encountered gives rise to one new arc and the splitting of at most one existing arc into two, and there is no other way an arc can appear on the beach line.
Figure 7.4 An arc disappears from the beach line
!
pkpi
q
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, 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 the proof of Lemma 7.6 was excluded. Hence, the three arcs " , " ", and " "" are defined by three distinct sites pi, p j, and pk. At the moment " " disappears, the parabolas defined by these three sites pass through a common point q. Point q is equidistant from ! and each of the three sites. Hence, there is a circle passing 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
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
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 T represent the breakpoints of the beach line.
Notice that a site may appear multiple times on the beach line
40
41
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)
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
4. Check for potential circle event(s), add them to event queue if they exist
41
Locate the existing arc that is above the new site
pi pj pk pl
< 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
pi pj
pk pl
l pm
pm pl
< pl, pm>
< pm, pl>
pl Different arcs can be identified by the same site!
41
pi pj pk
l pm
41
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
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
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
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
41
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
Handling Circle Events
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
pi pj pk
41
New Half Edge Record Endpoints.add(x, y)
A new edge is traced out by the new break point < pk, pm>
41
pi pj pk
41
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
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)
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)
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
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
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)