150
1-1 Computational Geometry Lecture #1 Convex Hull or Mixing Things Thomas van Dijk Winter Semester 2019/20

Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

1 - 1

Computational Geometry

Lecture #1

Convex Hullor

Mixing Things

Thomas van Dijk Winter Semester 2019/20

Page 2: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

1 - 2

Computational Geometry

Lecture #1

Convex Hullor

Mixing Things

Thomas van Dijk Winter Semester 2019/20

Page 3: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

2 - 1

Chair I

a) Efficient Algorithms

b) Knowledge-Based SystemsProf. Dietmar Seipel

c) Theoretical Comp. ScienceProf. Christian Glaßer

Page 4: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

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 · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

3 - 1

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

Page 6: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

3 - 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 7: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

3 - 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 efficient solutions withthe concepts of the lecture.

Page 8: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

3 - 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 efficient solutions withthe concepts of the lecture.

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

Page 9: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

3 - 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 efficient solutions withthe concepts of the lecture.

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

(Balanced) binary search tree, priority queue

Page 10: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

3 - 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 efficient solutions withthe concepts of the lecture.

– 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 11: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

3 - 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 efficient solutions withthe concepts of the lecture.

– 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 12: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

3 - 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 efficient solutions withthe concepts of the lecture.

– 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 13: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

4 - 1

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 14: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

4 - 2

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

New! MinimumConvex Partition

Page 15: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

5 - 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 16: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

5 - 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 17: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

5 - 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 18: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

6

Week 1

Mixing Thingsor:

Convex Hull

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

Page 19: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

7 - 1

Mixing Things

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

Given...

Page 20: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

7 - 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 21: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

7 - 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 22: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

7 - 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 23: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

7 - 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 24: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

7 - 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 25: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

7 - 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 26: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

7 - 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 27: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

7 - 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 28: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

7 - 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 29: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

8 - 1

Formally. . .

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

Page 30: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

8 - 2

Formally. . .

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

Physics approach:

Page 31: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

8 - 3

Formally. . .

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

Physics approach: – take (large enough) elastic rope

Page 32: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

8 - 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 33: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

8 - 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 34: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

8 - 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 35: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

8 - 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 36: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

8 - 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

Maths approach:

Page 37: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

8 - 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

Maths approach: – define convex

Page 38: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

8 - 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

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

⋂C⊇S : C convex

C

Page 39: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

9 - 1

Towards Computation

Problem with maths approach:

CH(S) def=

⋂C⊇S : C convex

C

Page 40: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

9 - 2

Towards Computation

Problem with maths approach:

CH(S) def=

⋂C⊇S : C convex

C

This set is HUGE!

Page 41: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

9 - 3

Towards Computation

Problem with maths approach:

CH(S) def=

⋂C⊇S : C convex

C

This set is HUGE!

Maybe we can do with a little less?

Page 42: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

9 - 4

Towards Computation

Problem with maths 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 43: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

9 - 5

Towards Computation

Problem with maths 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 44: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

9 - 6

Towards Computation

Problem with maths 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 45: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

9 - 7

Towards Computation

Problem with maths 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 46: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

10 - 1

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

Page 47: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

10 - 2

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

Page 48: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

10 - 3

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

Page 49: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

10 - 4

Algorithmic ApproachInput:

Output:

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

list of vertices of CH(S) in clockwise order

Page 50: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

10 - 5

Algorithmic 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 51: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

10 - 6

Algorithmic 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 52: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

11 - 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 53: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

11 - 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 54: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

11 - 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 55: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

11 - 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 56: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

11 - 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 57: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

11 - 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 58: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

11 - 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 59: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

11 - 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 60: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

11 - 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 61: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

11 - 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 62: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

12 - 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 63: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

12 - 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 64: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

12 - 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 65: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

12 - 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 66: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

12 - 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 67: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

12 - 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 68: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

12 - 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 69: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

12 - 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 70: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

13 - 1

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

Page 71: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

13 - 2

Discussion

r

p

q E

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

Page 72: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

13 - 3

Discussion

r

p

q E

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

Page 73: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

13 - 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 74: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

13 - 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 75: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

13 - 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 76: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

13 - 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 77: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

13 - 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 78: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

13 - 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 79: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 1

New Ideas (Graham Scan)

Page 80: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 2

New Ideas (Graham Scan)• split computation in two

Page 81: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 3

New Ideas (Graham Scan)• split computation in two

upper convex hull

Page 82: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 4

New Ideas (Graham Scan)• split computation in two

upper convex hull

lower convex hull

Page 83: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 5

New Ideas (Graham Scan)• split computation in two

• bring pts in lexicographic order

upper convex hull

lower convex hull

Page 84: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 6

New Ideas (Graham Scan)• split computation in two

• bring pts in lexicographic order

upper convex hull

lower convex hull• proceed incrementally

Page 85: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 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 86: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 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 87: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 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 88: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 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 89: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 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 90: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 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 91: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 13

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 92: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 14

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 93: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 15

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 94: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 16

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 95: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 17

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 96: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 18

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 97: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 19

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 98: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 20

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 · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 21

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 · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 22

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 · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 23

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 102: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 24

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 103: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 25

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 104: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 26

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 105: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 27

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 106: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 28

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 107: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 29

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 108: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 30

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 109: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 31

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 110: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 32

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 111: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 33

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 112: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 34

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 113: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 35

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 114: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 36

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 115: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 37

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 116: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 38

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 117: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 39

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 118: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

14 - 40

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 119: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

15 - 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 120: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

15 - 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 121: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

15 - 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 122: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

15 - 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 123: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

15 - 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 124: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

15 - 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 125: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

15 - 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 126: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

15 - 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 127: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

15 - 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 128: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

15 - 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 129: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

16 - 1

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

Page 130: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

16 - 2

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

Page 131: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

16 - 3

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

Page 132: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

16 - 4

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

Page 133: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

16 - 5

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

Page 134: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

16 - 6

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

Page 135: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

16 - 7

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

Page 136: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

16 - 8

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

Page 137: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

16 - 9

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

Page 138: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

16 - 10

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

Page 139: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

16 - 11

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

Runtime?

Page 140: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

16 - 12

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

Runtime? O(n · h)

Page 141: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

16 - 13

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

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

Runtime? O(n · h)

Page 142: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

16 - 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 143: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

17 - 1

Chan’s Algorithm P1P2

P4

P3

Page 144: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

17 - 2

Chan’s Algorithm P1P2

P4

P3

[in O(m log m) time]

Page 145: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

17 - 3

Chan’s Algorithm P1P2

P4

P3

[in O(m log m) time]

p1

p0

Page 146: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

17 - 4

Chan’s Algorithm P1P2

P4

P3

[in O(m log m) time]

p1

p0

Page 147: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

17 - 5

Chan’s Algorithm P1P2

P4

P3

q1

q3q4

q2

[in O(m log m) time]

pk

pk−1

pk+1

p1

p0

Page 148: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

17 - 6

Chan’s Algorithm P1P2

P4

P3

q1

q3q4

q2

[in O(m log m) time]

pk

pk−1

pk+1

p1

p0

Page 149: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

17 - 7

Chan’s Algorithm P1P2

P4

P3

q1

q3q4

q2

[in O(m log m) time]

pk

pk−1

pk+1

p1

p0

Page 150: Computational Geometry · Computational Geometry Learning goals: decide which algorithms help to solve a number of fundamental geometric problems, Requirements: At the end of this

18

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]