61
Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 Antoine Vigneron [email protected] National University of Singapore NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.1/61

Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

  • Upload
    vannhi

  • View
    215

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Computing a Delaunay triangulationLecture 10, CS 4235

18 march 2004

Antoine Vigneron

[email protected]

National University of Singapore

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.1/61

Page 2: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Outline

• RIC of the Delaunay triangulation• optimal O(n log n) time randomized algorithm• application: computing a Voronoi diagram• references• D. Mount Lecture 18• textbook chapter 9• H. Edelsbrunner’s book: Geometry and topology of

mesh generation, chapter 1• demo (J. Snoeyink) at:

http://www.cs.ubc.ca/spider/snoeyink/demos/crust/home.html

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.2/61

Page 3: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Incircle test

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.3/61

Page 4: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Definition

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

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.4/61

Page 5: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Expression

• we use the following expression:

inCircle(a, b, c, d) = det

1 ax ay ax2 + ay

2

1 bx by bx2 + by

2

1 cx cy cx2 + cy

2

1 dx dy dx2 + dy

2

• why does it work?• next ten slides: proof with geometric interpretation• D. Mount’s notes 18: different proof, through algebra• be careful: we reversed the sign of inCircle(·) with

respect to D. Mount’s notes, in order to simplify thefollowing proof.

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.5/61

Page 6: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Orientation of vectors in IR3

• 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

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.6/61

Page 7: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

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

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.7/61

Page 8: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

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

0 bx − ax by − ay bz − az

0 cx − ax cy − ay cz − az

0 dx − ax dy − ay dz − az

• why?• Develop with respect to first column

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.8/61

Page 9: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

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 counterclockwise (CCW)predicate in IR2 (see lecture 1)

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.9/61

Page 10: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Paraboloid P

• in IR3, let P be the paraboloid with equation z = x2 + y2

O

x

y

z

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.10/61

Page 11: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Property

• let H be a non–vertical plane• H has equation z = αx + βy + γ

• the projection of H ∩ P onto plane Oxy has equationx2 + y2 = αx + βy + γ• this is a circle

• property: the projection of H ∩ P onto plane Oxy is acircle

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.11/61

Page 12: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Property

O

x

y

z

a circle

H

P

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.12/61

Page 13: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Proof

O

x

y

z

ab

c

a

c

b

H

P

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.13/61

Page 14: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Proof

• let p = (px, py)

• we lift p onto P and obtain p = (px, py, p2x + p2

y)

• the transformation p→ p is called the lifting map

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.14/61

Page 15: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Proof

• we lift a, b, c and d:

a = (ax, ay, a2x + a2

y)

b = (bx, by, b2x + b2

y)

c = (cx, cy, c2x + c2

y)

d = (dx, dy, d2x + d2

y)

• we denote by H the plane through {a, b, c}

• inCircle(a, b, c, d) = 0 means thatOrientation(a, b, c, d) = 0

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

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.15/61

Page 16: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Proof: first case

• a, b, c, d cocircular if a, b, c, d coplanar

O

x

y

z

ab

c

a

c

b

d

dH

P

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.16/61

Page 17: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

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

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.17/61

Page 18: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

New interpretation of the Delaunaytriangulation

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.18/61

Page 19: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Lifting DT (P )

x

y

zP

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.19/61

Page 20: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Circumcircle property

• P = {p1, p2, . . . pn} is a set of points in the plane ingeneral position

• we denote P = {p1, p2, . . . pn}

• last lecture: triangle pipjpk is a face of DT (P ) iff itscircumcircle is empty• it means that ∀p ∈ P \ {pi, pj , pk}, p is above the

plane through pipj pk

• in other words, pipj pk is a facet of the lower hull of P

• Theorem: DT (P ) is the projection of the edges of thelower hull of P onto the plane z = 0

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.20/61

Page 21: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Edge flip

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.21/61

Page 22: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Property

a

b

c

d

c

a

b

d

or

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.22/61

Page 23: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Property

• let acbd be a 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

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.23/61

Page 24: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Proof (by picture)

c

b

d

a

a

b

d

c

d

a

c

bOR

c

ad

b

Concave Convex

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.24/61

Page 25: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Edge flip: definition

a

b

c

d

b

c

d

a

ab is illegal cd is locally Delaunay

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.25/61

Page 26: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Definitions

• let P be a set of n points in IR2

• P is in general position: no 4 points are cocircular• let T be a triangulation of P

• let ab be an edge of T

• let (c, d) ∈ P 2 such that abc and abd are triangles of T• ab is locally Delaunay iff d is outside the circumcircle of

abc

• ab is illegal iff d is inside the circumcircle of abc

• note that we can decide whether ab is locally Delaunayor illegal by computing the sign of CCW (abc) and thesign of inCircle(a, b, c, d)

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.26/61

Page 27: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

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

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.27/61

Page 28: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

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

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.28/61

Page 29: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Edge flip: interpretation

a

c c

b b

dd

a

a

b

d

c

d

a

c

b

the lifted triangulation gets lowerthe upper envelope becomes convex

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.29/61

Page 30: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

A first algorithm

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.30/61

Page 31: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Theorem

• let T be a triangulation of P

• T = DT (P ) iff all the edges of T are locally Delaunay• proof:• if T is Delaunay, then clearly all edges are locally

Delaunay (by definition)• other direction: non trivial• see textbook Theorem 9.8• or use the lifting map: locally Delaunay⇔ locally

convex⇔ globally convex⇔ globally Delaunay

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.31/61

Page 32: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

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

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.32/61

Page 33: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Pseudocode

Algorithm SlowDelaunay (P)

Input: a set P of n points in IR2

Output: DT (P )1. compute a triangulation T of P2. initialize a stack containing all the edges of T3. while stack is non–empty4. do pop ab from stack and unmark it5. if ab is illegal then6. do flip ab to cd7. for xy ∈ {ac, cb, bd, da}8. do if xy is not marked9. then mark xy and push it on

stack10. return T

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.33/61

Page 34: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

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• lower bound left as an exercise

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.34/61

Page 35: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Randomized incremental algorithm

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.35/61

Page 36: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

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}

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.36/61

Page 37: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

First step

p−1

p−3 p

−2

p1

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.37/61

Page 38: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

First step

p−1

p−3 p

−2

p1

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.38/61

Page 39: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

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 = nNUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.39/61

Page 40: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Example

p

• inserting pi

• to simplify the notations, we denote p = pi

• we do not draw p−1p−2p−3

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.40/61

Page 41: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

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 accordinglyNUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.41/61

Page 42: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Example

p

a

b

c

• edge ab is illegal• flip it

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.42/61

Page 43: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Example

p

a

b

c

d

• edge ab has been flipped into pd

• ad is locally Delaunay, we keep it

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.43/61

Page 44: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Example

p

a

b

c

d

• edge bd is illegal

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.44/61

Page 45: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Example

p

a

b

c

d

e

• edge bd has been flipped into pe

• edges de and be are locally Delaunay, we keep them

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.45/61

Page 46: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Example

p

a

b

c

d

e

• edge bc is illegal

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.46/61

Page 47: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Example

a

b

c

d

e

pf

• edge bc has been flipped into pf

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.47/61

Page 48: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Example

b

c

d

e

pf

a

• edge ac is illegal

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.48/61

Page 49: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Example

b

c

d

e

pf

a

g

• edge ag is locally Delaunay• no more edge to flip: we are done

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.49/61

Page 50: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Explanation

• we considered triangles in counterclockwise orderaround p and flipped illegal edges

• why is it enough to consider only triangles adjacent top?

• see proof later• the pseudocode for this algorithm is very simple• see next slide

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.50/61

Page 51: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

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)

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.51/61

Page 52: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Pseudocode

Algorithm SwapTest(ab)1. if ab is an edge of the exterior face2. do return3. d←the vertex to the right of edge ab4. if inCircle(p, a, b, d) < 05. do Flip edge ab for pd(∗ it includes conflict lists update ∗)6. SwapTest(ad)7. SwapTest(db)

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.52/61

Page 53: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Proof

• we only flipped edges of triangles that contain p

• why is it sufficient?• remember Theorem slide 26: 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

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.53/61

Page 54: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Analysis

• we look at ti: time taken to update the currenttriangulation 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

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.54/61

Page 55: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

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 Eulerformula)

• so by backward analysis

E[ti] =O(i)

i= O(1)

• so the time for updating the triangulation is O(n) overthe course of the whole algorithm

• similar with trapezoidal map: what takes Θ(n log n) timeis the update of conflict lists (see next slide)

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.55/61

Page 56: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

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 onaverage

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.56/61

Page 57: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Analysis

• problem: a site may be rebucketed several times at stepi• intuition: only a constant number of flips at each step

so it only account for a constant factor• detailed proof in textbook

• so overall, rebucketing takes expected time

O

(

n∑

i=1

n

i

)

= O(n log n)

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.57/61

Page 58: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Choice of p−1p−2p−3

p−3(−3M,−3M)

p−2(3M, 0)

P

p−1(0, 3M)

(M, M)

• M : max of any coordinate of any point in P

• For incircle test, do as if these three points are outsideany circle defined by three points in P

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.58/61

Page 59: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Conclusion

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.59/61

Page 60: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Conclusion

• the Delaunay triangulation of n points can be computedin expected time O(n log n)

• it holds for worst case input, the expectation is over therandom choices made by the algorithm

• it can also be done in O(n log n) deterministic time• knowing the Delaunay triangulation of P , we can find

the Voronoi diagram of P in O(n) time• left as an exercise

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.60/61

Page 61: Lecture 10, CS 4235 18 march 2004 - NUS Computingtantc/ioi_training/CG/l10cs4235.pdf · Computing a Delaunay triangulation Lecture 10, CS 4235 18 march 2004 ... next ten slides:

Conclusion

• combining with the point location data structure oflecture 8, we can answer proximity queries in the plane(see lecture 9) with• O(log n) expected query time• O(n log n) expected preprocessing time• O(n) expected space usage

• all these bounds can be made deterministic• harder, less practical

NUS – CS4235 – Lecture 10: Computing a Delaunay triangulation – p.61/61