Computing a Delaunay triangulation - Geometric Algorithms Group

56
CS 372: Computational Geometry Lecture 12 Computing a Delaunay triangulation Antoine Vigneron King Abdullah University of Science and Technology November 12, 2012 Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 1 / 56

Transcript of Computing a Delaunay triangulation - Geometric Algorithms Group

CS 372: Computational GeometryLecture 12

Computing a Delaunay triangulation

Antoine Vigneron

King Abdullah University of Science and Technology

November 12, 2012

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 1 / 56

1 Introduction

2 New interpretation of the Delaunay triangulation

3 Edge flip

4 A first algorithm

5 Randomized incremental construction

6 Conclusion

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 2 / 56

Outline

Randomized Incremental Construction (RIC) of the Delaunaytriangulation.

Optimal: O(n log n) expected time, O(n) space.

Yields the same bounds for the Voronoi diagram.

References:

Textbook Chapter 9.

Dave Mount’s lecture notes, Lecture 18.

Demo by Jack Snoeyink.

H. Edelsbrunner’s book Geometry and topology of mesh generation,Chapter 1.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 3 / 56

InCircle Test

d

c b

a

C

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

Definition (InCircle test)

Given a counterclockwise triangle abc, with circumcircle C, the inCircletest returns a value:

inCircle(a, b, c , d) = 0 if d ∈ C,

inCircle(a, b, c , d) > 0 if d is outside C, and

inCircle(a, b, c , d) < 0 if d is inside C.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 4 / 56

Expression

We can use the following expression:

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

1 ax ay ax

2 + ay2

1 bx by bx2 + by

2

1 cx cy cx2 + cy

2

1 dx dy dx2 + dy

2

.

Why does it work?

Next 10 slides: Geometric proof.

D. Mount’s notes 18: Different proof, through algebra.

I reversed the sign of inCircle(·) compared with D. Mount’s notes, inorder to simplify the presentation.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 5 / 56

Orientation of a triple of vectors in R3

The orientation of a triple of vectors (−→u ,−→v ,−→w ) is given by the sign of:

det

ux uy uz

vx vy vzwx wy wz

.

−→vO

z

y

x

Orientation (−→u ,−→v ,−→w ) > 0

Orientation (−→v ,−→u ,−→w ) < 0

−→w

−→u

⇐ right thumb rule

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 6 / 56

Orientation of a tetrahedron

The orientation of tetrahedron abcd is the orientation of (−→ab,−→ac,

−→ad).

a

b

d

c

Orientation(abcd) =

Orientation (−→ab,−→ac ,

−→ad) > 0

⇐ right thumb rule

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 7 / 56

Orientation of a tetrahedron

Orientation(abcd) = det

bx − ax by − ay bz − azcx − ax cy − ay cz − azdx − ax dy − ay dz − az

= det

1 ax ay az0 bx − ax by − ay bz − az0 cx − ax cy − ay cz − az0 dx − ax dy − ay dz − az

(By developping with respect to first column.)

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 8 / 56

Orientation of a tetrahedron

Now we add the first row to rows 2–4.

Orientation(abcd) = det

1 ax ay az1 bx by bz

1 cx cy cz1 dx dy dz

It generalizes the 2D-counterclockwise (CCW) predicate from Lecture 2.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 9 / 56

Paraboloid P

In R3, let P be the paraboloid with equation z = x2 + y2.

O

x

y

z

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 10 / 56

Paraboloid P

Property

When H is a non-vertical plane, the projection of H ∩ P onto plane Oxy isa circle.

Proof:

H has equation z = αx + βy + γ.

The projection of H ∩ P onto plane Oxy has equationx2 + y2 = αx + βy + γ.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 11 / 56

Paraboloid P

O

x

y

z

a circle

H

P

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 12 / 56

The Lifting Map

Definition (Lifting map)

The lifting map is the vertical projection of the horizontal plane onto theparaboloid P: Any point p = (px , py ) is mapped to the pointp = (px , py , p

2x + p2

y ).

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 13 / 56

Proof for the InCircle Test Expression

O

x

y

z

ab

c

a

c

b

H

P

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 14 / 56

Proof for the InCircle Test Expression

We lift a, b, c and d :

a = (ax , ay , a2x + a2y )

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 that Orientation(a, b, c , d) = 0.

I So d ∈ H.I Thus d ∈ C.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 15 / 56

Proof: First Case

We just proved that a, b, c , d are cocircular iff a, b, c , d are coplanar.

O

x

y

z

ab

c

a

c

b

d

dH

P

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 16 / 56

Proof: Remaining 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.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 17 / 56

New Interpretation of the Delaunay Triangulation

Lifting DT (P):

x

y

zP

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 18 / 56

Circumcircle property

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

We denote P = {p1, p2, . . . pn}.Previous lecture: triangle pipjpk is a face of DT (P) iff itscircumcircle is empty.

I It means that ∀p ∈ P \ {pi , pj , pk}, p is above the plane through pi pj pk

I in other words, pi pj pk is a facet of the lower hull of P.

Theorem

DT (P) is the projection of the edges of the lower hull of P onto the planez = 0.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 19 / 56

Edge Flip

a

b

c

d

c

a

b

d

or

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 20 / 56

Edge Flip

Property

Let acbd be a quadrilateral with diagonal ab. Then either

c is inside the circumcircle of abd and d is inside the circumcircle ofabc,

or c is outside circumcircle of abd and d is outside the circumcircle ofabc.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 21 / 56

Proof(By picture.)

c

b

d

a

a

b

d

c

d

a

c

bOR

c

ad

b

Concave Convex

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 22 / 56

Edge Flip: Definition

a

b

c

d

b

c

d

a

ab is illegal cd is locally Delaunay

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 23 / 56

Definitions

Let P be a set of n points in R2. We say that P is in general position if no4 points in P are cocircular.

Let T be a triangulation of P. Let ab be an edge of T , and let c , d betwo points in P such that abc and abd are faces of T .

Definition (Locally Delaunay edge)

The edge ab is locally Delaunay iff d is outside the circumcircle of abc.

Definition (Illegal edge)

The edge ab is illegal iff d is inside the circumcircle of abc.

Note that we can decide whether ab is locally Delaunay or illegal bycomputing the sign of CCW (abc) and the sign of inCircle(a, b, c , d).

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 24 / 56

Edge Flip

If ab is illegal, we can perform an edge flip: Remove ab from T and insertcd .

c

a

d

b

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 25 / 56

Edge Flip

If ab is illegal, we can perform an edge flip: Remove ab from T and insertcd .

a

c

b

d

Now cd is locally Delaunay.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 26 / 56

Edge Flip: Interpretation

a

c c

b b

dd

a

a

b

d

c

d

a

c

b

The lifted triangulation gets lower.The upper envelope becomes convex.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 27 / 56

A First Algorithm

Theorem

Let T be a triangulation of P. Then T = DT (P) iff all the edges of T arelocally Delaunay.

Proof:

If T is Delaunay, then clearly all edges are locally Delaunay.

Other direction: Non trivial.I See textbook Theorem 9.8.I Or use the lifting map: Locally Delaunay ⇔ locally convex ⇔ globally

convex ⇔ globally Delaunay.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 28 / 56

A First Algorithm

Idea:

Start with an arbitrary triangulation T of P.

If all the edges of T are locally Delaunay, then we are done.

Otherwise, pick an illegal edge and flip it.

Repeat this process until each edge is locally Delaunay.

We will use a stack. Invariants:

All the illegal edges are in the stack.I But some locally Delaunay edges may be in the stack too.

The edges stored in the stack are marked, the others are not.I We use it to avoid having several copies of the same edge in the stack.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 29 / 56

A First Algorithm

Pseudocode

Algorithm SlowDelaunay(P)Input: a set P of n points in R2

Output: DT (P)1. Compute a triangulation T of P.2. Mark all the edges of T .3. Initialize a stack containing all the edges of T .4. while stack is non-empty5. do pop ab from stack and unmark it6. if ab is illegal then7. do flip ab to cd .8. for xy ∈ {ac, cb, bd , da}9. do if xy is not marked10. then mark xy and push it on stack.11. return T

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 30 / 56

Analysis

It is not obvious that this program halts!

But in fact, it runs in Θ(n2) time.

Proof using lifting map:I Each time we flip an edge, the lifted triangulation gets lower.I So an edge can be flipped only once: Afterward, it remains above the

lifted triangulation.I There are O(n2) possible edges.I So the algorithm runs in O(n2) time.I Lower bound left as an exercise.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 31 / 56

Randomized Incremental Construction

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 each i , we denote Pi = {p−3, p−2, p−1, p1, p2, . . . pi}.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 32 / 56

Randomized Incremental Construction

First step:

p−1

p−3 p−2

p1

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 33 / 56

Randomized Incremental Construction

First step:

p−1

p−3 p−2

p1

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 34 / 56

Randomized Incremental Construction

Idea:

Insert p1, then p2 . . . and finally pn.

Suppose we have computed DT (Pi−1).

Insert pi ⇒ splits a triangle into threeI Find this triangle using conflict lists.

F Each non inserted point has a pointer to the triangle in DT (Pi−1) thatcontains it.

F Each triangle in DT (Pi−1) is associated with the list of all thenon-inserted points that it contains.

Perform edge flips until no illegal edge remains.I We only need to perform flips around pi .I On average, this step takes constant time.

We have just computed DT (Pi ).

Repeat the process until i = n.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 35 / 56

Example

p

Inserting pi .

To alleviate notation, we denote p = pi .

We do not draw p−1p−2p−3.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 36 / 56

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.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 37 / 56

Example

p

a

b

c

Edge ab is illegal.

Flip it.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 38 / 56

Example

p

a

b

c

d

Edge ab has been flipped into pd .

ad is locally Delaunay, we keep it.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 39 / 56

Example

p

a

b

c

d

Edge bd is illegal.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 40 / 56

Example

p

a

b

c

d

e

Edge bd has been flipped into pe.

Edges de and be are locally Delaunay, we keep them

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 41 / 56

Example

p

a

b

c

d

e

Edge bc is illegal.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 42 / 56

Example

a

b

c

d

e

pf

Edge bc has been flipped into pf .

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 43 / 56

Example

b

c

d

e

pf

a

Edge ac is illegal.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 44 / 56

Example

b

c

d

e

pf

a

g

Edge ag is locally Delaunay.

No more edge to flip: We are done.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 45 / 56

Explanation

We considered triangles in counterclockwise order around p andflipped illegal edges.

Why is it enough to consider only triangles adjacent to p? See prooflater.

The pseudocode for this algorithm is very simple: See next slide.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 46 / 56

Randomized Incremental Construction

RIC 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) 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).

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 47 / 56

Randomized Incremental Construction

RIC Pseudocode

Algorithm SwapTest(ab)1. if ab is an edge of the exterior face.2. do return3. d ←the vertex on the other side of ab.4. if inCircle(p, a, b, d) < 05. do Flip edge ab for pd .(∗ it includes conflict lists update ∗)6. SwapTest(ad).7. SwapTest(db).

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 48 / 56

Proof of Correctness

We only flipped edges of triangles that contain p.

Why is it sufficient?

Remember the theorem: locally Delaunay implies (globally) Delaunay.

Any edge between two triangles that do not contain p was locallyDelaunay before insertion of p.

So it is still locally Delaunay.

Thus the triangulation we obtain is the Delaunay triangulation.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 49 / 56

Analysis

Consider the time ti taken to update the current triangulation whileinserting pi .

It does not account for conflict lists updates.

Each new edge (obtained by splitting abc or a flip) is incident to pi .

So ti is proportional to the degree of pi in DT (Pi ).

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 50 / 56

Analysis

We use backward analysis: Pi is fixed, pi is random.

Each edge has two endpoints.

So each edge is incident to pi with probability 2i .

There are O(i) edges in the whole triangulation.

So by backward analysis

E [ti ] =O(i)

i= O(1).

Thus the time for updating the triangulation is O(n) during the wholeconstruction of DT (P).

Similar with trapezoidal map: It takes Θ(n log n) time to update theconflict lists. (See next slide).

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 51 / 56

Analysis

While inserting pi , what is the probability that p ∈ P \ Pi isrebucketted?

Backward analysis:I It is the probability that pi ∈ {a, b, c}, when abc is the triangle ofDT (Pi ) that contains p.

I So this probability is 3/i .

So while inserting pi , we rebucket less than 3n/i sites on average.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 52 / 56

Analysis

Problem: a site may be rebucketted several times at step i .I Intuition: Only a constant number of flips at each step so it only

accounts for a constant factor.I Detailed proof in textbook.

So overall, rebucketting takes expected time

O

(n∑

i=1

n

i

)= O(n log n).

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 53 / 56

Choice of p−1p−2p−3

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

p−2(3M, 0)

P

p−1(0, 3M)

(M,M)

M: Maximum of any coordinate of any point in P.

For incircle test, do as if these three points are outside any circledefined by three points in P.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 54 / 56

Concluding Remarks

The Delaunay triangulation of n points can be computed in expectedtime O(n log n).

It holds for worst case input, the expectation is over the randomchoices 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 Voronoidiagram of P in O(n) time.

I Left as an exercise.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 55 / 56

Concluding Remarks

Combined with the point location data structure of Lecture 9, we cananswer proximity queries in the plane (see Lecture 11) in

I O(log n) expected query time,I O(n log n) expected preprocessing time, andI O(n) expected space usage.

All these bounds can be made deterministic.I Harder, less practical.

Antoine Vigneron (KAUST) CS 372 Lecture 12 November 12, 2012 56 / 56