DCG19 Convex Hulls - Graz University of Technology · Irene Parada Discrete and Computational...

Post on 15-Jul-2020

4 views 0 download

Transcript of DCG19 Convex Hulls - Graz University of Technology · Irene Parada Discrete and Computational...

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls1

Convex Hulls

Discrete & Computational Geometry WS 2019/20

Slides by Irene Parada and Vera Sacristan

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls2

Outline

• Convexity.

• Caratheodory’s Theorem.

• Convex hulls in 2D.

• Doubly connected edge list (DCEL).

• Convex hulls in 3D.

• Convex hulls in higher dimensions.

• Convex hulls of simple polygons.

In this lecture: general position (no three collinear points)and worst-case complexity.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls3

Convexity I

Let S be a set of points in Ed (real Euclidean space of dim. d).

Linear combination of points in S:k∑i=1

λipi, with k ∈ N, pi ∈ S, λi ∈ R.

Affine combination of points in S:

linear combination s.t.k∑i=1

λi = 1.

The set of all affinecombinations of S is calledaffine hull of S.

Convex combination of points in S:affine combination s.t. λi ≥ 0 ∀ i.

The set of all convexcombinations of S is calledconvex hull of S, conv(S).

A set is called convex if it is stable under convex combinations.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls3

Convexity I

Linear combination of points in S:k∑i=1

λipi, with k ∈ N, pi ∈ S, λi ∈ R.

Affine combination of points in S:

linear combination s.t.k∑i=1

λi = 1.

Convex combination of points in S:affine combination s.t. λi ≥ 0 ∀ i.

Exercise: Find the set of allcombinations of each type of thesetwo points in the Euclidean plane.

Let S be a set of points in Ed.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls3

Convexity I

Linear combination of points in S:k∑i=1

λipi, with k ∈ N, pi ∈ S, λi ∈ R.

Affine combination of points in S:

linear combination s.t.k∑i=1

λi = 1.

Convex combination of points in S:affine combination s.t. λi ≥ 0 ∀ i.

Let S be a set of points in Ed.Exercise: Find the set of all

combinations of each type of thesethree points in the plane.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls4

Convexity II

Prop. A set S is convex iff it contains segment pq for all p, q ∈ S.

convexnot convex

pq

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls4

Convexity II

Prop. A set S is convex iff it contains segment pq for all p, q ∈ S.

Proof :(⇒) If S is convex, it is stable under convex combinations and, inparticular, it contains all segments with endpoints in S.

(⇐) By induction on the number of points k of the convexcombination. For k = 2, we have the statement.Consider now a convex combination with k + 1 points. We have

k∑i=0

λipi = λ0p0 +k∑i=1

λipi = λ0p0 + (1− λ0)k∑i=1

λi1− λ0

pi ∈ S.

k∑i=1

λipi ∈ S, for all pi ∈ S, λi ≥ 0,∑ki=1 λi = 1.

Def.

Want to show ∈ S Since∑ki=1

λi

1−λ0= 1−λ0

1−λ0= 1, by ind. hip. ∈ S

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls4

Convexity II

Prop. A set S is convex iff it contains segment pq for all p, q ∈ S.

Corollaries:• The intersection of convex sets is convex.

• The convex hull conv(S) of a set S is the smallest convex setcontaining S.

• The convex hull conv(S) of a set S is the intersection of all theconvex sets containing S.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls5

Caratheodory’s Theorem

Caratheodory’s Thm. Let S be a set of points in Ed. Every pointp ∈ conv(S) can be written as the convex combination of at mostd+ 1 points of S.

Proof. Suppose p is a convex combination of k points of S and k is

the smallest possible: p =k∑i=1

λipi with pi ∈ S, λi > 0,k∑i=1

λi = 1.

Assume k > d+ 1. Then the k − 1 > d vectors p2 − p1, . . . , pk − p1are linearly dependent:

∑ki=2 µi(pi − p1) = 0 with not all µi = 0.

We define µ1 = −∑ki=2 µi. Then

k∑i=1

µipi = 0 andk∑i=1

µi = 0.

Thus, for any α ∈ R, p =k∑i=1

λipi − αk∑i=1

µipi =k∑i=1

(λi − αµi)pi.

Set α = min1≤j≤k

λj

µj: µj > 0

⇒ p is a convex comb. of < k points.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls6

Computing the Convex Hull in 2D

Input: S = p1, . . . , pn.Output: set of the extreme points.

Procedure:For each i,

For each j, k, l 6= i,If pi lies in the triangle pj , pk, pl,eliminate pi.

Return the set of surviving pi’s.

Algorithm 1: Computing the extreme points by brute force.

Given S = p1, . . . , pn, the point pi belongs to the boundary ofconv(S) iff pi does not lie in any of the triangles pjpkpl.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls6

Computing the Convex Hull in 2D

Input: S = p1, . . . , pn.Output: set of the extreme points.

Procedure:For each i,

For each j, k, l 6= i,If pi lies in the triangle pj , pk, pl,eliminate pi.

Return the set of surviving pi’s.

Algorithm 1: Computing the extreme points by brute force.

Given S = p1, . . . , pn, the point pi belongs to the boundary ofconv(S) iff pi does not lie in any of the triangles pjpkpl.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls6

Computing the Convex Hull in 2D

Input: S = p1, . . . , pn.Output: set of the extreme points.

Procedure:For each i,

For each j, k, l 6= i,If pi lies in the triangle pj , pk, pl,eliminate pi.

Return the set of surviving pi’s.

Algorithm 1: Computing the extreme points by brute force.

Given S = p1, . . . , pn, the point pi belongs to the boundary ofconv(S) iff pi does not lie in any of the triangles pjpkpl.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls6

Computing the Convex Hull in 2D

Input: S = p1, . . . , pn.Output: set of the extreme points.

Procedure:For each i,

For each j, k, l 6= i,If pi lies in the triangle pj , pk, pl,eliminate pi.

Return the set of surviving pi’s.

Algorithm 1: Computing the extreme points by brute force.

Given S = p1, . . . , pn, the point pi belongs to the boundary ofconv(S) iff pi does not lie in any of the triangles pjpkpl.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls6

Computing the Convex Hull in 2D

Input: S = p1, . . . , pn.Output: set of the extreme points.

Procedure:For each i,

For each j, k, l 6= i,If pi lies in the triangle pj , pk, pl,eliminate pi.

Return the set of surviving pi’s.

Algorithm 1: Computing the extreme points by brute force.

Given S = p1, . . . , pn, the point pi belongs to the boundary ofconv(S) iff pi does not lie in any of the triangles pjpkpl.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls6

Computing the Convex Hull in 2D

Input: S = p1, . . . , pn.Output: set of the extreme points.

Procedure:For each i,

For each j, k, l 6= i,If pi lies in the triangle pj , pk, pl,eliminate pi.

Return the set of surviving pi’s.

Algorithm 1: Computing the extreme points by brute force.

Given S = p1, . . . , pn, the point pi belongs to the boundary ofconv(S) iff pi does not lie in any of the triangles pjpkpl.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls6

Computing the Convex Hull in 2D

Input: S = p1, . . . , pn.Output: set of the extreme points.

Procedure:For each i,

For each j, k, l 6= i,If pi lies in the triangle pj , pk, pl,eliminate pi.

Return the set of surviving pi’s.

Algorithm 1: Computing the extreme points by brute force.

Given S = p1, . . . , pn, the point pi belongs to the boundary ofconv(S) iff pi does not lie in any of the triangles pjpkpl.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls6

Computing the Convex Hull in 2D

Input: S = p1, . . . , pn.Output: set of the extreme points.

Procedure:For each i,

For each j, k, l 6= i,If pi lies in the triangle pj , pk, pl,eliminate pi.

Return the set of surviving pi’s.

Running time: O(n4)

Algorithm 1: Computing the extreme points by brute force.

Given S = p1, . . . , pn, the point pi belongs to the boundary ofconv(S) iff pi does not lie in any of the triangles pjpkpl.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls6

Computing the Convex Hull in 2D

Input: S = p1, . . . , pn.Output: set of the extreme points.

Procedure:For each i,

For each j, k, l 6= i,If pi lies in the triangle pj , pk, pl,eliminate pi.

Return the set of surviving pi’s.

Running time: O(n4)

Algorithm 1: Computing the extreme points by brute force.

Given S = p1, . . . , pn, the point pi belongs to the boundary ofconv(S) iff pi does not lie in any of the triangles pjpkpl.

Exercise: Does this approachwork in d dimensions? If yes,

what is the running time?

Yes, using Caratheodory’stheorem and the same approachwe get an O(nd+2) algorithm.

(Can be tightened more, thoughnot in the exponent.)

Still, this is not an efficientalgorithm!

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls7

Computing the Convex Hull in 2D

Algorithm 2: Computing the extreme segments by brute force.

Given S = p1, . . . , pn, the segment pipj belongs to the boundaryof conv(S) iff all other pi lie in the same halfplane defined by pipj .

Input: S = p1, . . . , pn.Output: set of extreme segments.

Procedure:For each i, j,

Check whether all pk, k 6= i, jlie on the same halplanedefined by pipj .

If true, return the segment pk.

Running time: Θ(n3)

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls8

Computing the Convex Hull in 2D

Algorithm 3: Jarvis’ march (gift wrapping).

Given S = p1, . . . , pn, the segment pipj belongs to the boundaryof conv(S) iff all other pk lie to the left of pipj (oriented).

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Procedure:

Add extreme point to l.Set v = Last(l).While |l| = 1 < n or v 6= First(l):

Detect angularly rightmost pointpj ∈ P wrt v and add it to l.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls8

Computing the Convex Hull in 2D

Algorithm 3: Jarvis’ march (gift wrapping).

Given S = p1, . . . , pn, the segment pipj belongs to the boundaryof conv(S) iff all other pk lie to the left of pipj (oriented).

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Procedure:

Add extreme point to l.Set v = Last(l).While |l| = 1 < n or v 6= First(l):

Detect angularly rightmost pointpj ∈ P wrt v and add it to l.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls8

Computing the Convex Hull in 2D

Algorithm 3: Jarvis’ march (gift wrapping).

Given S = p1, . . . , pn, the segment pipj belongs to the boundaryof conv(S) iff all other pk lie to the left of pipj (oriented).

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Procedure:

Add extreme point to l.Set v = Last(l).While |l| = 1 < n or v 6= First(l):

Detect angularly rightmost pointpj ∈ P wrt v and add it to l.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls8

Computing the Convex Hull in 2D

Algorithm 3: Jarvis’ march (gift wrapping).

Given S = p1, . . . , pn, the segment pipj belongs to the boundaryof conv(S) iff all other pk lie to the left of pipj (oriented).

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Procedure:

Add extreme point to l.Set v = Last(l).While |l| = 1 < n or v 6= First(l):

Detect angularly rightmost pointpj ∈ P wrt v and add it to l.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls8

Computing the Convex Hull in 2D

Algorithm 3: Jarvis’ march (gift wrapping).

Given S = p1, . . . , pn, the segment pipj belongs to the boundaryof conv(S) iff all other pk lie to the left of pipj (oriented).

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Procedure:

Add extreme point to l.Set v = Last(l).While |l| = 1 < n or v 6= First(l):

Detect angularly rightmost pointpj ∈ P wrt v and add it to l.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls8

Computing the Convex Hull in 2D

Algorithm 3: Jarvis’ march (gift wrapping).

Given S = p1, . . . , pn, the segment pipj belongs to the boundaryof conv(S) iff all other pk lie to the left of pipj (oriented).

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Procedure:

Add extreme point to l.Set v = Last(l).While |l| = 1 < n or v 6= First(l):

Detect angularly rightmost pointpj ∈ P wrt v and add it to l.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls8

Computing the Convex Hull in 2D

Algorithm 3: Jarvis’ march (gift wrapping).

Given S = p1, . . . , pn, the segment pipj belongs to the boundaryof conv(S) iff all other pk lie to the left of pipj (oriented).

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Procedure:

Add extreme point to l.Set v = Last(l).While |l| = 1 < n or v 6= First(l):

Detect angularly rightmost pointpj ∈ P wrt v and add it to l.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls8

Computing the Convex Hull in 2D

Algorithm 3: Jarvis’ march (gift wrapping).

Given S = p1, . . . , pn, the segment pipj belongs to the boundaryof conv(S) iff all other pk lie to the left of pipj (oriented).

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Procedure:

Add extreme point to l.Set v = Last(l).While |l| = 1 < n or v 6= First(l):

Detect angularly rightmost pointpj ∈ P wrt v and add it to l.

Running time: Θ(hn) = O(n2)

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls9

Computing the Convex Hull in 2D

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization:- Push v extremal in l, del. from S.- Angularly sort pts. in S around v.- Push first pt. in l and del. from S.

Advance:While ∃pi ∈ S to be explored:p = last(l); p− = prev(last(l))- If p−ppi is a left turn:

Push pi in l, del. from S.- Else: Pop p from l.

Algorithm 4: Graham’s scan (succesive local repair).

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls9

Computing the Convex Hull in 2D

1 23

4

56

7

8

9

10

11

12

13

14

15

16

17

18

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization:- Push v extremal in l, del. from S.- Angularly sort pts. in S around v.- Push first pt. in l and del. from S.

Advance:While ∃pi ∈ S to be explored:p = last(l); p− = prev(last(l))- If p−ppi is a left turn:

Push pi in l, del. from S.- Else: Pop p from l.

Algorithm 4: Graham’s scan (succesive local repair).

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls9

Computing the Convex Hull in 2D

1 23

4

56

7

8

9

10

11

12

13

14

15

16

17

18

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization:- Push v extremal in l, del. from S.- Angularly sort pts. in S around v.- Push first pt. in l and del. from S.

Advance:While ∃pi ∈ S to be explored:p = last(l); p− = prev(last(l))- If p−ppi is a left turn:

Push pi in l, del. from S.- Else: Pop p from l.

Algorithm 4: Graham’s scan (succesive local repair).

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls9

Computing the Convex Hull in 2D

1 23

4

56

7

8

9

10

11

12

13

14

15

16

17

18

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization:- Push v extremal in l, del. from S.- Angularly sort pts. in S around v.- Push first pt. in l and del. from S.

Advance:While ∃pi ∈ S to be explored:p = last(l); p− = prev(last(l))- If p−ppi is a left turn:

Push pi in l, del. from S.- Else: Pop p from l.

Algorithm 4: Graham’s scan (succesive local repair).

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls9

Computing the Convex Hull in 2D

1 23

4

56

7

8

9

10

11

12

13

14

15

16

17

18

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization:- Push v extremal in l, del. from S.- Angularly sort pts. in S around v.- Push first pt. in l and del. from S.

Advance:While ∃pi ∈ S to be explored:p = last(l); p− = prev(last(l))- If p−ppi is a left turn:

Push pi in l, del. from S.- Else: Pop p from l.

Algorithm 4: Graham’s scan (succesive local repair).

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls9

Computing the Convex Hull in 2D

1 23

4

56

7

8

9

10

11

12

13

14

15

16

17

18

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization:- Push v extremal in l, del. from S.- Angularly sort pts. in S around v.- Push first pt. in l and del. from S.

Advance:While ∃pi ∈ S to be explored:p = last(l); p− = prev(last(l))- If p−ppi is a left turn:

Push pi in l, del. from S.- Else: Pop p from l.

Algorithm 4: Graham’s scan (succesive local repair).

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls9

Computing the Convex Hull in 2D

1 23

4

56

7

8

9

10

11

12

13

14

15

16

17

18

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization:- Push v extremal in l, del. from S.- Angularly sort pts. in S around v.- Push first pt. in l and del. from S.

Advance:While ∃pi ∈ S to be explored:p = last(l); p− = prev(last(l))- If p−ppi is a left turn:

Push pi in l, del. from S.- Else: Pop p from l.

Algorithm 4: Graham’s scan (succesive local repair).

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls9

Computing the Convex Hull in 2D

1 23

4

56

7

8

9

10

11

12

13

14

15

16

17

18

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization:- Push v extremal in l, del. from S.- Angularly sort pts. in S around v.- Push first pt. in l and del. from S.

Advance:While ∃pi ∈ S to be explored:p = last(l); p− = prev(last(l))- If p−ppi is a left turn:

Push pi in l, del. from S.- Else: Pop p from l.

Algorithm 4: Graham’s scan (succesive local repair).

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls9

Computing the Convex Hull in 2D

1 23

4

56

7

8

9

10

11

12

13

14

15

16

17

18

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization:- Push v extremal in l, del. from S.- Angularly sort pts. in S around v.- Push first pt. in l and del. from S.

Advance:While ∃pi ∈ S to be explored:p = last(l); p− = prev(last(l))- If p−ppi is a left turn:

Push pi in l, del. from S.- Else: Pop p from l.

Algorithm 4: Graham’s scan (succesive local repair).

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls9

Computing the Convex Hull in 2D

1 23

4

56

7

8

9

10

11

12

13

14

15

16

17

18

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization:- Push v extremal in l, del. from S.- Angularly sort pts. in S around v.- Push first pt. in l and del. from S.

Advance:While ∃pi ∈ S to be explored:p = last(l); p− = prev(last(l))- If p−ppi is a left turn:

Push pi in l, del. from S.- Else: Pop p from l.

Algorithm 4: Graham’s scan (succesive local repair).

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls9

Computing the Convex Hull in 2D

1 23

4

56

7

8

9

10

11

12

13

14

15

16

17

18

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization:- Push v extremal in l, del. from S.- Angularly sort pts. in S around v.- Push first pt. in l and del. from S.

Advance:While ∃pi ∈ S to be explored:p = last(l); p− = prev(last(l))- If p−ppi is a left turn:

Push pi in l, del. from S.- Else: Pop p from l.

Algorithm 4: Graham’s scan (succesive local repair).

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls9

Computing the Convex Hull in 2D

1 23

4

56

7

8

9

10

11

12

13

14

15

16

17

18

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization:- Push v extremal in l, del. from S.- Angularly sort pts. in S around v.- Push first pt. in l and del. from S.

Advance:While ∃pi ∈ S to be explored:p = last(l); p− = prev(last(l))- If p−ppi is a left turn:

Push pi in l, del. from S.- Else: Pop p from l.

Algorithm 4: Graham’s scan (succesive local repair).

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls9

Computing the Convex Hull in 2D

1 23

4

56

7

8

9

10

11

12

13

14

15

16

17

18

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization:- Push v extremal in l, del. from S.- Angularly sort pts. in S around v.- Push first pt. in l and del. from S.

Advance:While ∃pi ∈ S to be explored:p = last(l); p− = prev(last(l))- If p−ppi is a left turn:

Push pi in l, del. from S.- Else: Pop p from l.

Algorithm 4: Graham’s scan (succesive local repair).

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls9

Computing the Convex Hull in 2D

1 23

4

56

7

8

9

10

11

12

13

14

15

16

17

18

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization:- Push v extremal in l, del. from S.- Angularly sort pts. in S around v.- Push first pt. in l and del. from S.

Advance:While ∃pi ∈ S to be explored:p = last(l); p− = prev(last(l))- If p−ppi is a left turn:

Push pi in l, del. from S.- Else: Pop p from l.

Algorithm 4: Graham’s scan (succesive local repair).

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls9

Computing the Convex Hull in 2D

1 23

4

56

7

8

9

10

11

12

13

14

15

16

17

18

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization:- Push v extremal in l, del. from S.- Angularly sort pts. in S around v.- Push first pt. in l and del. from S.

Advance:While ∃pi ∈ S to be explored:p = last(l); p− = prev(last(l))- If p−ppi is a left turn:

Push pi in l, del. from S.- Else: Pop p from l.

Algorithm 4: Graham’s scan (succesive local repair).

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls9

Computing the Convex Hull in 2D

1 23

4

56

7

8

9

10

11

12

13

14

15

16

17

18

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization:- Push v extremal in l, del. from S.- Angularly sort pts. in S around v.- Push first pt. in l and del. from S.

Advance:While ∃pi ∈ S to be explored:p = last(l); p− = prev(last(l))- If p−ppi is a left turn:

Push pi in l, del. from S.- Else: Pop p from l.

Algorithm 4: Graham’s scan (succesive local repair).

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls9

Computing the Convex Hull in 2D

1 23

4

56

7

8

9

10

11

12

13

14

15

16

17

18

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization:- Push v extremal in l, del. from S.- Angularly sort pts. in S around v.- Push first pt. in l and del. from S.

Advance:While ∃pi ∈ S to be explored:p = last(l); p− = prev(last(l))- If p−ppi is a left turn:

Push pi in l, del. from S.- Else: Pop p from l.

Algorithm 4: Graham’s scan (succesive local repair).

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls9

Computing the Convex Hull in 2D

1 23

4

56

7

8

9

10

11

12

13

14

15

16

17

18

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization:- Push v extremal in l, del. from S.- Angularly sort pts. in S around v.- Push first pt. in l and del. from S.

Advance:While ∃pi ∈ S to be explored:p = last(l); p− = prev(last(l))- If p−ppi is a left turn:

Push pi in l, del. from S.- Else: Pop p from l.

Algorithm 4: Graham’s scan (succesive local repair).

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls9

Computing the Convex Hull in 2D

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization:- Push v extremal in l, del. from S.- Angularly sort pts. in S around v.- Push first pt. in l and del. from S.

Advance:While ∃pi ∈ S to be explored:p = last(l); p− = prev(last(l))- If p−ppi is a left turn:

Push pi in l, del. from S.- Else: Pop p from l.

Running time: O(n log n)

Algorithm 4: Graham’s scan (succesive local repair).

To play:http://animalgo.ist.tugraz.at

O(n log n)

O(n)

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls10

Computing the Convex Hull in 2D

Algorithm 5: Incremental algorithm.

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization: l = p1, p2, p3

Advance: From i = 4 to n, do:If pi lies out of the polygon def. by l:

- Compute the points pl and prof tangency.

- Replace pl, . . . , pr in lwith pl, pi, pr.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls10

Computing the Convex Hull in 2D

Algorithm 5: Incremental algorithm.

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization: l = p1, p2, p3

Advance: From i = 4 to n, do:If pi lies out of the polygon def. by l:

- Compute the points pl and prof tangency.

- Replace pl, . . . , pr in lwith pl, pi, pr.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls10

Computing the Convex Hull in 2D

Algorithm 5: Incremental algorithm.

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization: l = p1, p2, p3

Advance: From i = 4 to n, do:If pi lies out of the polygon def. by l:

- Compute the points pl and prof tangency.

- Replace pl, . . . , pr in lwith pl, pi, pr.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls10

Computing the Convex Hull in 2D

Algorithm 5: Incremental algorithm.

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization: l = p1, p2, p3

Advance: From i = 4 to n, do:If pi lies out of the polygon def. by l:

- Compute the points pl and prof tangency.

- Replace pl, . . . , pr in lwith pl, pi, pr.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls10

Computing the Convex Hull in 2D

Algorithm 5: Incremental algorithm.

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization: l = p1, p2, p3

Advance: From i = 4 to n, do:If pi lies out of the polygon def. by l:

- Compute the points pl and prof tangency.

- Replace pl, . . . , pr in lwith pl, pi, pr.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls10

Computing the Convex Hull in 2D

By storing l in a structure allowingbinary search and updates (insertionsand deletions) in O(log n) time.

Algorithm 5: Incremental algorithm.

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization: l = p1, p2, p3

Advance: From i = 4 to n, do:If pi lies out of the polygon def. by l:

- Compute the points pl and prof tangency.

- Replace pl, . . . , pr in lwith pl, pi, pr.

Running time: O(n log n)

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls11

Computing the Convex Hull in 2D

Algorithm 6: Divide and conquer.

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization: Sort points by x-coord.

Division: Divide the points (xi, yi) intotwo subsets wrt the median x-coord.

Recursion: Recursively compute theconvex hull of the two subsets.

Merge: Compute the external commontangents of the two convex polygons.Discard int. points between tangents.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls11

Computing the Convex Hull in 2D

Algorithm 6: Divide and conquer.

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization: Sort points by x-coord.

Division: Divide the points (xi, yi) intotwo subsets wrt the median x-coord.

Recursion: Recursively compute theconvex hull of the two subsets.

Merge: Compute the external commontangents of the two convex polygons.Discard int. points between tangents.

Question: How to compute the tangentsefficiently?

Question: Are the topmostand bottommost points onthe tangents?

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls11

Computing the Convex Hull in 2D

Algorithm 6: Divide and conquer.

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization: Sort points by x-coord.

Division: Divide the points (xi, yi) intotwo subsets wrt the median x-coord.

Recursion: Recursively compute theconvex hull of the two subsets.

Merge: Compute the external commontangents of the two convex polygons.Discard int. points between tangents.

Question: How to compute the tangentsefficiently?

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls11

Computing the Convex Hull in 2D

Algorithm 6: Divide and conquer.

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization: Sort points by x-coord.

Division: Divide the points (xi, yi) intotwo subsets wrt the median x-coord.

Recursion: Recursively compute theconvex hull of the two subsets.

Merge: Compute the external commontangents of the two convex polygons.Discard int. points between tangents.

Question: How to compute the tangentsefficiently?

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls11

Computing the Convex Hull in 2D

Algorithm 6: Divide and conquer.

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization: Sort points by x-coord.

Division: Divide the points (xi, yi) intotwo subsets wrt the median x-coord.

Recursion: Recursively compute theconvex hull of the two subsets.

Merge: Compute the external commontangents of the two convex polygons.Discard int. points between tangents.

Question: How to compute the tangentsefficiently?

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls11

Computing the Convex Hull in 2D

Algorithm 6: Divide and conquer.

Input: S = p1, . . . , pn.Output: l: ccw points on ∂ conv(S).

Initialization: Sort points by x-coord.

Division: Divide the points (xi, yi) intotwo subsets wrt the median x-coord.

Recursion: Recursively compute theconvex hull of the two subsets.

Merge: Compute the external commontangents of the two convex polygons.Discard int. points between tangents.

O(n log n)

T (n) = 2T(n2

)+O(n)

= O(n log n)

Running time: O(n log n)

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls12

Convex Hulls in 2D: Lower Bound

Input: n real numbersx1, . . . , xn real numbers

Input: n pointsp1, . . . , pn, with pi = (xi, x

2i )

Output: convex hull of the pointsSorted list of the vertices p1, . . . , pn

Output: sorting the numbersSorted list of the numbers x1, . . . , xn

O(n)

O(n)

Ω(n log n)

Ω(n log n)

So, this is it? AreO(n log n) algorithms thebest possible?

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls13

Computing the Convex Hull in 2D

Algorithm 3: Jarvis’ march (gift wrapping). Θ(hn) = O(n2)

Algorithm 6: Divide and conquer.

Algorithm 5: Incremental algorithm.

O(n log n)Algorithm 4: Graham’s scan (succesive local repair).

O(n log n)

O(n log n)

Algorithm 2: Computing the extreme segments by brute force. Θ(n3)

Algorithm 1: Computing the extreme points by brute force. O(n4)

Algorithm 7: Chan’s algorithm. O(n log h)

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls14

Computing the Convex Hull in 2D

Algorithm 7: Chan’s algorithm.

Input: S = p1, . . . , pn, H ≤ n.Output: If there are at most H extremepoints, l: ccw points on ∂ conv(S).

Division:• Divide S into k = dn/He setsS1, . . . , Sk with |Si| ≤ H.

• Construct conv(Si) for all i.

Conquest: Use gift wrapping (Jarvi’smarch) on the small convex hulls tofind the first H points on ∂ conv(S)ccw from the lex. min. point in S.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls14

Computing the Convex Hull in 2D

Algorithm 7: Chan’s algorithm.

Input: S = p1, . . . , pn, H ≤ n.Output: If there are at most H extremepoints, l: ccw points on ∂ conv(S).

Division:• Divide S into k = dn/He setsS1, . . . , Sk with |Si| ≤ H.

• Construct conv(Si) for all i.

Conquest: Use gift wrapping (Jarvi’smarch) on the small convex hulls tofind the first H points on ∂ conv(S)ccw from the lex. min. point in S.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls14

Computing the Convex Hull in 2D

Algorithm 7: Chan’s algorithm.

Input: S = p1, . . . , pn, H ≤ n.Output: If there are at most H extremepoints, l: ccw points on ∂ conv(S).

Division:• Divide S into k = dn/He setsS1, . . . , Sk with |Si| ≤ H.

• Construct conv(Si) for all i.

Conquest: Use gift wrapping (Jarvi’smarch) on the small convex hulls tofind the first H points on ∂ conv(S)ccw from the lex. min. point in S.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls14

Computing the Convex Hull in 2D

Algorithm 7: Chan’s algorithm.

Input: S = p1, . . . , pn, H ≤ n.Output: If there are at most H extremepoints, l: ccw points on ∂ conv(S).

Division:• Divide S into k = dn/He setsS1, . . . , Sk with |Si| ≤ H.

• Construct conv(Si) for all i.

Conquest: Use gift wrapping (Jarvi’smarch) on the small convex hulls tofind the first H points on ∂ conv(S)ccw from the lex. min. point in S.

To see it working:http://chrisgregory.me/

projects/web/chans/

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls14

Computing the Convex Hull in 2D

Algorithm 7: Chan’s algorithm.

Input: S = p1, . . . , pn, H ≤ n.Output: If there are at most H extremepoints, l: ccw points on ∂ conv(S).

Division:• Divide S into k = dn/He setsS1, . . . , Sk with |Si| ≤ H.

• Construct conv(Si) for all i.

Conquest: Use gift wrapping (Jarvi’smarch) on the small convex hulls tofind the first H points on ∂ conv(S)ccw from the lex. min. point in S.

Running time: H ·O(k logH) = O(n logH)

To see it working:http://chrisgregory.me/

projects/web/chans/

O(n logH)For a extremal point we canfind the tangent point qi withone of the k = dn/He sets inO(logH) time.

We can find the next extremalpoint among the qi’s in O(k)time.⇒ Each wrapO(k logH + k) = O(k logH).

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls14

Computing the Convex Hull in 2D

Algorithm 7: Chan’s algorithm.

Input: S = p1, . . . , pn, H ≤ n.Output: If there are at most H extremepoints, l: ccw points on ∂ conv(S).

Running time:O(n logH)

If we knew h, then we could make H = h, but we don’t know h...

We call the algorithm with H = min22t , n for t = 0, 1, . . . until weget the extremal points (wrap around) when t = s.

Total running time:

s∑t=0

cn log 22t

= cns∑t=0

2t = cn(2s+1 − 1) < 4cn log h = O(n log h)

for some constant c.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls15

Computing the Convex Hull in 2D

Algorithm 3: Jarvis’ march (gift wrapping). Θ(hn) = O(n2)

Algorithm 6: Divide and conquer.

Algorithm 5: Incremental algorithm.

O(n log n)Algorithm 4: Graham’s scan (succesive local repair).

O(n log n)

O(n log n)

Algorithm 2: Computing the extreme segments by brute force. Θ(n3)

Algorithm 1: Computing the extreme points by brute force. O(n4)

Algorithm 7: Chan’s algorithm. O(n log h)

Other algorithms: Quick hull.Kirkpatrick–Seidel algorithm (marriage-before-conquest).

O(n2)O(n log h)

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls16

DCEL

• For each vertex v: Its coordinates (x, y, z) An edge e(v) incident to it

• For each face f : An edge e(f) incident to it

• For each (oriented) edge e: Its starting and ending vertices vS(e), vE(e) Its left and right incident faces fL(e), fR(e) Its counterclockwise previous and next edges eP (e), eN (e)

The doubly connected edge list (DCEL), is a data structure torepresent an embedding of a planar graph (and polyhedra).

vS vE

eNfR

fLeP

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls16

DCEL

The doubly connected edge list (DCEL), is a data structure torepresent an embedding of a planar graph (and polyhedra).

vS vE

eNfR

fLeP

Why do we use it?

• Time: Sorted lists of vertices and edges of

any face in time ∝ size of the face. Sorted lists of edges and faces indicent

to any vertex in time ∝ its degree.

• Space: linear in the number of vertices V .

Proof: Since the graph is planar, V + F = E + 2.Since the faces are k-gons (with k ≥ 3), 2E ≥ 3F . Therefore:

2V + 2F = 2E + 4 ≥ 3F + 4 =⇒ F ≤ 2V − 4.

3E + 6 = 3V + 3F ≤ 3V + 2E =⇒ E ≤ 3V − 6.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls17

Convex Hull in 3D

Algorithm: Divide and conquer.

Input: S = p1, . . . , pn.Output: conv(p1, . . . , pn).

Initialization: Sort points by x-coord.

Division: Divide the points into twoequal subsets by a vertical plane.

Recursion: Recursively compute theconvex hull of the two subsets.

Merge: Compute the convex hull of theunion of the convex hulls of the subsets.

O(n log n)

T (n) = 2T(n2

)+O(n)

= O(n log n)

Running time: O(n log n)

We must merge in O(n) time!

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls17

Convex Hull in 3D

Algorithm: Divide and conquer. Running time: O(n log n)

C1 C2

Merging

Notation:

• Faces of C1 and C2 that appearin C are called blue.

• Faces of C1 and C2 that do notappear in C are called red.

• Edges and vertices are coloredwith the intersection color (blue,red and purple) of their incidentfaces.

C

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls17

Convex Hull in 3D

Algorithm: Divide and conquer. Running time: O(n log n)

Merging

Careful!

• Purple might not be connected.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls17

Convex Hull in 3D

Algorithm: Divide and conquer. Running time: O(n log n)

Merging

Careful!

• Purple might not be connected.a

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls17

Convex Hull in 3D

Algorithm: Divide and conquer. Running time: O(n log n)

Merging

Careful!

• Purple might not be connected.• There might be no blue faces.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls17

Convex Hull in 3D

Algorithm: Divide and conquer. Running time: O(n log n)

Merging

Careful!

• Purple might not be connected.• There might be no blue faces.

p

q

Edge pq is incident to two red faces.

Vertex p is incident to more thantwo purple edges.

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls17

Convex Hull in 3D

Algorithm: Divide and conquer. Running time: O(n log n)

C1 C2

Merging

h0

Convex polygon C0.

Merging algorithm:

• Find an edge of C \ C1 ∪ C2.• Find the remaining new faces

and edges in the order inducedby C0.

• Identify the red faces, edges andvertices and update the DCEL.

C

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls18

Convex Hull of a Simple Polygon

Given a simple polygon with n vertices, how fast can we compute itsconvex hull?

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls18

Convex Hull of a Simple Polygon

Given a simple polygon with n vertices, how fast can we compute itsconvex hull?

Exercise: Does Graham scan work for a simple polygon using theorder of its vertices?

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls19

Convex Hull of a Simple Polygon

Given a simple polygon with n vertices, we can compute its convexhull in O(n) time.

• 1972 Sklansky: Incorrect.• 1975 Shamos: Incorrect.• 1979 McCallum, Avis: Correct.• 1980 Kim: Incorrect.• 1982 Sklansky: Incorrect.• 1983 Lee: Correct.• 1983 Graham, Yao: Correct.• 1983 ElGindy, Avis, Toussaint: Correct.• 1983 Ghosh, Shyamasundar : Incorrect.

• 1984 Bhattacharya,ElGindy: Correct.

• 1985 Preparata, Shamos:Correct.

• 1985 Orlowski: Correct.• 1986 Shin, Woo: Correct.• 1986 Werner: Incorrect.• 1987 Melkman: Correct.• 1989 Chen: Incorrect.

(From http://http://cgm.cs.mcgill.ca/ athens/cs601/)

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls19

Convex Hull of a Simple Polygon

Given a simple polygon with n vertices, we can compute its convexhull in O(n) time.

• 1972 Sklansky: Incorrect.• 1975 Shamos: Incorrect.• 1979 McCallum, Avis: Correct.• 1980 Kim: Incorrect.• 1982 Sklansky: Incorrect.• 1983 Lee: Correct.• 1983 Graham, Yao: Correct.• 1983 ElGindy, Avis, Toussaint: Correct.• 1983 Ghosh, Shyamasundar : Incorrect.

• 1984 Bhattacharya,ElGindy: Correct.

• 1985 Preparata, Shamos:Correct.

• 1985 Orlowski: Correct.• 1986 Shin, Woo: Correct.• 1986 Werner: Incorrect.• 1987 Melkman: Correct.• 1989 Chen: Incorrect.

It is an on-line algorithm!Let’s see how it works:https://maxgoldste.in/melkman/

Irene Parada Discrete and Computational Geometry 2019. Convex Hulls19

Convex Hull of a Simple Polygon

Given a simple polygon with n vertices, we can compute its convexhull in O(n) time.

• 1972 Sklansky: Incorrect.• 1975 Shamos: Incorrect.• 1979 McCallum, Avis: Correct.• 1980 Kim: Incorrect.• 1982 Sklansky: Incorrect.• 1983 Lee: Correct.• 1983 Graham, Yao: Correct.• 1983 ElGindy, Avis, Toussaint: Correct.• 1983 Ghosh, Shyamasundar : Incorrect.

• 1984 Bhattacharya,ElGindy: Correct.

• 1985 Preparata, Shamos:Correct.

• 1985 Orlowski: Correct.• 1986 Shin, Woo: Correct.• 1986 Werner: Incorrect.• 1987 Melkman: Correct.• 1989 Chen: Incorrect.

Exercise: Can we compute the convex hull of a monotone polygon ino(n) time? Design an optimal-time algorithm.