Computing Delaunay Triangulation and Voronoi Diagram Lekcija 10 - - PowerPoint PPT Presentation

computing delaunay triangulation and voronoi diagram
SMART_READER_LITE
LIVE PREVIEW

Computing Delaunay Triangulation and Voronoi Diagram Lekcija 10 - - PowerPoint PPT Presentation

Computing Delaunay Triangulation and Voronoi Diagram Lekcija 10 Sergio Cabello sergio.cabello@fmf.uni-lj.si FMF Univerza v Ljubljani Includes slides by Antoine Vigneron Sergio Cabello RC Computing Vor Del Outline RIC of the


slide-1
SLIDE 1

Computing Delaunay Triangulation and Voronoi Diagram

Lekcija 10 Sergio Cabello sergio.cabello@fmf.uni-lj.si FMF Univerza v Ljubljani Includes slides by Antoine Vigneron

Sergio Cabello RC – Computing Vor – Del

slide-2
SLIDE 2

Outline

◮ RIC of the Delaunay triangulation

  • randomized
  • expected O(n log n) time

◮ Fortune’s algorithm to construct Voronoi diagram

  • sweep line algorithm
  • worst-case O(n log n) time

Sergio Cabello RC – Computing Vor – Del

slide-3
SLIDE 3

Incircle test

d c b a C inCircle(a, b, c, d) < 0

◮ assume triangle abc is counterclockwise ◮ let C be the circumcircle of abc ◮ we want to design a test inCircle(·) such that

  • inCircle(a, b, c, d) = 0 if d ∈ C
  • inCircle(a, b, c, d) > 0 if d is outside C
  • inCircle(a, b, c, d) < 0 if d is inside C

Sergio Cabello RC – Computing Vor – Del

slide-4
SLIDE 4

Expression

◮ we use the following expression:

inCircle(a, b, c, d) = det     1 ax ay ax2 + ay 2 1 bx by bx 2 + by 2 1 cx cy cx 2 + cy 2 1 dx dy dx 2 + dy 2    

◮ why does it work?

  • we next see proof with geometric interpretation
  • another possible path: algebra

Sergio Cabello RC – Computing Vor – Del

slide-5
SLIDE 5

Orientation of vectors in I R3

◮ the orientation of (−

→ u , − → v , − → w ) is given by the sign of det   ux uy uz vx vy vz wx wy wz  

− → v O z y x Orientation (− → u , − → v , − → w ) > 0 Orientation (− → v , − → u , − → w ) < 0 − → w − → u ⇐ right thumb rule

Sergio Cabello RC – Computing Vor – Del

slide-6
SLIDE 6

Orientation of a tetrahedron

◮ orientation of tetrahedron abcd = orientation of (−

→ ab, − → ac, − → ad)

a b d c Orientation(abcd) = Orientation (− → ab, − → ac, − → ad) > 0 ⇐ right thumb rule

Sergio Cabello RC – Computing Vor – Del

slide-7
SLIDE 7

Orientation of a tetrahedron

◮ Orientation (abcd)

= det   bx − ax by − ay bz − az cx − ax cy − ay cz − az dx − ax dy − ay dz − az   = det     1 ax ay az bx − ax by − ay bz − az cx − ax cy − ay cz − az dx − ax dy − ay dz − az    

◮ developing with respect to first column Sergio Cabello RC – Computing Vor – Del

slide-8
SLIDE 8

Orientation of a tetrahedron

◮ add first row to the other rows ◮ Orientation (abcd)

= det     1 ax ay az 1 bx by bz 1 cx cy cz 1 dx dy dz    

◮ note that it generalizes the predicate to test right turns in I

R2

Sergio Cabello RC – Computing Vor – Del

slide-9
SLIDE 9

Paraboloid P

◮ in I

R3, let P be the paraboloid with equation z = x2 + y 2

O x y z

Sergio Cabello RC – Computing Vor – Del

slide-10
SLIDE 10

Property

◮ let H be a non–vertical plane ◮ H has equation z = αx + βy + γ ◮ the projection of H ∩ P onto plane Oxy has equation

x2 + y 2 = αx + βy + γ

  • this is a circle

◮ property: the projection of H ∩ P onto plane Oxy is a circle Sergio Cabello RC – Computing Vor – Del

slide-11
SLIDE 11

Property

O x y z a circle H P

Sergio Cabello RC – Computing Vor – Del

slide-12
SLIDE 12

Proof

O x y z a b c ˆ a ˆ c ˆ b H P

Sergio Cabello RC – Computing Vor – Del

slide-13
SLIDE 13

Proof

◮ let p = (px, py) ◮ we lift p onto P and obtain ˆ

p = (px, py, p2

x + p2 y)

◮ the transformation p → ˆ

p is called the lifting map

Sergio Cabello RC – Computing Vor – Del

slide-14
SLIDE 14

Proof

◮ we lift a, b, c and d:

ˆ a = (ax, ay, a2

x + a2 y)

ˆ b = (bx, by, b2

x + b2 y)

ˆ c = (cx, cy, c2

x + c2 y )

ˆ d = (dx, dy, d2

x + d2 y )

◮ we denote by H the plane through {ˆ

a, ˆ b, ˆ c}

◮ inCircle(a, b, c, d) = 0 means that Orientation(ˆ

a, ˆ b, ˆ c, ˆ d) = 0

  • so ˆ

d ∈ H

  • we project to horizontal
  • we obtain that d is in the circumcircle of abc

Sergio Cabello RC – Computing Vor – Del

slide-15
SLIDE 15

Proof: first case

◮ a, b, c, d cocircular if ˆ

a, ˆ b, ˆ c, ˆ d coplanar

O x y z a b c ˆ a ˆ c ˆ b ˆ d d H P

Sergio Cabello RC – Computing Vor – Del

slide-16
SLIDE 16

Proof: other cases

◮ inCircle(a, b, c, d) > 0 means that Orientation(ˆ

a, ˆ b, ˆ c, ˆ d) > 0

  • then ˆ

d is above H

  • so d is outside the circumcircle of abc

◮ inCircle(a, b, c, d) < 0 means that Orientation(ˆ

a, ˆ b, ˆ c, ˆ d) < 0

  • then ˆ

d is below H

  • so d is inside the circumcircle of abc

Sergio Cabello RC – Computing Vor – Del

slide-17
SLIDE 17

Lifts and Delaunay triangulation

Lifting DT (P)

x y z P

Sergio Cabello RC – Computing Vor – Del

slide-18
SLIDE 18

Circumcircle property

◮ P = {p1, p2, . . . pn} is a set of points in the plane in general

position

◮ we denote ˆ

P = {ˆ p1, ˆ p2, . . . ˆ pn}

◮ last lecture: triangle pipjpk is a face of DT (P) iff its

circumcircle is empty

  • it means that ∀p ∈ P \ {pi, pj, pk}, ˆ

p is above the plane through ˆ pi ˆ pjˆ pk

  • in other words, ˆ

piˆ pjˆ pk is a facet of the lower hull of ˆ P

Theorem

The edges of the Delaunay triangulation of P are the projection of the edges of the lower hull of ˆ P onto the plane z = 0

Sergio Cabello RC – Computing Vor – Del

slide-19
SLIDE 19

Geometric property

abcd convex quadrilateral.

a b c d c a b d

  • r

Sergio Cabello RC – Computing Vor – Del

slide-20
SLIDE 20

Geometric property

◮ let acbd be a convex quadrilateral with diagonal ab ◮ then either

  • c is inside the circumcircle of abd and d is inside the

circumcircle of abc

  • or c is outside circumcircle of abd and d is outside the

circumcircle of abc

Sergio Cabello RC – Computing Vor – Del

slide-21
SLIDE 21

Proof (by picture)

ˆ a, ˆ b, ˆ c, ˆ d define a tethraedra in R3

ˆ c ˆ b ˆ d ˆ a a b d c d a c b OR ˆ c ˆ a ˆ d ˆ b Concave Convex

Sergio Cabello RC – Computing Vor – Del

slide-22
SLIDE 22

Edge flip: definition

a b c d b c d a ab is illegal cd is locally Delaunay

◮ Defined only for convex quadrilaterals. ◮ Why not concave? What is wrong in the proof? Sergio Cabello RC – Computing Vor – Del

slide-23
SLIDE 23

Definitions

◮ P a set of n points in I

R2 in general position: no 4 cocircular

◮ T a triangulation of P ◮ ab an edge of T ◮ let (c, d) ∈ P2 such that abc and abd are triangles of T ◮ ab is illegal iff acbd convex quadrilateral and d is inside the

circumcircle of abc

◮ otherwise ab is locally Delaunay: acbd non-convex quadrilateral

  • r d is outside the circumcircle of abc

◮ deciding if ab is locally Delaunay or illegal is done computing the

sign of CCW (abc) and the sign of inCircle(a, b, c, d)

Sergio Cabello RC – Computing Vor – Del

slide-24
SLIDE 24

Definition

◮ if ab is illegal, we can perform an edge flip:

remove ab from T and insert cd

◮ now cd is locally Delaunay

c a d b

Sergio Cabello RC – Computing Vor – Del

slide-25
SLIDE 25

Definition

◮ if ab is illegal, we can perform an edge flip:

remove ab from T and insert cd

◮ now cd is locally Delaunay

a c b d

Sergio Cabello RC – Computing Vor – Del

slide-26
SLIDE 26

Edge flip: interpretation

ˆ a ˆ c ˆ c ˆ b ˆ b ˆ d ˆ d ˆ a a b d c d a c b

the lifted triangulation gets lower the upper envelope becomes convex

Sergio Cabello RC – Computing Vor – Del

slide-27
SLIDE 27

Characterization

Theorem

T be a triangulation of P. T = DT (P) if and only if all the edges of T are locally Delaunay

Dokaz.

◮ if T is Delaunay, then clearly all edges are locally Delaunay

because of circumcircle property

◮ other direction:

  • 2-dimensional proof in the book
  • use the lifting map: locally Delaunay ⇔ locally convex ⇔

globally convex ⇔ globally Delaunay

Sergio Cabello RC – Computing Vor – Del

slide-28
SLIDE 28

First algorithm – Idea

◮ draw a triangulation T of P ◮ if all the edges of T are locally Delaunay, we are done ◮ otherwise, pick an illegal edge and flip it ◮ repeat this process until all edges are locally Delaunay Sergio Cabello RC – Computing Vor – Del

slide-29
SLIDE 29

Pseudocode

Algorithm SlowDelaunay(P) Input: a set P of n points in I R2 Output: DT (P) 1. compute a triangulation T of P 2. initialize a stack containing all the edges of T 3. while stack is non–empty 4. do pop ab from stack and unmark it 5. if ab is illegal then 6. do flip ab to cd 7. for xy ∈ {ac, cb, bd, da} 8. do if xy is not marked 9. then mark xy and push it on stack

  • 10. return T

Sergio Cabello RC – Computing Vor – Del

slide-30
SLIDE 30

Analysis

◮ it is not obvious that this program halts! ◮ in fact runs in Θ(n2) time ◮ proof using lifting map

  • each time we flip an edge, the lifted triangulation gets lower
  • so an edge can be flipped only once: afterward it remains

above the lifted triangulation

  • there are O(n2) edges
  • so the algorithm runs in O(n2) time

◮ show a lower bound of Ω(n2) for this algorithm Sergio Cabello RC – Computing Vor – Del

slide-31
SLIDE 31

Randomized incremental algorithm

Sergio Cabello RC – Computing Vor – Del

slide-32
SLIDE 32

Preliminary

◮ let (p1, p2, p3 . . . pn) be a random permutation of P ◮ let p−3p−2p−1 be a large triangle containing P

P p−1 p−3 p−2

◮ for all i we denote Pi = {p−3, p−2, p−1, p1, p2, . . . pi} Sergio Cabello RC – Computing Vor – Del

slide-33
SLIDE 33

First step

p−1 p−3 p−2 p1

Sergio Cabello RC – Computing Vor – Del

slide-34
SLIDE 34

First step

p−1 p−3 p−2 p1

Sergio Cabello RC – Computing Vor – Del

slide-35
SLIDE 35

Idea

◮ insert p1, then p2 . . . and finally pn ◮ suppose we have computed DT (Pi−1) ◮ insert pi ⇒ splits a triangle into three

  • find this triangle using conflict lists

⋆ each non inserted point has a pointer to the triangle in

DT (Pi−1) that contains it

⋆ each triangle in DT (Pi−1) is associated with the list of

all the non–inserted points that it contains

◮ perform edge flips until no illegal edge remains

  • we only need to perform flips around pi
  • on average, this step takes constant time

◮ we have just computed DT (Pi) ◮ repeat the process until i = n Sergio Cabello RC – Computing Vor – Del

slide-36
SLIDE 36

Example

p

◮ inserting pi ◮ to simplify the notations, we denote p = pi ◮ we do not draw p−1p−2p−3 Sergio Cabello RC – Computing Vor – Del

slide-37
SLIDE 37

Example

p a b c

◮ use the pointer from p to the triangle abc that contains it ◮ split abc into abp, bcp and cap ◮ split the conflict list of abc accordingly Sergio Cabello RC – Computing Vor – Del

slide-38
SLIDE 38

Example

p a b c

◮ edge ab is illegal ◮ flip it Sergio Cabello RC – Computing Vor – Del

slide-39
SLIDE 39

Example

p a b c d

◮ edge ab has been flipped into pd ◮ ad is locally Delaunay, we keep it Sergio Cabello RC – Computing Vor – Del

slide-40
SLIDE 40

Example

p a b c d

◮ edge bd is illegal Sergio Cabello RC – Computing Vor – Del

slide-41
SLIDE 41

Example

p a b c d e

◮ edge bd has been flipped into pe ◮ edges de and be are locally Delaunay, we keep them Sergio Cabello RC – Computing Vor – Del

slide-42
SLIDE 42

Example

p a b c d e

◮ edge bc is illegal Sergio Cabello RC – Computing Vor – Del

slide-43
SLIDE 43

Example

a b c d e p f

◮ edge bc has been flipped into pf Sergio Cabello RC – Computing Vor – Del

slide-44
SLIDE 44

Example

b c d e p f a

◮ edge ac is illegal Sergio Cabello RC – Computing Vor – Del

slide-45
SLIDE 45

Example

b c d e p f a g

◮ edge ag is locally Delaunay ◮ no more edge to flip: we are done Sergio Cabello RC – Computing Vor – Del

slide-46
SLIDE 46

Explanation

◮ we considered triangles in counterclockwise order around p and

flipped illegal edges

◮ why is it enough to consider only triangles adjacent to p? ◮ see proof later ◮ the pseudocode for this algorithm is very simple ◮ see next slide Sergio Cabello RC – Computing Vor – Del

slide-47
SLIDE 47

Pseudocode

Algorithm Insert(p) Input: a point p, a set of point P and T = DT (p) Output: DT (P ∪ {p}) 1. Find the triangle abc of DT (P ∪ {p}) containing p (∗ use reverse pointers from conflict lists ∗) (∗ abc is chosen to be counterclockwise ∗) 2. Insert edges pa,pb and pc (∗ it includes conflict lists updates ∗) 3. SwapTest(ab) (∗ pseudocode of this procedure next slide ∗) 4. SwapTest(bc) 5. SwapTest(ca)

Sergio Cabello RC – Computing Vor – Del

slide-48
SLIDE 48

Pseudocode

Algorithm SwapTest(ab) 1. if ab is an edge of the exterior face 2. do return 3. d ←the vertex to the right of edge ab 4. if inCircle(p, a, b, d) < 0 5. do Flip edge ab for pd (∗ it includes conflict lists update ∗) 6. SwapTest(ad) 7. SwapTest(db)

Sergio Cabello RC – Computing Vor – Del

slide-49
SLIDE 49

Proof

◮ we only flipped edges of triangles that contain p ◮ why is it sufficient? ◮ remember Theorem: locally Delaunay implies Delaunay ◮ any edge between two triangles that do not contain p was locally

Delaunay before insertion of p

◮ so it is still locally Delaunay ◮ thus the triangulation we obtain is the Delaunay triangulation Sergio Cabello RC – Computing Vor – Del

slide-50
SLIDE 50

Analysis

◮ we look at ti: time taken to update the current triangulation

while inserting pi

◮ it does not account for conflict lists updates ◮ each new edge (after splitting abc or after a flip) contains pi ◮ so ti is proportional to the degree of pi in DT (pi)

  • degree of pi: number of edges that contain pi

Sergio Cabello RC – Computing Vor – Del

slide-51
SLIDE 51

Analysis

◮ we use backward analysis: Pi is fixed, pi is random ◮ each edge has two vertices ◮ so each edge contains pi with probability 2

i

◮ there are O(i) edges in the whole triangulation (by Euler

formula)

◮ so by backward analysis

E[ti] = O(i) i = O(1)

◮ so the time for updating the triangulation is O(n) over the

course of the whole algorithm

◮ similar with trapezoidal map: what takes Θ(n log n) time is the

update of conflict lists (see next slide)

Sergio Cabello RC – Computing Vor – Del

slide-52
SLIDE 52

Analysis

◮ while inserting pi, what is the probability that p ∈ P \ Pi is

rebucketed?

◮ backward analysis

  • assume p is in triangle abc
  • this is the probability that pi ∈ {a, b, c}
  • so it is 3/i

◮ so while inserting pi, we rebucket less than 3n/i sites on average Sergio Cabello RC – Computing Vor – Del

slide-53
SLIDE 53

Analysis

◮ problem: a site may be rebucketed several times at step i

  • intuition: only a constant number of flips at each step so it
  • nly account for a constant factor
  • proof omitted

◮ so overall, rebucketing takes expected time

O n

  • i=1

n i

  • = O(n log n)

Sergio Cabello RC – Computing Vor – Del

slide-54
SLIDE 54

Choice of p−1p−2p−3

p−3(−3M, −3M) p−2(3M, 0) P p−1(0, 3M) (M, M)

◮ why do we need p−1p−2p−3? ◮ M: max of any coordinate of any point in P ◮ For incircle test, do as if these three points are outside any circle

defined by three points in P

Sergio Cabello RC – Computing Vor – Del

slide-55
SLIDE 55

Theorem

The Delaunay triangulation of n points can be computed in expected O(n log n) time with a randomized incremental algorithm.

Sergio Cabello RC – Computing Vor – Del

slide-56
SLIDE 56

Fortune’s algorithm

◮ sweep line algorithm ◮ what invariant do we maintain? ◮ cannot maintain Voronoi diagram to the left Sergio Cabello RC – Computing Vor – Del

slide-57
SLIDE 57

Fortune’s algorithm

◮ sweep vertical line ℓ from left to right ◮ maintain the portion of Voronoi diagram that cannot change ◮ what points cannot change? ◮ how does the corresponding portion of the Voronoi diagram look

like?

◮ beach-line: curve separating fixed from changing part ◮ the break points of the beach-line trace Voronoi edges Sergio Cabello RC – Computing Vor – Del

slide-58
SLIDE 58

Beach line

Sergio Cabello RC – Computing Vor – Del

slide-59
SLIDE 59

Beach line

Sergio Cabello RC – Computing Vor – Del

slide-60
SLIDE 60

Beach line

Sergio Cabello RC – Computing Vor – Del

slide-61
SLIDE 61

Fortune’s algorithm – Events

◮ insertion event: a new parabolic arc appears in the beach-line ◮ deletion event: a parabolic arc dissappears from the beach-line

sweep line sweep line

Sergio Cabello RC – Computing Vor – Del

slide-62
SLIDE 62

Fortune’s algorithm – Insertion Events

Lemma

An insertion event happens only when the sweep line passes a site. Proof: later This cannot happen: Only this can happen:

sweep line sweep line

degeneretad parabola

Consequence: the beach line has at most 2n − 1 parabolic arcs

Sergio Cabello RC – Computing Vor – Del

slide-63
SLIDE 63

Fortune’s algorithm – Deletion Events

Lemma

Deletion can only happen when the points p, q, r corresponding to consecutive parabolic arcs become cocircular. Proof: later

sweep line

p q r

sweep line

p q r

sweep line

p q r

Sergio Cabello RC – Computing Vor – Del

slide-64
SLIDE 64

An applet

A really nice applet: http://www.diku.dk/hjemmesider/studerende/duff/Fortune/

Sergio Cabello RC – Computing Vor – Del

slide-65
SLIDE 65

A 3D view of the algorithm

◮ for each site p, make the surface cone

Cp = {(x, y, z) ∈ R3 | x2 + y 2 = z2, z ≥ 0}

◮ the lower envelope of the cones are the points visible from

z = −∞

◮ Voronoi faces, edges and vertices are the same faces, edges and

vertices of the lower envelope

◮ picture in the board ◮ sweep a plane π slanted 45 degrees to the xy-plane ◮ the sweep line ℓ is π ∩ xy-plane ◮ the left of ℓ is the portion of lower envelope below π Sergio Cabello RC – Computing Vor – Del

slide-66
SLIDE 66

A 3D view of the algorithm

◮ it should be clear now that

  • inserting parabolic arcs only at sites
  • deleting parabolic arcs only at circles centered at Voronoi

vertices

Sergio Cabello RC – Computing Vor – Del

slide-67
SLIDE 67

Algorithm – Data structures

◮ Voronoi diagram to the left of the beach line

  • DCEL

◮ Beach line

  • BST with the parabolic arcs from top-to-bottom

◮ Priority event queue sorted by x-coordinate

  • BST
  • initially contains all sites as insertion events

Sergio Cabello RC – Computing Vor – Del

slide-68
SLIDE 68

Algorithm – Events

◮ Insertion event

  • update the beach-line
  • update the portion of

Voronoi diagram

  • check for new deletion

events

sweep line sweep line

degeneretad parabola

◮ Deletion event

  • update the beach-line
  • update the portion of

Voronoi diagram

  • check for new deletion

events

sweep line

p q r

sweep line

p q r

sweep line

p q r

Sergio Cabello RC – Computing Vor – Del

slide-69
SLIDE 69

◮ in each event we need O(log n) time ◮ there are O(n) events:

  • sites
  • vertices of the final Voronoi diagram

Theorem

The Voronoi diagram of n sites can be computed in O(n log n) time with a sweep line in O(n log n) time.

◮ the algorithm does not use parabolic arcs!! ◮ only the concept Sergio Cabello RC – Computing Vor – Del

slide-70
SLIDE 70

Conclusion

◮ the Delaunay triangulation can be computed in expected time

O(n log n) with RIC

◮ it holds for worst case input, the expectation is over the random

choices made by the algorithm

◮ the Voronoi it can be constructed in O(n log n) worst-case time ◮ remember we can go from Delaunay to Voronoi and vice versa in

O(n) time

◮ deterministic algorithm harder to implement ◮ combining with the point location data structures, proximity

queries in the plane with

  • O(log n) query time
  • O(n log n) preprocessing time
  • O(n) storage

Sergio Cabello RC – Computing Vor – Del