[CS504 Presentation]
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
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
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
•
– 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
•
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
•
– π π =
π π
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
•
– Find the point that maximize angle in
π(π)
– Number of vertices on convex hull : β
– Total time complexity :
π(πβ)
⇒ Output-sensitive algorithm
CS504 Presentation
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
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
CS504 Presentation