Slide - Geometric Computing Lab

advertisement

[CS504 Presentation]

Planar Convex Hull

2013 / 5 / 9

Group 4

Sungheon Park

Jeongho Son

CS504 Presentation

Contents

• Definition of convex hull

• Bruteforce algorithm

• Graham’s scan

• Divide and conquer

• Quickhull

• Jarvis’ method

CS504 Presentation

What is convex hull?

• Let S be a set of points in the plane.

• Intuition: Imagine the points of S as being pegs; the convex hull of S is the shape of a rubber-band stretched around the pegs.

CS504 Presentation

What is convex hull?

• Formal definition: the convex hull of S is the smallest convex polygon that contains all the points of S

• Convexity : A set

𝑆 is

convex

given any points 𝑝, π‘ž ∈ 𝑆 any if convex combination of p and q is in

𝑆

, or equivalently, the line segment π‘π‘ž ⊆ 𝑆

.

CS504 Presentation

Applications of convex hull computer visualization, ray tracing path finding

Geographical Information Systems (GIS) Visual pattern matching

CS504 Presentation

Orientation test

• Given a triplet π‘₯

1

, 𝑦

1

, 𝑝

π‘‚π‘Ÿπ‘–π‘’π‘›π‘‘ 𝑝

2

1

= π‘₯

, 𝑝

2

, 𝑝

2

3

(𝑝

1

, 𝑦

2

, 𝑝

2

,

, 𝑝

3 𝑝

3

) of three points

= π‘₯

3 𝑝

1

= in the plane, is defined as

, 𝑦

3

= π‘₯

1 𝑦

π‘‚π‘Ÿπ‘–π‘’π‘›π‘‘ 𝑝

1

2

− π‘₯

2 𝑦

1

, 𝑝

2

, 𝑝

+ π‘₯

3 𝑦

1

3

=

− π‘₯

1 π‘₯

1 π‘₯

2 π‘₯

3 𝑦

3 𝑦

1 𝑦

2 𝑦

3

+ π‘₯

2 𝑦

3

1

1

1

− π‘₯

3 𝑦

2

• π‘‚π‘Ÿπ‘–π‘’π‘›π‘‘ 𝑝

1

, 𝑝

2

, 𝑝

3

• π‘‚π‘Ÿπ‘–π‘’π‘›π‘‘ 𝑝

1

, 𝑝

2

, 𝑝

3

• π‘‚π‘Ÿπ‘–π‘’π‘›π‘‘ 𝑝

1

, 𝑝

2

, 𝑝

3

>0 : oriented counterclockwise

=0 : collinear

<0 : oriented clockwise

CS504 Presentation

Graham’s Scan

• 𝑂 𝑛 log 𝑛 algorithm

• Points are added one at a time, and structure is updated on each new insertion.

CS504 Presentation

Graham’s Scan

• Algorithm

1. Sort the points according to increasing order of their π‘₯

-coordinates, denoted 𝑝

1

, 𝑝

2

, … , 𝑝 𝑛

.

2. Push 𝑝

1 and then

3. for 𝑖 = 3 to 𝑛 do: 𝑝

2 onto stack

𝐻

.

while( 𝑠𝑖𝑧𝑒(𝐻) ≥ 2 and

π‘‚π‘Ÿπ‘–π‘’π‘›π‘‘(𝑝 𝑖

, 𝐻 π‘“π‘–π‘Ÿπ‘ π‘‘

, 𝐻 π‘ π‘’π‘π‘œπ‘›π‘‘

) ≤ 0

) pop

𝐻

.

Push 𝑝 𝑖 onto

𝐻

CS504 Presentation

Graham’s Scan

Analysis

– Sorting :

𝑂 𝑛 log 𝑛

– Let 𝑑 𝑖 the number of points that are popped on processing 𝑝 𝑖

, the amount of time spent processing 𝑝 𝑖 is

𝑂(𝑑 𝑖

+ 1) 𝑛 𝑛 𝑑 𝑖

+ 1 = 𝑛 + 𝑑 𝑖 𝑖=1 𝑖=1 𝑛 𝑖=1 𝑑 𝑖 is bounded by

𝑂(𝑛) since each of the 𝑛 points is pushed onto the stack once.

Total time complexity is

𝑂 𝑛 log 𝑛

CS504 Presentation

Original Graham’s scan

• Initially, points are sorted in increasing angular value

• If the point is not convex (concave), it removes the current point from the perimeter list

CS504 Presentation

Divide-and-Conquer

• 𝑂 𝑛 log 𝑛 algorithm

• Recursively compute convex hulls, and merge two hulls by computing upper and lower tangent

CS504 Presentation

Divide-and-Conquer

Algorithm finding lower tangent

LowerTangent(

𝐻

𝐴

,

𝐻

𝐡

) :

(1) Let a be the rightmost point of

𝐻

𝐴

(2) Let b be the leftmost point of

𝐻

𝐡

.

.

(3) While (ab is not a lower tangent for

𝐻

𝐴 and

(a) While (ab is not a lower tangent to

𝐻

𝐴

𝐻

𝐡

) do

) move a clockwise

(b) While (ab is not a lower tangent to

𝐻

𝐡

(4) Return ab.

) move b counterclockwise

• Can be done in

𝑂 π‘š , where π‘š = 𝐻

𝐴

• Overall algorithm runs 𝑂 𝑛 log 𝑛 time.

+ |𝐻

𝐡

|

.

CS504 Presentation

Quickhull

• 𝑂 𝑛 2 in worst case, but shows better performance in most cases

• Discard points that are not on the hull as quickly as possible.

• Begin with the quadrilateral which connects maximum and minimum x,y coordinates

CS504 Presentation

Quickhull

• Find a point 𝑐 that lies on the hull, and connect π‘Žπ‘ and 𝑏𝑐

• Eliminate the points inside hull, and recursively process for the remaining points.

• Performance depends on the distribution of the points, and how a point 𝑐 is selected

CS504 Presentation

Quickhull

Analysis

– 𝑇 𝑛 =

𝑇 𝑛

1

1

+ 𝑇 𝑛

2 𝑖𝑓 𝑛 = 1 π‘€β„Žπ‘’π‘Ÿπ‘’ 𝑛

1

+ 𝑛

2

≤ 𝑛

– If max 𝑛

1

, 𝑛

2

≤ 𝛼𝑛 for some 𝛼 ≤ 1

, then the running time will be

𝑂 𝑛 log 𝑛

– Performance depends on the distribution of the points, and how a point 𝑐 is selected

CS504 Presentation

Jarvis’s March

• Build the hull using “gift wrapping” process

CS504 Presentation

Jarvis’s March

• Algorithm

1. Begins with 𝑖 = 0 and pick 𝑝

0 which is known to be on convex hull (e.g. the leftmost point)

2. Pick the point 𝑝 𝑖 between 𝑝 𝑖−2 system) 𝑝 𝑖−1 which minimize the angle and 𝑝 𝑖−1 𝑝 𝑖

.(Use polar coordinate

3. Repeat step 2 until 𝑝 𝑖

= 𝑝

0

.

CS504 Presentation

Jarvis’s March

Analysis

– Find the point that maximize angle in

𝑂(𝑛)

– Number of vertices on convex hull : β„Ž

– Total time complexity :

𝑂(π‘›β„Ž)

⇒ Output-sensitive algorithm

CS504 Presentation

Applet

• Java applet

– http://www.cse.unsw.edu.au/~lambert/java/3 d/hull.html

– http://www.cs.princeton.edu/courses/archive/ spr09/cos226/demo/ah/JarvisMarch.html

CS504 Presentation

Chan’s algorithm

Jeongho Son

CS504 Presentation

Planar Convex Hull

• Graham’s Scan :

𝑂(𝑛 log 𝑛)

• Jarvis’s March :

𝑂(π‘›β„Ž)

• Is there any

𝑂(𝑛 log β„Ž) algorithm?

CS504 Presentation

Chan’s Algorithm

• Chan’s algorithm

– combining Graham’s scan and Jarvis’s March together

– 𝑂 𝑛 log β„Ž

• 3 stages of Chan’s algorithm

1. divide vertices into partition s

2. apply Graham’s scan on each partition

3. apply Jarvis’s March on the small convex hull

(repeat 1~3 until we find the hull)

CS504 Presentation

Chan’s Algorithm

• Stage1 : Partition

• Consider arbitrary value π‘š < 𝑛

, the size of partition

– how to decide π‘š will be treated later

• Partition the points into groups, each of size π‘š

– π‘Ÿ = 𝑛 π‘š is the number of groups

CS504 Presentation

Chan’s Algorithm

• Stage 1

CS504 Presentation n = 32

Set m = 8

Chan’s Algorithm

• Stage 1

CS504 Presentation n = 32

Set m = 8 r = 4

Chan’s Algorithm

• Stage2 : Graham’s Scan

• Compute convex hull of each partition using Graham’s scan

• Total

𝑂(𝑛 log π‘š) time

CS504 Presentation

Chan’s Algorithm

• Stage 2

CS504 Presentation

(After Stage 1) m = 8 r = 4

Chan’s Algorithm

• Stage 2

Using Graham’s Scan

O π‘š log π‘š for each group

-> total

𝑂(π‘šπ‘Ÿ log π‘š)

=

𝑂(𝑛 log π‘š)

CS504 Presentation

Chan’s Algorithm

• Stage3 : Jarvis’s March

• How to merge these r hulls into a single hull?

• IDEA : treat each hull as a “ fat point ” and run Jarvis’s

March!

• # of iteration is at most m

– to guarantee the time complexity O(nlogh)

CS504 Presentation

Chan’s Algorithm

• (-inf,0) -> lowest pt

(−∞, 0) lowest pt

CS504 Presentation

Chan’s Algorithm

• Find the point that maximize the angle in each hull

(−∞, 0)

1 lowest pt

CS504 Presentation

Chan’s Algorithm

• Find the point that maximize the angle in each hull

(−∞, 0)

2

1 lowest pt

CS504 Presentation

Chan’s Algorithm

• Find the point that maximize the angle in each hull

3

(−∞, 0)

2

1 lowest pt

CS504 Presentation

Chan’s Algorithm

If π‘š < β„Ž

, then the algorithm will fail!

CS504 Presentation

Chan’s Algorithm

• FAIL EXAMPLE – too small value m

(−∞, 0) m = 4

4 iteration

CS504 Presentation

Chan’s Algorithm

In 4(a), how to find such points?

CS504 Presentation

Chan’s Algorithm

• Find the point that maximize the angle in each hull

(−∞, 0)

1 lowest pt

CS504 Presentation

Chan’s Algorithm

• Find the point that maximize the angle in a hull

(−∞, 0)

CS504 Presentation

Chan’s Algorithm

• Finding tangent between a point and a convex π‘š

-gon

5

1

𝑂 log π‘š process

4

3

2

CS504 Presentation

Chan’s Algorithm

→ 𝑂(log π‘š)

CS504 Presentation

Chan’s Algorithm

Analysis

• Suppose God told you some good value for π‘š

– β„Ž ≤ π‘š ≤ β„Ž 2

• 𝑂 𝑛 log π‘š for stage1~2

• At most h steps in Jarvis’s March

– 𝑂(log π‘š) time to compute each tangent

– π‘Ÿ tangent for each iteration

– total

𝑂 β„Žπ‘Ÿ log π‘š = 𝑂(β„Ž 𝑛 π‘š log π‘š) time

• 𝑂 𝑛 + β„Ž 𝑛 π‘š log π‘š = 𝑂 𝑛 log π‘š = 𝑂(𝑛 log β„Ž) as desired. π‘š ≤ β„Ž 2

CS504 Presentation

Chan’s Algorithm

• The only question remaining is… how do we know what value to give to π‘š

?

CS504 Presentation

Chan’s Algorithm

• Answer : square search

• Try this way π‘š = 2, 4, 8, … , 2 2 𝑑

, …

• Then we eventually get π‘š to be in

[β„Ž, β„Ž 2 ]

!

CS504 Presentation

Chan’s Algorithm

• The algorithm stops as soon as

2 2 𝑑

– 𝑑 = lg lg β„Ž

≥ β„Ž

• Total time complexity lg lg β„Ž lg lg β„Ž 𝑛 log 2 2 𝑑

= 𝑛2 𝑑 ≤ 𝑛 2 1+lg lg β„Ž = 2𝑛 2 lg lg β„Ž 𝑑=1 𝑑=1

= 2𝑛 log β„Ž = 𝑂(𝑛 log β„Ž)

CS504 Presentation

Lower bound for convex hull

• 𝑂(𝑛 log 𝑛)

• Reduction from the sorting problem n points in the x-axis

CS504 Presentation

Lower bound for convex hull

• 𝑂(𝑛 log 𝑛)

• Reduction from the sorting problem 𝑦 = π‘₯

2 lifting up to 2D plane

CS504 Presentation

Lower bound for convex hull

• 𝑂(𝑛 log 𝑛)

• Reduction from the sorting problem lower convex hull

CS504 Presentation

Quiz

• Show that the convex hull of n points in the plane can be computed in

𝑂(𝑛) time if each coordinate of each point is a rational number of the form 𝑝 π‘ž

, with bounded values for 𝑝 and π‘ž

.

– hint: don’t use comparison-based sort!

CS504 Presentation

Quiz

• Solution

Instead of comparison-based sort, using radix sort

→ 𝑂(𝑛)

And apply Graham’s scan algorithm.

CS504 Presentation

Summary

• Finding the convex hull of a set of points is an important problem that is often part of a larger problem

• Many different algorithms

– Graham’s Scan

– Quickhull

– Divide-and-Conquer

– Jarvis’s March

– Chan’s algorithm

CS504 Presentation

Q&A

Any question?

CS504 Presentation

Download