Voronoi Diagrams. 7.0 Voronoi Diagrams for points. Libraries for Computational Geometry. D7013E Lecture 7

Voronoi Diagrams D7013E Lecture 7 Fortune’s Algorithm Voronoi Diagrams Plane-sweep Proximity problems D7013E Computational Geometry - Håkan Jonsso...
11 downloads 1 Views 1MB Size
Voronoi Diagrams

D7013E Lecture 7 Fortune’s Algorithm

Voronoi Diagrams

Plane-sweep Proximity problems

D7013E Computational Geometry - Håkan Jonsson

1

D7013E Computational Geometry - Håkan Jonsson

2

7.0 Voronoi Diagrams for points

Libraries for Computational Geometry

•  Input:

•  LEDA

–  A set of n points P = {p1, p2, …, pn} called sites

•  Output: –  A subdivision Vor(P) of the plane into n cells such that: –  1. Each cell contains exactly one (1) site –  2. The cell V(pi) of pi contains all points closer to pi than any other site

V(pi) pi

•  CGAL

–  Computational Geometry Algorithms Library –  C++

•  CORE –  http://cs.nyu.edu/exact/ –  They state: In fact, simplest usage is to take a standard C/C++ program, and insert this 2-line preamble: #define Level #include "CORE.h” where sets the desired accuracy.

•  Boundaries of cells consists of points equidistant from two or more sites D7013E Computational Geometry - Håkan Jonsson

–  Library of Efficient Data Structures –  C++

3

D7013E Computational Geometry - Håkan Jonsson

4

Some definitions

Basic Properties

•  We use Euclidean distance in the plane •  Slight abuse of notation:

•  Observation 7.1:

–  Sometimes Voronoi diagram will refer to the edges and vertices that bound the cells rather than the cells themselves

–  Each cell V(pi) is the intersection of n-1 halfplanes defined by bisectors

•  So, at most n-1 vertices and n-1 edges •  Cells are open sets –  Separate from edges and vertices

•  The bisector of a line segment:

•  Edges are open line segments –  Separate from vertices (the end points of the edges)

D7013E Computational Geometry - Håkan Jonsson

5

D7013E Computational Geometry - Håkan Jonsson

Basic Properties

Basic Properties

•  Theorem 7.2: •  If all sites are collinear, Vor(P) consists of n-1 parallel lines

•  Theorem 7.3:

–  For n≥3, •  the number of vertices of a Vor(P) is at most 2n-5 and •  the number of edges is at most 3n-6 –  Vor(P) is a planar graph, if we add a virtual vertex to which all unbounded lines are connected –  Euler’s formula

–  Argue using bisectors

•  If not, Vor(P) is connected and its edges are either line segments or half-lines

•  Note: A single cell could have O(n) vertices

–  Proof by contradiction

D7013E Computational Geometry - Håkan Jonsson

6

–  By Theorem 7.3, there are just a constant number of such cells 7

D7013E Computational Geometry - Håkan Jonsson

8

Basic Properties

Computing a Voronoi Diagram

•  Vertices of Vor(P) are intersections between bisectors

•  A first solution: –  For each site pi: •  For all other sites pj, where j≠i: –  Compute the bisector Li of [pi, pj] »  These bisectors (lines) bound half-planes •  Compute the intersection of the half-planes of all Li –  This is V(pi) –  (Connect all V(pi) into Vor(P))

O(n2)

–  The number of bisectors is –  But Vor(P) has only linear size..?

•  The largest empty circle CP(q) of q with respect to P is the largest circle centered at q that does not contain any point of P •  Theorem 7.4:

–  a) The point q is a vertex of Vor(P) if and only if CP(q) contains 3 or more sites on its boundary –  b) The bisector L between pi and pj define an edge of Vor(P) if and only if there is a point q on L such that CP(q) has pi and pj on its boundary but no other sites D7013E Computational Geometry - Håkan Jonsson

•  Computing n intersections of n-1 half-planes takes O(n2 log n) time as explained in Chapter 4 •  Can we do better? 9

D7013E Computational Geometry - Håkan Jonsson

A lower bound

Fortune’s Algorithm

•  Well, computing a Voronoi Diagram must take Ω(n log n) time because it can be reduced to the problem of sorting:

•  … and there is a better algorithm •  Steve Fortune published an optimal algorithm in 1987

–  Map all numbers xi to points (xi, 0), compute the Voronoi diagram (see below), and find the minimum number xmin –  (xmin, 0) lies in the left-most vertical Voronoi cell ((x2, 0) below) –  The rest of the numbers can now be extracted one after another from left to right by observing that all vertical Voronoi edges lie exactly in the middle between the points (xi, 0)

10

–  Works in Θ(n log n) time and O(n) space

•  Based on plane sweep –  However, slightly more complicated than what we have seen so far

•  The sweep line is a line as before •  The status, however, is not the same –  A concatenation of parabolas above the sweep line –  Called a beach line

x2

x4 x7 x1 x9

x10 x3



•  There are two kinds of event points where the sweep line stops:

x5 x6 x11

D7013E Computational Geometry - Håkan Jonsson

x8

11

–  Site events, and –  Circle events

D7013E Computational Geometry - Håkan Jonsson

12

Demo

The Beach Line •  Acts as our status information •  The edges of Vor(P) are traced out by the breaks in the beach line as the sweep is carried out –  When the sweep line moves, the beach line will also move/change

•  Invariant: –  Above the beach line, the Voronoi diagram has been computed –  Note: Not everything above the sweep line(!) D7013E Computational Geometry - Håkan Jonsson

13

The Beach Line

14

Site Events – Creating Voronoi edges •  Arcs appear in the beach line at site events, which is when the sweep line hits a site:

•  The Voronoi diagram of a point and a line is a parabola •  A beach line is the lower envelope of the Voronoi diagrams of each site above the sweep line and the sweep line

pj

pj

pi

–  The point-wise minimum of all the parabolas

•  An event happens when an arc [of a parabola] appears on, or disappears from, the beach line

D7013E Computational Geometry - Håkan Jonsson

D7013E Computational Geometry - Håkan Jonsson

pi

The break has traced out a line segment, a part of the Voronoi edge between V(pi) and V(pj)

15

pj

pi

V(pj) pj pi

V(pi)

D7013E Computational Geometry - Håkan Jonsson

16

Site Events

Circle events – Creating Voronoi vertices

•  Lemma 7.6:

•  An arc disappears at a circle event

–  The only way in which a new arc can appear on the beach line is through a site event •  Essentially, the further above the sweep line a site lies, the “wider” the parabola

–  A circle event is the lowest point on the circle through three sites defining consecutive arcs in the beach line –  Two break points meet two Voronoi edges are joined by a Voronoi vertex

•  Corollary: –  There are at most 2n-1 arcs in the beach line •  Each new arc might split at most one old arc

•  Since Voronoi edges are traced out by break points, and break points are introduced when arcs are inserted, site events are where new Voronoi edges are starting to take form –  … starting with the second site event (we need at least two arcs to have a break point) D7013E Computational Geometry - Håkan Jonsson

17

D7013E Computational Geometry - Håkan Jonsson

Representation

Representation

•  The Voronoi diagram under construction:

• 

–  A DCEL with a bounding box large enough to hold the final Voronoi diagram

18

The beach line: A balanced binary search tree T in which –  leaves correspond to arcs (ordered by xcoordinate), and –  (internal) nodes correspond to breakpoints. –  Takes O(log n) time to find the arc above a new site –  Pointers from •  leaves into the event queue (to the circle events that removes the arcs, if they exist) •  nodes into the DCEL (the edge being traced out by the breakpoint)

• 

The event queue: –  Events ordered by y-coordinate •  Circle events are represented by the lowest point on the circle –  Pointers from circle events to their leaves in T

D7013E Computational Geometry - Håkan Jonsson

19

D7013E Computational Geometry - Håkan Jonsson

20

False alarms (false circle events)

Complexity

•  Circle events are added immediately when detected during the sweep •  Two concerns:

•  There are two special cases to consider: –  Two or more events on the same ycoordinate •  Example: Four or more sites on a circle –  Would be several coinciding circle events –  Use zero-length Voronoi edges during the computation; filter them away afterwards –  A site event occurs exactly under a break point •  Also here, a zero-length edge is created and everything works fine

–  Not all three points defining consecutive arcs in the beach line give rise to a circle event •  Just skip it –  A circle event might not take place; it must then be cancelled ahead of time •  A new arc splits the three consecutive arcs (a site event occurs) so that the triple disappears –  (Note that this might introduce other, new, circle events) •  Remove it by using the pointers between the circle event in the event queue and the leaf in T of the arc hit by the new arc D7013E Computational Geometry - Håkan Jonsson

Chapter 7 VORONOI DIAGRAMS

•  Theorem 7.10: The Voronoi diagram of n points can be computed in O(n log n) time and O(n) storage

21

Chapter 7 VORONOI DIAGRAMS

D7013E Computational Geometry - Håkan Jonsson

22

half-edge ⃗e we can determine the two sites that have e on their bisector (using IncidentFace(⃗e) and IncidentFace(Twin(⃗e))). Since we can also easily find the two vertices between which the edge lies (Origin(⃗e) and Origin(Twin(⃗e))), we can determine the shape of any edge in constant time. The whole sweep line algorithm is now just an extension of the one for point sites, with more cases to be distinguished and handled. However, the algorithm still has only O(n) events, and each can be handled in O(log n) time.

7.3 Voronoi diagrams of line segments

A problem

•  If the sites are not points but objects, we use as metric the distance to the closest point on the object •  The Voronoi diagram for disjoint line segments consists of line segments and parabolas

•  If line segments share end points, some bisectors become strange.

Theorem 7.11 The Voronoi diagram of a set of n disjoint line segment sites can be computed in O(n log n) time using O(n) storage.

One of the applications of the Voronoi diagram for line segments is in motion planning (covered more extensively in Chapter 13). Assume that a set of obstacles is given, consisting of n line segments in total, and that we have a robot R. We assume that the robot can move freely in all directions, and is approximated well by an enclosing disc D. Suppose that we wish to find a collision-free motion from one location of the robot to another, or to decide that none exists. One motion-planning technique is called retraction. The idea of retraction is that the arcs of the Voronoi diagram define the middle between the line segments, and therefore define a path with the most clearance. So a path over the arcs of the Voronoi diagram is the best option for a collision-free path. Figure 7.6 shows a set of line segments inside a rectangle, together with a Voronoi diagram of the line segments and the sides of the rectangle.

pend

–  They are no longer curves but regions

•  The remedy here is to move line segments a (very) small distance away from each other so they do not intersect at all

pstart

–  We just consider them moved Figure 7.6 Voronoi diagram of line segments, and start and end positions of a disc

162

We can determine a collision-free path between two disc positions amidst a Computational set of D7013E line segments with the followingGeometry algorithm. - Håkan Jonsson

7.3

Vorono

The Voronoi dia distance from a p point on the obje bisector of two d up to seven parts Parabolic arcs oc the closest point bisector part is st are somewhat m Voronoi diagram Assume for a that is, we allow be equally close t are not even curv and computing V will simply assu applications we disjoint line segm The sweep l segment sites. L call the segments interior in the fo

s 23

D7013E Computational Geometry - Håkan Jonsson

24

Figure 7.5 The beach line for a set of line segment sites. The breakpoints trace the dashed

bisector of two disjoint line segments has a more complex shape. It consists of Voronoi diagram of n disjoint line segments is still only O(n). parts, where each part is either a line segment or a parabolic arc. Assume for a moment that we allow the line segments up to to beseven non-crossing, Parabolic occur that is, we allow them to share endpoints. Then a whole region of thearcs plane canif the closest point of one line segment is an endpoint and the closest of the other line segment is in its interior. In all other cases the be equally close to two line segments via their common endpoint, andpoint bisectors bisector part is straight. Although bisectors and therefore the Voronoi diagram are not even curves anymore. To avoid the complications that arise in defining are somewhat more complex, the number of vertices, edges, and faces in the and computing Voronoi diagrams of line segments that share endpoints, we Voronoi diagram of n disjoint line segments is still only O(n). will simply assume here that all line segments are strictly disjoint. In many Assume for a moment that we allow the line segments to be non-crossing, applications we can simply shorten the line segments very slightly to obtain that is, we allow them to share endpoints. Then a whole region of the plane can disjoint line segments. be equally close to two line segments via their common endpoint, and bisectors The sweep line algorithm for points can be adapted are to the case curves of lineanymore. To avoid the complications that arise in defining not even S = {s1 ,the . . . ,same sn } beplane a set sweep of n disjoint line computing segments. We sites. and Voronoi diagrams of line segments that share endpoints, • segment It turns out Let essentially still works, with some •  Theweinput calladjustments the segments of S sites as before, and use the terms site endpoint and sitehere that all line segments are strictly disjoint. In many will simply assume as sites applications we can simply shorten the line segments very slightly to obtain –  However, the beach line now contains both parabolas and line segments interior in the following description.

An algorithm

s1

An algorithm

s3 s2

Figure 7.5 h line for a set of line segment e breakpoints trace the dashed ich include the Voronoi edges

VORONOI DIAGRAMS

s4

–  End points of these are disjoint line segments. site event points The sweep line algorithm for points can be adapted to the case of line We are 5 kinds of segment sites. Let S = {s1 , . . . , sn } be a set of n disjoint line segments. •  There Figure 7.5 s5 the segments of S sites as before, and use the terms site endpoint and site call The beach line for a set of line segment circle event sites. The points breakpoints trace the dashed interior in the following description. arcs, which include the Voronoi edges ℓ s1

s3 s2

Figure 7.5

s4

s5

interior in the followin

Clearly, there must be size of Couter , and at le of Cinner . But one ℓ s1 poin annulus yet. There ap 7.5a piecewisepoints on the two circ Recall that our algorithm for point sites maintainedFigure a beach line: parabolic x-monotone curve suchfor that,afor on thesegment curve, the distance to Couter contains at The beach line setpoints of line the closest site above the sweep line is equal to the distance to the sweep line. point of P. sites. breakpoints dashed What does the beachThe line look like when thetrace sites arethe segments? First we note that a line segment may be partially above and partially below the sweep arcs, site which include the Voronoi edges Couter contains at l line. When defining the beach line, we consider only those parts of the sites that of P. are above the sweep line. Hence, for a given position of the sweep line ℓ, the beach line consists of those points such that the distance to the closest portion Recall Couterthat andour Cinner b algor s1

s3

s2

s4

s5 Chapter 7

VORONOI DIAGRAMS

•  The beach line can be maintained in the spirit of how we first did it but, of course, involving more cases of a site above ℓ is equal to the distance to ℓ. This means that the beach line ℓ

Recall that our algorithm for line point a beach line: a piecewise The beach forsites a set maintained of line segment parabolic x-monotone curve such that, fortrace points on the curve, the distance to sites. The breakpoints the dashed –  Read arcs, whichline include the Voronoi the closest site above the sweep is equal to theedges distance to the sweep line. What does the beach line look like when the sites are segments? First we note Recall the thatsweep our algorithm for point sites maintained a beach line: a piecewise that a line segment site may be partially above and partially below D7013E Computational Geometry - Håkan Jonsson 25 parabolic line. When defining the beach line, we consider only those parts of thex-monotone sites that curve such that, for points on the curve, the distance to thesweep closestline site ℓ, above are above the sweep line. Hence, for a given position of the the the sweep line is equal to the distance to the sweep line. does theportion beach line look like when the sites are segments? First we note beach line consists of those points such that the distance toWhat the closest line segment site may be partially above and partially below the sweep of a site above ℓ is equal to the distance to ℓ. This meansthat thatathe beach line line. When defining the beach line, we consider only those parts of the sites that now consists of parabolic arcs and straight line segments. A parabolic arc arises are above the sweep line. Hence, for a given position of the sweep line ℓ, the when that part of the beach line is closest to a site endpoint,beach and aline straight line consists of those points such that the distance to the closest portion segment arises when that part of the beach line is closest to of a site interior. Note a site above ℓ is equal to the distance to ℓ. This means that the beach line that if a site interior intersects ℓ, then the beach line will have straight line nowtwo consists of parabolic arcs and straight line segments. A parabolic arc arises segments ending at the intersection—see site s2 in Figure 7.5. when that part of the beach line is closest to a site endpoint, and a straight line

Result

segments act

The Voronoi diagram can also be defined for objects other than points.bisector The part is straight. distance from a point in the plane to an object is then measured to the closest are point on the object. Whereas the bisector of two points is simply a line, the somewhat more co bisector of two disjoint line segments has a more complex shape. It consists of Voronoi diagram of n d up to seven parts, where each part is either a line segment or a parabolic arc. Parabolic arcs occur if the closest point of one line segment is an endpoint and Assume for a mom the closest point of the other line segment is in its interior. In all other cases the that is, we allow them t bisector part is straight. Although bisectors and therefore the Voronoi diagram are somewhat more complex, the number of vertices, edges, and faces in betheequally close to two Voronoi diagram of n disjoint line segments is still only O(n). are not even curves any Assume for a moment that we allow the line segments to be non-crossing, that is, we allow them to share endpoints. Then a whole region of the plane can computing Vorono and be equally close to two line segments via their common endpoint, and bisectors will simply assume he are not even curves anymore. To avoid the complications that arise in defining and computing Voronoi diagrams of line segments that share endpoints, we applications we can sim will simply assume here that all line segments are strictly disjoint. In many applications we can simply shorten the line segments very slightly to obtain disjoint line segments. disjoint line segments. The sweep line algorithm for points can be adapted to the case of line The sweep line alg We segment sites. Let S = {s1 , . . . , sn } be a set of n disjoint line segments.segment sites. Let S = call the segments of S sites as before, and use the terms site endpoint and site call the segments of S s interior in the following description.

on your own 160

parabolic x-monotone c now consists of parabolic arcs and straight line segments. A parabolic arc arises when that part of the beach line is closest to a site endpoint, and a straight line the closest site above th segment arises when that part of the beach line is closest to a site interior. Note that if a site interior intersects ℓ, then the beach line will have two straight line What does the beach lin segments ending at the intersection—see site s2 in Figure 7.5.

that a line segment site line. When defining the are above the sweep lin Figure 7.7 beach line consists of t Three cases of the smallest-width of a site above ℓ is equ annulus now consists of parabol when that partor ofCthe bec If Cinner outer segment when we canarises always find th an thatsmallest-width if a site interior int annulu 160 segments ending at the of finding the smalle technique we used fo segment arises when that part of the beach line is closest to a site interior. Note the smallest-width ann that if a site interior intersects ℓ, then the beach line will have two straight line the optimal annulus s segments ending at the intersection—see site s2 in Figure 7.5. cell of p j annulus does not hold •  The cell of a site pi consists of those Finding the small points that lie further away from pi than Once the center poin any other site the points of P that a –  The intersection of the ”other sides” of diagram of P, then th the bisectors pi that a similar structur cell of pi –  Vorfp(P) Voronoi diagram. Th •  Observation 7.13: of P is the farthest po pj intersection of n − 1 h –  Only sites on the convex hull of the sites the “other sides” of th have cells cells of the farthest-po •  Can be computed in O(n log n) time a cell in the farthest-p –  O(n) time if the points are all in convex can be empty. It is n position point in the set P mu •  Bonus: We can get the convex hull in O(n) a point that lies insid time from Vorfp(P) Voronoi diagram. D7013E Computational Geometry - Håkan Jonsson

26

7.4 Furthest-point Voronoi diagrams

•  The number of events160 turns out to be O(n) •  Theorem 7.11: –  The Voronoi diagram of a set of n disjoint line segments can be computed in O(n log n) time using O(n) storage

•  Application: Motion planning – compute an obstacle avoiding path for a circle –  Move along the Voronoi diagram –  Remove edges at too narrow passages –  Do a depth-first search

•  So, the path can be computed in O(n log n) time D7013E Computational Geometry - Håkan Jonsson

27

D7013E Computational Geometry - Håkan Jonsson

164

28

Observation 7.13 Gi the farthest-point Voro of P.

7.4 Furthest-point Voronoi diagrams •  Application: Roundness of manufactured goods via surface sampling •  Measured by computing a smallestwidth annulus of the sampled points P –  Using both the Vor(P) and the Vorfp(P)

•  Theorem 7.15: A smallestwidth annulus can be computed in O(n2) time using O(n) space D7013E Computational Geometry - Håkan Jonsson

29