132
1-1 Computational Geometry Lecture #1 Convex Hull or Mixing Things Dr. Philipp Kindermann Winter Semester 2018

Computational Geometry - uni-wuerzburg.de

  • Upload
    others

  • View
    11

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Computational Geometry - uni-wuerzburg.de

1 - 1

Computational Geometry

Lecture #1

Convex Hullor

Mixing Things

Dr. Philipp Kindermann Winter Semester 2018

Page 2: Computational Geometry - uni-wuerzburg.de

1 - 2

Computational Geometry

Lecture #1

Convex Hullor

Mixing Things

Dr. Philipp Kindermann Winter Semester 2018

Page 3: Computational Geometry - uni-wuerzburg.de

2 - 1

Chair I

a) Efficient Algorithms

b) Knowledge-Based SystemsProf. Dietmar Seipel

c) Theoretical Comp. ScienceProf. Christian Glaßer

Page 4: Computational Geometry - uni-wuerzburg.de

2 - 2

Chair I

a) Efficient Algorithms

b) Knowledge-Based SystemsProf. Dietmar Seipel

Alexander Wolff Philipp Kindermann

Thomas van Dijk

Steven Chaplick

c) Theoretical Comp. ScienceProf. Christian Glaßer

Professor PostDoc

PostDocMyroslav Kryven

Oksana Firman

Johannes ZinkAndre Loffler

PostDoc

Page 5: Computational Geometry - uni-wuerzburg.de

3 - 1

Philipp [email protected]:

Page 6: Computational Geometry - uni-wuerzburg.de

3 - 2

Philipp [email protected]:

Wurzburg 2006 – 2011: Study

Page 7: Computational Geometry - uni-wuerzburg.de

3 - 3

Philipp [email protected]:

Wurzburg 2006 – 2011: Study2011 – 2015: PhD

Page 8: Computational Geometry - uni-wuerzburg.de

3 - 4

Philipp [email protected]:

Wurzburg

Hagen

2006 – 2011: Study2011 – 2015: PhD

2015 – 2018:PostDoc

Page 9: Computational Geometry - uni-wuerzburg.de

3 - 5

Philipp [email protected]:

Wurzburg

Hagen

2006 – 2011: Study2011 – 2015: PhD

2015 – 2018:PostDoc

Page 10: Computational Geometry - uni-wuerzburg.de

3 - 6

Philipp [email protected]:

Waterloo

Page 11: Computational Geometry - uni-wuerzburg.de

3 - 7

Philipp [email protected]:

Waterloo

Page 12: Computational Geometry - uni-wuerzburg.de

3 - 8

Philipp [email protected]:

Office hours: Wed, 14–15h

Page 13: Computational Geometry - uni-wuerzburg.de

3 - 9

Philipp [email protected]

Office:

Email:

E14 @ Former Math Build. (M8)Office hours: Wed, 14–15h

Page 14: Computational Geometry - uni-wuerzburg.de

3 - 10

Philipp [email protected]

Office:

Email:

E14 @ Former Math Build. (M8)Office hours: Wed, 14–15h

Page 15: Computational Geometry - uni-wuerzburg.de

3 - 11

Philipp [email protected]

Office:

Email:

E14 @ Former Math Build. (M8)Office hours: Wed, 14–15h

Research areas:

– Comp. Geometry– Graph Algorithms– Graph Visualization

Page 16: Computational Geometry - uni-wuerzburg.de

4 - 1

Computational GeometryLearning goals: At the end of this lecture you will be able to

Page 17: Computational Geometry - uni-wuerzburg.de

4 - 2

Computational GeometryLearning goals:

– decide which algorithms help to solve a number offundamental geometric problems,

At the end of this lecture you will be able to

Page 18: Computational Geometry - uni-wuerzburg.de

4 - 3

Computational GeometryLearning goals:

– decide which algorithms help to solve a number offundamental geometric problems,

At the end of this lecture you will be able to

– analyze new problems and find – with the concepts ofthe lecture – efficient solutions.

Page 19: Computational Geometry - uni-wuerzburg.de

4 - 4

Computational GeometryLearning goals:

– decide which algorithms help to solve a number offundamental geometric problems,

Requirements:

At the end of this lecture you will be able to

– analyze new problems and find – with the concepts ofthe lecture – efficient solutions.

– Big-Oh notation (Landau); e.g., O(n log n)

Page 20: Computational Geometry - uni-wuerzburg.de

4 - 5

Computational GeometryLearning goals:

– decide which algorithms help to solve a number offundamental geometric problems,

Requirements:

At the end of this lecture you will be able to

– analyze new problems and find – with the concepts ofthe lecture – efficient solutions.

– Some basic Algorithms & Data Structures– Big-Oh notation (Landau); e.g., O(n log n)

(Balanced) binary search tree, priority queue

Page 21: Computational Geometry - uni-wuerzburg.de

4 - 6

Computational GeometryLearning goals:

– decide which algorithms help to solve a number offundamental geometric problems,

Requirements:

At the end of this lecture you will be able to

– analyze new problems and find – with the concepts ofthe lecture – efficient solutions.

– Some basic Algorithms & Data Structures

– Some basic Algorithmic Graph Theory

– Big-Oh notation (Landau); e.g., O(n log n)

(Balanced) binary search tree, priority queue

Breadth-first search, Dijkstra’s algorithm

Page 22: Computational Geometry - uni-wuerzburg.de

4 - 7

Computational GeometryLearning goals:

– decide which algorithms help to solve a number offundamental geometric problems,

Requirements:

At the end of this lecture you will be able to

– analyze new problems and find – with the concepts ofthe lecture – efficient solutions.

– Some basic Algorithms & Data Structures

– Some basic Algorithmic Graph Theory

– Oral exam at the end of the semester

– Big-Oh notation (Landau); e.g., O(n log n)

(Balanced) binary search tree, priority queue

Breadth-first search, Dijkstra’s algorithm

Page 23: Computational Geometry - uni-wuerzburg.de

4 - 8

Computational GeometryLearning goals:

– decide which algorithms help to solve a number offundamental geometric problems,

Requirements:

My vision: • “hands-on”• interactive

At the end of this lecture you will be able to

– analyze new problems and find – with the concepts ofthe lecture – efficient solutions.

– Some basic Algorithms & Data Structures

– Some basic Algorithmic Graph Theory

– Oral exam at the end of the semester

– Big-Oh notation (Landau); e.g., O(n log n)

(Balanced) binary search tree, priority queue

Breadth-first search, Dijkstra’s algorithm

Page 24: Computational Geometry - uni-wuerzburg.de

5

Content1. Convex Hull in 2D2. Map Overlay3. Polygon Triangulation4. Linear Programming5. Orthogonal Range Queries6. Point Location7. Voronoi Diagram8. Delaunay Triangulation9. Convex Hull in 3D

10. Motion Planning11. Simplex Range Searching12. Arrangements and Duality13. Binary Space Partition14. Randomized Triangulation

Page 25: Computational Geometry - uni-wuerzburg.de

6 - 1

LiteratureM. de Berg, O. Cheong, M. van Kreveld, M. Overmars:Computational Geometry: Algorithms & Applications.Springer, 3rd edition, 2008

Main resource for this course!Abbreviated as: Comp. Geom A&A

Page 26: Computational Geometry - uni-wuerzburg.de

6 - 2

Literature

Rolf Klein:Algorithmische Geometrie: Grundlagen, Methoden,Anwendungen.Springer, 2nd edition, 2005

M. de Berg, O. Cheong, M. van Kreveld, M. Overmars:Computational Geometry: Algorithms & Applications.Springer, 3rd edition, 2008

Main resource for this course!Abbreviated as: Comp. Geom A&A

Page 27: Computational Geometry - uni-wuerzburg.de

6 - 3

Literature

Rolf Klein:Algorithmische Geometrie: Grundlagen, Methoden,Anwendungen.Springer, 2nd edition, 2005

M. de Berg, O. Cheong, M. van Kreveld, M. Overmars:Computational Geometry: Algorithms & Applications.Springer, 3rd edition, 2008

Ketan Mulmuley:Computational Geometry: An Introduction ThroughRandomized Algorithms. Prentice Hall, 1st edition, 1993

Main resource for this course!Abbreviated as: Comp. Geom A&A

Page 28: Computational Geometry - uni-wuerzburg.de

7

Week 1

Mixing Thingsor

Convex Hull

[Comp. Geom A&A : Chapter 1, (see also Ch. 11)]

Page 29: Computational Geometry - uni-wuerzburg.de

8 - 1

Mixing Things

subst. fract. A fract. Bs1 10 % 35 %s2 20 % 5 %s3 40 % 25 %

Given...

Page 30: Computational Geometry - uni-wuerzburg.de

8 - 2

Mixing Things

subst. fract. A fract. Bs1 10 % 35 %s2 20 % 5 %s3 40 % 25 %

Given...

subst. fract. A fract. Bq1 25 % 28 %q2 15 % 15 %

can we mix

?using s1, s2, s3

Page 31: Computational Geometry - uni-wuerzburg.de

8 - 3

Mixing Things

.1 .2 .3 .4

subst. fract. A fract. Bs1 10 % 35 %s2 20 % 5 %s3 40 % 25 %

.4

.3

.2

.1

B

A

s1

s2

s3

Given...

subst. fract. A fract. Bq1 25 % 28 %q2 15 % 15 %

can we mix

?using s1, s2, s3

Page 32: Computational Geometry - uni-wuerzburg.de

8 - 4

Mixing Things

.1 .2 .3 .4

subst. fract. A fract. Bs1 10 % 35 %s2 20 % 5 %s3 40 % 25 %

.4

.3

.2

.1

B

A

s1

s2

s3

Given...

subst. fract. A fract. Bq1 25 % 28 %q2 15 % 15 %

can we mix

q1

q2

?using s1, s2, s3

Page 33: Computational Geometry - uni-wuerzburg.de

8 - 5

Mixing Things

.1 .2 .3 .4

subst. fract. A fract. Bs1 10 % 35 %s2 20 % 5 %s3 40 % 25 %

.4

.3

.2

.1

B

A

s1

s2

s3

Given...

subst. fract. A fract. Bq1 25 % 28 %q2 15 % 15 %

can we mix

q1

q2

?using s1, s2, s3

Page 34: Computational Geometry - uni-wuerzburg.de

8 - 6

Mixing Things

.1 .2 .3 .4

subst. fract. A fract. Bs1 10 % 35 %s2 20 % 5 %s3 40 % 25 %

.4

.3

.2

.1

B

A

s1

s2

s3

Given...

subst. fract. A fract. Bq1 25 % 28 %q2 15 % 15 %

can we mix

q1

q2

?using s1, s2, s3

Observe: Given a set S ⊂ R2 of substances, we can mix asubstance q ∈ R2 using the substances in S ⇔

Page 35: Computational Geometry - uni-wuerzburg.de

8 - 7

Mixing Things

.1 .2 .3 .4

subst. fract. A fract. Bs1 10 % 35 %s2 20 % 5 %s3 40 % 25 %

.4

.3

.2

.1

B

A

s1

s2

s3

Given...

subst. fract. A fract. Bq1 25 % 28 %q2 15 % 15 %

can we mix

q1

q2

?using s1, s2, s3

Observe: Given a set S ⊂ R2 of substances, we can mix asubstance q ∈ R2 using the substances in S ⇔q ∈ CH(S).

Page 36: Computational Geometry - uni-wuerzburg.de

8 - 8

Mixing Things

.1 .2 .3 .4

subst. fract. A fract. Bs1 10 % 35 %s2 20 % 5 %s3 40 % 25 %

.4

.3

.2

.1

B

A

s1

s2

s3

Given...

subst. fract. A fract. Bq1 25 % 28 %q2 15 % 15 %

can we mix

q1

q2

?using s1, s2, s3

Observe: Given a set S ⊂ R2 of substances, we can mix asubstance q ∈ R2 using the substances in S ⇔q ∈ CH(S).

s4

Page 37: Computational Geometry - uni-wuerzburg.de

8 - 9

Mixing Things

.1 .2 .3 .4

subst. fract. A fract. Bs1 10 % 35 %s2 20 % 5 %s3 40 % 25 %

.4

.3

.2

.1

B

A

s1

s2

s3

Given...

subst. fract. A fract. Bq1 25 % 28 %q2 15 % 15 %

can we mix

q1

q2

?using s1, s2, s3

Observe: Given a set S ⊂ R2 of substances, we can mix asubstance q ∈ R2 using the substances in S ⇔q ∈ CH(S).

s4

s5

Page 38: Computational Geometry - uni-wuerzburg.de

8 - 10

Mixing Things

.1 .2 .3 .4

subst. fract. A fract. Bs1 10 % 35 %s2 20 % 5 %s3 40 % 25 %

.4

.3

.2

.1

B

A

s1

s2

s3

Given...

subst. fract. A fract. Bq1 25 % 28 %q2 15 % 15 %

can we mix

q1

q2

?using s1, s2, s3

Observe: Given a set S ⊂ R2 of substances, we can mix asubstance q ∈ R2 using the substances in S ⇔q ∈ CH(S).

d

d

s4

s5

Page 39: Computational Geometry - uni-wuerzburg.de

9 - 1

Formally. . .

Given S ⊂ R2, how do we define the convex hull CH(S)?

Page 40: Computational Geometry - uni-wuerzburg.de

9 - 2

Formally. . .

Given S ⊂ R2, how do we define the convex hull CH(S)?

Physics approach:

Page 41: Computational Geometry - uni-wuerzburg.de

9 - 3

Formally. . .

Given S ⊂ R2, how do we define the convex hull CH(S)?

Physics approach: – take (large enough) elastic rope

Page 42: Computational Geometry - uni-wuerzburg.de

9 - 4

Formally. . .

Given S ⊂ R2, how do we define the convex hull CH(S)?

Physics approach: – take (large enough) elastic rope– stretch and let go

Page 43: Computational Geometry - uni-wuerzburg.de

9 - 5

Formally. . .

Given S ⊂ R2, how do we define the convex hull CH(S)?

Physics approach: – take (large enough) elastic rope– stretch and let go

Page 44: Computational Geometry - uni-wuerzburg.de

9 - 6

Formally. . .

Given S ⊂ R2, how do we define the convex hull CH(S)?

Physics approach: – take (large enough) elastic rope– stretch and let go– take area inside (and on) the rope

Page 45: Computational Geometry - uni-wuerzburg.de

9 - 7

Formally. . .

Given S ⊂ R2, how do we define the convex hull CH(S)?

Physics approach: – take (large enough) elastic rope– stretch and let go– take area inside (and on) the rope

Page 46: Computational Geometry - uni-wuerzburg.de

9 - 8

Formally. . .

Given S ⊂ R2, how do we define the convex hull CH(S)?

Physics approach: – take (large enough) elastic rope– stretch and let go– take area inside (and on) the rope

Math approach:

Page 47: Computational Geometry - uni-wuerzburg.de

9 - 9

Formally. . .

Given S ⊂ R2, how do we define the convex hull CH(S)?

Physics approach: – take (large enough) elastic rope– stretch and let go– take area inside (and on) the rope

Math approach: – define convex

Page 48: Computational Geometry - uni-wuerzburg.de

9 - 10

Formally. . .

Given S ⊂ R2, how do we define the convex hull CH(S)?

Physics approach: – take (large enough) elastic rope– stretch and let go– take area inside (and on) the rope

Math approach: – define convex– define CH(S) =

⋂C⊇S : C convex

C

Page 49: Computational Geometry - uni-wuerzburg.de

10 - 1

Towards Computation

Problem with math approach:

CH(S) =def⋂

C⊇S : C convex

C

Page 50: Computational Geometry - uni-wuerzburg.de

10 - 2

Towards Computation

Problem with math approach:

CH(S) =def⋂

C⊇S : C convex

C

This set is HUGE!

Page 51: Computational Geometry - uni-wuerzburg.de

10 - 3

Towards Computation

Problem with math approach:

CH(S) =def⋂

C⊇S : C convex

C

This set is HUGE!

Maybe we can do with a little less?

Page 52: Computational Geometry - uni-wuerzburg.de

10 - 4

Towards Computation

Problem with math approach:

CH(S) =def⋂

C⊇S : C convex

C

This set is HUGE!

Maybe we can do with a little less?

Claim: CH(S) =

Page 53: Computational Geometry - uni-wuerzburg.de

10 - 5

Towards Computation

Problem with math approach:

CH(S) =def⋂

C⊇S : C convex

C

This set is HUGE!

Maybe we can do with a little less?

Claim: CH(S) =⋂

H⊇S :

H

H closed halfplane

Page 54: Computational Geometry - uni-wuerzburg.de

10 - 6

Towards Computation

Problem with math approach:

CH(S) =def⋂

C⊇S : C convex

C

This set is HUGE!

Maybe we can do with a little less?

Claim: CH(S) =⋂

H⊇S :

H =

H closed halfplane

Page 55: Computational Geometry - uni-wuerzburg.de

10 - 7

Towards Computation

Problem with math approach:

CH(S) =def⋂

C⊇S : C convex

C

This set is HUGE!

Maybe we can do with a little less?

Claim: CH(S) =⋂

H⊇S :

H =⋂

H⊇S : H cl. halfplane,

H

|∂H ∩ S| ≥ 2H closed halfplane

Page 56: Computational Geometry - uni-wuerzburg.de

11 - 1

Computer Science ApproachInput: set S of n points in the plane, that is, S ⊂ R2

Page 57: Computational Geometry - uni-wuerzburg.de

11 - 2

Computer Science ApproachInput: set S of n points in the plane, that is, S ⊂ R2

Page 58: Computational Geometry - uni-wuerzburg.de

11 - 3

Computer Science ApproachInput: set S of n points in the plane, that is, S ⊂ R2

Page 59: Computational Geometry - uni-wuerzburg.de

11 - 4

Computer Science ApproachInput:

Output:

set S of n points in the plane, that is, S ⊂ R2

list of vertices of CH(S) in clockwise order

Page 60: Computational Geometry - uni-wuerzburg.de

11 - 5

Computer Science ApproachInput:

Output:

set S of n points in the plane, that is, S ⊂ R2

list of vertices of CH(S) in clockwise order

Observation. (p, q) is an edge of CH(S) ⇔

p q

Page 61: Computational Geometry - uni-wuerzburg.de

11 - 6

Computer Science ApproachInput:

Output:

set S of n points in the plane, that is, S ⊂ R2

list of vertices of CH(S) in clockwise order

Observation. (p, q) is an edge of CH(S) ⇔each point in S lies– strictly to the right of the directed line −→pq or– on the line segment pq

p q−→pq

Page 62: Computational Geometry - uni-wuerzburg.de

12 - 1

Finally, an Algorithm

FirstConvexHull(S)E← ∅foreach (p, q) ∈ S× S with p 6= q do

valid← trueforeach r ∈ S do

if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

if valid thenE← E ∪ {(p, q)}

from E construct sorted list L of vertices of CH(S)return L

Page 63: Computational Geometry - uni-wuerzburg.de

12 - 2

Finally, an Algorithm

FirstConvexHull(S)E← ∅foreach (p, q) ∈ S× S with p 6= q do

valid← trueforeach r ∈ S do

if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

if valid thenE← E ∪ {(p, q)}

from E construct sorted list L of vertices of CH(S)return L

// test: (p, q) edge of CH(S)?

Page 64: Computational Geometry - uni-wuerzburg.de

12 - 3

Finally, an Algorithm

FirstConvexHull(S)E← ∅foreach (p, q) ∈ S× S with p 6= q do

valid← trueforeach r ∈ S do

if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

if valid thenE← E ∪ {(p, q)}

from E construct sorted list L of vertices of CH(S)return L

// test: (p, q) edge of CH(S)?

Page 65: Computational Geometry - uni-wuerzburg.de

12 - 4

Finally, an Algorithm

FirstConvexHull(S)E← ∅foreach (p, q) ∈ S× S with p 6= q do

valid← trueforeach r ∈ S do

if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

if valid thenE← E ∪ {(p, q)}

from E construct sorted list L of vertices of CH(S)return L

r strictly right of −→pqm∣∣∣∣∣∣

xr yr 1xp yp 1xq yq 1

∣∣∣∣∣∣ < 0

Page 66: Computational Geometry - uni-wuerzburg.de

12 - 5

Finally, an Algorithm

FirstConvexHull(S)E← ∅foreach (p, q) ∈ S× S with p 6= q do

valid← trueforeach r ∈ S do

if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

if valid thenE← E ∪ {(p, q)}

from E construct sorted list L of vertices of CH(S)return L

r strictly right of −→pqm∣∣∣∣∣∣

xr yr 1xp yp 1xq yq 1

∣∣∣∣∣∣ < 0

Important:Test takes O(1) time!

Page 67: Computational Geometry - uni-wuerzburg.de

12 - 6

Finally, an Algorithm

FirstConvexHull(S)E← ∅foreach (p, q) ∈ S× S with p 6= q do

valid← trueforeach r ∈ S do

if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

if valid thenE← E ∪ {(p, q)}

from E construct sorted list L of vertices of CH(S)return L

r strictly right of −→pqm∣∣∣∣∣∣

xr yr 1xp yp 1xq yq 1

∣∣∣∣∣∣ < 0

Important:Test takes O(1) time!

Page 68: Computational Geometry - uni-wuerzburg.de

12 - 7

Finally, an Algorithm

FirstConvexHull(S)E← ∅foreach (p, q) ∈ S× S with p 6= q do

valid← trueforeach r ∈ S do

if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

if valid thenE← E ∪ {(p, q)}

from E construct sorted list L of vertices of CH(S)return L

r strictly right of −→pqm∣∣∣∣∣∣

xr yr 1xp yp 1xq yq 1

∣∣∣∣∣∣ < 0

Important:Test takes O(1) time!

Page 69: Computational Geometry - uni-wuerzburg.de

12 - 8

Finally, an Algorithm

FirstConvexHull(S)E← ∅foreach (p, q) ∈ S× S with p 6= q do

valid← trueforeach r ∈ S do

if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

if valid thenE← E ∪ {(p, q)}

from E construct sorted list L of vertices of CH(S)return L

r strictly right of −→pqm∣∣∣∣∣∣

xr yr 1xp yp 1xq yq 1

∣∣∣∣∣∣ < 0

Important:Test takes O(1) time!

Page 70: Computational Geometry - uni-wuerzburg.de

12 - 9

Finally, an Algorithm

FirstConvexHull(S)E← ∅foreach (p, q) ∈ S× S with p 6= q do

valid← trueforeach r ∈ S do

if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

if valid thenE← E ∪ {(p, q)}

from E construct sorted list L of vertices of CH(S)return L

r strictly right of −→pqm∣∣∣∣∣∣

xr yr 1xp yp 1xq yq 1

∣∣∣∣∣∣ < 0

Important:Test takes O(1) time!

Page 71: Computational Geometry - uni-wuerzburg.de

12 - 10

Finally, an Algorithm

FirstConvexHull(S)E← ∅foreach (p, q) ∈ S× S with p 6= q do

valid← trueforeach r ∈ S do

if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

if valid thenE← E ∪ {(p, q)}

from E construct sorted list L of vertices of CH(S)return L

r strictly right of −→pqm∣∣∣∣∣∣

xr yr 1xp yp 1xq yq 1

∣∣∣∣∣∣ < 0

Important:Test takes O(1) time!

Page 72: Computational Geometry - uni-wuerzburg.de

13 - 1

Running Time Analysis

FirstConvexHull(S)E← ∅foreach (p, q) ∈ S× S with p 6= q do

valid← trueforeach r ∈ S do

if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

if valid thenE← E ∪ {(p, q)}

from E construct sorted list L of vertices of CH(S)return L

Page 73: Computational Geometry - uni-wuerzburg.de

13 - 2

Running Time Analysis

FirstConvexHull(S)E← ∅foreach (p, q) ∈ S× S with p 6= q do

valid← trueforeach r ∈ S do

if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

if valid thenE← E ∪ {(p, q)}

from E construct sorted list L of vertices of CH(S)return L

Page 74: Computational Geometry - uni-wuerzburg.de

13 - 3

Running Time Analysis

FirstConvexHull(S)E← ∅foreach (p, q) ∈ S× S with p 6= q do

valid← trueforeach r ∈ S do

if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

if valid thenE← E ∪ {(p, q)}

from E construct sorted list L of vertices of CH(S)return L

Θ(1)

Page 75: Computational Geometry - uni-wuerzburg.de

13 - 4

Running Time Analysis

FirstConvexHull(S)E← ∅foreach (p, q) ∈ S× S with p 6= q do

valid← trueforeach r ∈ S do

if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

if valid thenE← E ∪ {(p, q)}

from E construct sorted list L of vertices of CH(S)return L

Θ(1)

Θ(n)

Page 76: Computational Geometry - uni-wuerzburg.de

13 - 5

Running Time Analysis

FirstConvexHull(S)E← ∅foreach (p, q) ∈ S× S with p 6= q do

valid← trueforeach r ∈ S do

if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

if valid thenE← E ∪ {(p, q)}

from E construct sorted list L of vertices of CH(S)return L

Θ(1)

Θ(n)

(n2 − n)·

Page 77: Computational Geometry - uni-wuerzburg.de

13 - 6

Running Time Analysis

FirstConvexHull(S)E← ∅foreach (p, q) ∈ S× S with p 6= q do

valid← trueforeach r ∈ S do

if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

if valid thenE← E ∪ {(p, q)}

from E construct sorted list L of vertices of CH(S)return L

Θ(1)

Θ(n)

(n2 − n)·

Θ(n

3 )

Page 78: Computational Geometry - uni-wuerzburg.de

13 - 7

Running Time Analysis

FirstConvexHull(S)E← ∅foreach (p, q) ∈ S× S with p 6= q do

valid← trueforeach r ∈ S do

if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

if valid thenE← E ∪ {(p, q)}

from E construct sorted list L of vertices of CH(S)return L

Θ(1)

Θ(n)

(n2 − n)·

Θ(n

3 )O(n

2 )

Page 79: Computational Geometry - uni-wuerzburg.de

13 - 8

Running Time Analysis

FirstConvexHull(S)E← ∅foreach (p, q) ∈ S× S with p 6= q do

valid← trueforeach r ∈ S do

if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

if valid thenE← E ∪ {(p, q)}

from E construct sorted list L of vertices of CH(S)return L

Θ(1)

Θ(n)

(n2 − n)·

Θ(n

3 )O(n

2 )

Lemma. We can compute the convex hull of n pts in theplane in Θ(n3) time.

Page 80: Computational Geometry - uni-wuerzburg.de

14 - 1

Discussion if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

Page 81: Computational Geometry - uni-wuerzburg.de

14 - 2

Discussion

r

p

q E

if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

Page 82: Computational Geometry - uni-wuerzburg.de

14 - 3

Discussion

r

p

q E

if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

Page 83: Computational Geometry - uni-wuerzburg.de

14 - 4

Discussion

r

p

q E

if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

Test may returnwrong answer(floating pt arithmetic!):

r right of −→pq :-(

Page 84: Computational Geometry - uni-wuerzburg.de

14 - 5

Discussion

r

p

q E

if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

E

Test may returnwrong answer(floating pt arithmetic!):

r right of −→pq :-(

p

r

q

Page 85: Computational Geometry - uni-wuerzburg.de

14 - 6

Discussion

r

p

q E

if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

E

Test may returnwrong answer(floating pt arithmetic!):

r right of −→pq :-(

p not right of −→rq

p

r

q

Page 86: Computational Geometry - uni-wuerzburg.de

14 - 7

Discussion

r

p

q E

if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

E

Test may returnwrong answer(floating pt arithmetic!):

r right of −→pq :-(

p not right of −→rq

q not right of −→pr

p

r

q

Page 87: Computational Geometry - uni-wuerzburg.de

14 - 8

Discussion

r

p

q E

if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

E

Test may returnwrong answer(floating pt arithmetic!):

r right of −→pq :-(

p not right of −→rq

q not right of −→pr

p

r

q

Page 88: Computational Geometry - uni-wuerzburg.de

14 - 9

Discussion

r

p

q E

if not (r strictly right of −→pq or r ∈ pq) thenvalid← false

E

Test may returnwrong answer(floating pt arithmetic!):

r right of −→pq :-(

p not right of −→rq

q not right of −→pr

p

r

q

Observation. Algorithm FirstConvexHull is not robust.

Page 89: Computational Geometry - uni-wuerzburg.de

15 - 1

New Ideas (Graham Scan)

Page 90: Computational Geometry - uni-wuerzburg.de

15 - 2

New Ideas (Graham Scan)• split computation in two

Page 91: Computational Geometry - uni-wuerzburg.de

15 - 3

New Ideas (Graham Scan)• split computation in two

upper convex hull

Page 92: Computational Geometry - uni-wuerzburg.de

15 - 4

New Ideas (Graham Scan)• split computation in two

upper convex hull

lower convex hull

Page 93: Computational Geometry - uni-wuerzburg.de

15 - 5

New Ideas (Graham Scan)• split computation in two

• bring pts in lexicographic order

upper convex hull

lower convex hull

Page 94: Computational Geometry - uni-wuerzburg.de

15 - 6

New Ideas (Graham Scan)• split computation in two

• bring pts in lexicographic order

upper convex hull

lower convex hull• proceed incrementally

Page 95: Computational Geometry - uni-wuerzburg.de

15 - 7

New Ideas (Graham Scan)• split computation in two

• bring pts in lexicographic order

upper convex hull

lower convex hullUpperConvexHull(S: set of pts in the plane)〈p1, p2, . . . , pn〉 ← sort S lexicographicallyL← 〈p1, p2〉for i← 3 to n do

L.append(pi)while |L| > 2 and last 3 pts in L make no right turn do

remove second last pt from L

return L

• proceed incrementally

Page 96: Computational Geometry - uni-wuerzburg.de

15 - 8

New Ideas (Graham Scan)• split computation in two

• bring pts in lexicographic order

upper convex hull

lower convex hullUpperConvexHull(S: set of pts in the plane)〈p1, p2, . . . , pn〉 ← sort S lexicographicallyL← 〈p1, p2〉for i← 3 to n do

L.append(pi)while |L| > 2 and last 3 pts in L make no right turn do

remove second last pt from L

return L

• proceed incrementally

Page 97: Computational Geometry - uni-wuerzburg.de

15 - 9

New Ideas (Graham Scan)• split computation in two

• bring pts in lexicographic order

upper convex hull

lower convex hullUpperConvexHull(S: set of pts in the plane)〈p1, p2, . . . , pn〉 ← sort S lexicographicallyL← 〈p1, p2〉for i← 3 to n do

L.append(pi)while |L| > 2 and last 3 pts in L make no right turn do

remove second last pt from L

return L

• proceed incrementally

Page 98: Computational Geometry - uni-wuerzburg.de

15 - 10

New Ideas (Graham Scan)• split computation in two

• bring pts in lexicographic order

upper convex hull

lower convex hullUpperConvexHull(S: set of pts in the plane)〈p1, p2, . . . , pn〉 ← sort S lexicographicallyL← 〈p1, p2〉for i← 3 to n do

L.append(pi)while |L| > 2 and last 3 pts in L make no right turn do

remove second last pt from L

return L

• proceed incrementally

// compute upper convex hull of {p1, p2, . . . , pi}

Page 99: Computational Geometry - uni-wuerzburg.de

15 - 11

New Ideas (Graham Scan)• split computation in two

• bring pts in lexicographic order

upper convex hull

lower convex hullUpperConvexHull(S: set of pts in the plane)〈p1, p2, . . . , pn〉 ← sort S lexicographicallyL← 〈p1, p2〉for i← 3 to n do

L.append(pi)while |L| > 2 and last 3 pts in L make no right turn do

remove second last pt from L

return L

• proceed incrementally

// compute upper convex hull of {p1, p2, . . . , pi}

Page 100: Computational Geometry - uni-wuerzburg.de

15 - 12

New Ideas (Graham Scan)• split computation in two

• bring pts in lexicographic order

upper convex hull

lower convex hullUpperConvexHull(S: set of pts in the plane)〈p1, p2, . . . , pn〉 ← sort S lexicographicallyL← 〈p1, p2〉for i← 3 to n do

L.append(pi)while |L| > 2 and last 3 pts in L make no right turn do

remove second last pt from L

return L

• proceed incrementally

// compute upper convex hull of {p1, p2, . . . , pi}

Page 101: Computational Geometry - uni-wuerzburg.de

16 - 1

Running Time AnalysisUpperConvexHull(S: set of pts in the plane)〈p1, p2, . . . , pn〉 ← sort S lexicographicallyL← 〈p1, p2〉for i← 3 to n do

L.append(pi)while |L| > 2 and last 3 pts in L make no right turn do

remove second last pt from L

return L

Page 102: Computational Geometry - uni-wuerzburg.de

16 - 2

Running Time AnalysisUpperConvexHull(S: set of pts in the plane)〈p1, p2, . . . , pn〉 ← sort S lexicographicallyL← 〈p1, p2〉for i← 3 to n do

L.append(pi)while |L| > 2 and last 3 pts in L make no right turn do

remove second last pt from L

return L

O(n log n)

Page 103: Computational Geometry - uni-wuerzburg.de

16 - 3

Running Time AnalysisUpperConvexHull(S: set of pts in the plane)〈p1, p2, . . . , pn〉 ← sort S lexicographicallyL← 〈p1, p2〉for i← 3 to n do

L.append(pi)while |L| > 2 and last 3 pts in L make no right turn do

remove second last pt from L

return L

O(n log n)

(n− 2)·

Page 104: Computational Geometry - uni-wuerzburg.de

16 - 4

Running Time AnalysisUpperConvexHull(S: set of pts in the plane)〈p1, p2, . . . , pn〉 ← sort S lexicographicallyL← 〈p1, p2〉for i← 3 to n do

L.append(pi)while |L| > 2 and last 3 pts in L make no right turn do

remove second last pt from L

return L

O(n log n)

(n− 2)·

?

Page 105: Computational Geometry - uni-wuerzburg.de

16 - 5

Running Time AnalysisUpperConvexHull(S: set of pts in the plane)〈p1, p2, . . . , pn〉 ← sort S lexicographicallyL← 〈p1, p2〉for i← 3 to n do

L.append(pi)while |L| > 2 and last 3 pts in L make no right turn do

remove second last pt from L

return L

O(n log n)

(n− 2)·

?

Amortized analysis:

Page 106: Computational Geometry - uni-wuerzburg.de

16 - 6

Running Time AnalysisUpperConvexHull(S: set of pts in the plane)〈p1, p2, . . . , pn〉 ← sort S lexicographicallyL← 〈p1, p2〉for i← 3 to n do

L.append(pi)while |L| > 2 and last 3 pts in L make no right turn do

remove second last pt from L

return L

O(n log n)

(n− 2)·

?

Amortized analysis:– each pt p2, . . . , pn−1 pays 1e for its potential removal later on

Page 107: Computational Geometry - uni-wuerzburg.de

16 - 7

Running Time AnalysisUpperConvexHull(S: set of pts in the plane)〈p1, p2, . . . , pn〉 ← sort S lexicographicallyL← 〈p1, p2〉for i← 3 to n do

L.append(pi)while |L| > 2 and last 3 pts in L make no right turn do

remove second last pt from L

return L

O(n log n)

(n− 2)·

?

Amortized analysis:– each pt p2, . . . , pn−1 pays 1e for its potential removal later on– this pays for the total effort of all executions of the while loop

Page 108: Computational Geometry - uni-wuerzburg.de

16 - 8

Running Time AnalysisUpperConvexHull(S: set of pts in the plane)〈p1, p2, . . . , pn〉 ← sort S lexicographicallyL← 〈p1, p2〉for i← 3 to n do

L.append(pi)while |L| > 2 and last 3 pts in L make no right turn do

remove second last pt from L

return L

O(n log n)

(n− 2)·

?

Amortized analysis:– each pt p2, . . . , pn−1 pays 1e for its potential removal later on– this pays for the total effort of all executions of the while loop

Page 109: Computational Geometry - uni-wuerzburg.de

16 - 9

Running Time AnalysisUpperConvexHull(S: set of pts in the plane)〈p1, p2, . . . , pn〉 ← sort S lexicographicallyL← 〈p1, p2〉for i← 3 to n do

L.append(pi)while |L| > 2 and last 3 pts in L make no right turn do

remove second last pt from L

return L

O(n log n)

(n− 2)·

?

Amortized analysis:– each pt p2, . . . , pn−1 pays 1e for its potential removal later on– this pays for the total effort of all executions of the while loop

O(n)

Page 110: Computational Geometry - uni-wuerzburg.de

16 - 10

Running Time AnalysisUpperConvexHull(S: set of pts in the plane)〈p1, p2, . . . , pn〉 ← sort S lexicographicallyL← 〈p1, p2〉for i← 3 to n do

L.append(pi)while |L| > 2 and last 3 pts in L make no right turn do

remove second last pt from L

return L

O(n log n)

(n− 2)·

?

Amortized analysis:– each pt p2, . . . , pn−1 pays 1e for its potential removal later on– this pays for the total effort of all executions of the while loop

O(n)

Theorem. We can compute the convex hull of n pts in theplane in O(n log n) time – in a robust way.

Page 111: Computational Geometry - uni-wuerzburg.de

17 - 1

Output-Sensitive Algorithms• Jarvis’ gift-wrapping algorithm (aka Jarvis’ march)

Page 112: Computational Geometry - uni-wuerzburg.de

17 - 2

Output-Sensitive Algorithms• Jarvis’ gift-wrapping algorithm (aka Jarvis’ march)

Page 113: Computational Geometry - uni-wuerzburg.de

17 - 3

Output-Sensitive Algorithms• Jarvis’ gift-wrapping algorithm (aka Jarvis’ march)

Page 114: Computational Geometry - uni-wuerzburg.de

17 - 4

Output-Sensitive Algorithms• Jarvis’ gift-wrapping algorithm (aka Jarvis’ march)

Page 115: Computational Geometry - uni-wuerzburg.de

17 - 5

Output-Sensitive Algorithms• Jarvis’ gift-wrapping algorithm (aka Jarvis’ march)

Page 116: Computational Geometry - uni-wuerzburg.de

17 - 6

Output-Sensitive Algorithms• Jarvis’ gift-wrapping algorithm (aka Jarvis’ march)

Page 117: Computational Geometry - uni-wuerzburg.de

17 - 7

Output-Sensitive Algorithms• Jarvis’ gift-wrapping algorithm (aka Jarvis’ march)

Page 118: Computational Geometry - uni-wuerzburg.de

17 - 8

Output-Sensitive Algorithms• Jarvis’ gift-wrapping algorithm (aka Jarvis’ march)

Page 119: Computational Geometry - uni-wuerzburg.de

17 - 9

Output-Sensitive Algorithms• Jarvis’ gift-wrapping algorithm (aka Jarvis’ march)

Page 120: Computational Geometry - uni-wuerzburg.de

17 - 10

Output-Sensitive Algorithms• Jarvis’ gift-wrapping algorithm (aka Jarvis’ march)

Page 121: Computational Geometry - uni-wuerzburg.de

17 - 11

Output-Sensitive Algorithms• Jarvis’ gift-wrapping algorithm (aka Jarvis’ march)

Runtime?

Page 122: Computational Geometry - uni-wuerzburg.de

17 - 12

Output-Sensitive Algorithms• Jarvis’ gift-wrapping algorithm (aka Jarvis’ march)

Runtime? O(n · h)

Page 123: Computational Geometry - uni-wuerzburg.de

17 - 13

Output-Sensitive Algorithms• Jarvis’ gift-wrapping algorithm (aka Jarvis’ march)

. . . where h = |CH(S)| = size of the output

Runtime? O(n · h)

Page 124: Computational Geometry - uni-wuerzburg.de

17 - 14

Output-Sensitive Algorithms• Jarvis’ gift-wrapping algorithm (aka Jarvis’ march)

• Chan’s exponential-search algorithm O(n log h)

. . . where h = |CH(S)| = size of the output

Runtime? O(n · h)

Page 125: Computational Geometry - uni-wuerzburg.de

18 - 1

Chan’s Algorithm P1P2

P4

P3

Page 126: Computational Geometry - uni-wuerzburg.de

18 - 2

Chan’s Algorithm P1P2

P4

P3

[in O(m log m) time]

Page 127: Computational Geometry - uni-wuerzburg.de

18 - 3

Chan’s Algorithm P1P2

P4

P3

[in O(m log m) time]

p1

p0

Page 128: Computational Geometry - uni-wuerzburg.de

18 - 4

Chan’s Algorithm P1P2

P4

P3

[in O(m log m) time]

p1

p0

Page 129: Computational Geometry - uni-wuerzburg.de

18 - 5

Chan’s Algorithm P1P2

P4

P3

q1

q3q4

q2

[in O(m log m) time]

pk

pk−1

pk+1

p1

p0

Page 130: Computational Geometry - uni-wuerzburg.de

18 - 6

Chan’s Algorithm P1P2

P4

P3

q1

q3q4

q2

[in O(m log m) time]

pk

pk−1

pk+1

p1

p0

Page 131: Computational Geometry - uni-wuerzburg.de

18 - 7

Chan’s Algorithm P1P2

P4

P3

q1

q3q4

q2

[in O(m log m) time]

pk

pk−1

pk+1

p1

p0

Page 132: Computational Geometry - uni-wuerzburg.de

19

Chan’s AlgorithmInitially, we assume that the value of h is known and make a parameter m = h. This assumption is not realistic, but weremove it later. The algorithm starts by arbitrarily partitioning P into at most 1 + n

m subsets Q with at most m pointseach. Then, it computes the convex hull of each subset Q using an O(n log n) algorithm – Graham’s scan. Note that, asthere are O(n/m) subsets of O(m) points each, this phase takes O(n/m) ·O(m log m) = O(n log m) time.

The second phase consists of executing the Jarvis’ march algorithm algorithm and using the precomputed convex hullsto speed up the execution. At each step in Jarvis’s march, we have a point pi in the convex hull, and need to find a pointpi+1 = f (pi , P) such that all other points of P are to the right of the line pi pi+1. If we know the convex hull of a set Qof m points, then we can compute f (pi , Q) in O(log m) time, by using binary search. We can compute f (pi , Q) for allthe O(n/m) subsets Q in O(n/m log m) time. Then, we can determine f (pi , P) using the same technique as normallyused in Jarvis’s march, but only considering the points that are f (pi , Q) for some subset Q. As Jarvis’s march repeatsthis process O(h) times, the second phase also takes O(n log m) time, and therefore O(n log h) time if m = h.By running the two phases described above, we can compute the convex hull of n points in O(n log h) time, assumingthat we know the value of h. If we make m < h, we can abort the execution after m + 1 steps, therefore spending onlyO(n log m) time (but not computing the convex hull). We can initially set m as a small constant (we use 2 for ouranalysis, but in practice numbers around 5 may work better), and increase the value of m until m > h, in which case weobtain the convex hull as a result.If we increase the value of m too slowly, we may need to repeat the steps mentioned before too many times, and theexecution time will be large. On the other hand, if we increase the value of m too quickly, we risk making m much largerthan h, also increasing the execution time. Similar to strategy used by Chazelle and Matousek’s algorithm, Chan’salgorithm squares the value of m at each iteration, and makes sure that m is never larger than n. In other words, at

iteration t (starting at 1), we have m = min(

n, 22t)

. The total running time of the algorithm is

dlog log he∑

t=1O(

n log(22t)

)= O(n)

dlog log he∑

t=1O(2t ) = O

(n · 21+dlog log he) = O(n log h).

To generalize this construction for the 3-dimensional case, an O(n log n) algorithm to compute the 3-dimensionalconvex hull should be used instead of Graham scan, and a 3-dimensional version of Jarvis’s march needs to be used.The time complexity remains O(n log h).

[Text copied on October 17, 2017 from:https://en.wikipedia.org/wiki/Chan’s algorithm]