Slide - Geometric Computing Lab
Download
Report
Transcript Slide - Geometric Computing Lab
[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 if
given any points 𝑝, 𝑞 ∈ 𝑆 any
convex combination of p and q
is in 𝑆, or equivalently, the line
segment 𝑝𝑞 ⊆ 𝑆.
CS504 Presentation
Applications of convex hull
computer visualization, ray tracing
Geographical Information Systems (GIS)
path finding
Visual pattern matching
CS504 Presentation
Orientation test
• Given a triplet (𝑝1 , 𝑝2 , 𝑝3 ) of three points 𝑝1 =
𝑥1 , 𝑦1 , 𝑝2 = 𝑥2 , 𝑦2 , 𝑝3 = 𝑥3 , 𝑦3 in the plane,
𝑂𝑟𝑖𝑒𝑛𝑡 𝑝1 , 𝑝2 , 𝑝3 is defined as
𝑥1 𝑦1 1
𝑂𝑟𝑖𝑒𝑛𝑡 𝑝1 , 𝑝2 , 𝑝3 = 𝑥2 𝑦2 1
𝑥3 𝑦3 1
= 𝑥1 𝑦2 − 𝑥2 𝑦1 + 𝑥3 𝑦1 − 𝑥1 𝑦3 + 𝑥2 𝑦3 − 𝑥3 𝑦2
• 𝑂𝑟𝑖𝑒𝑛𝑡 𝑝1 , 𝑝2 , 𝑝3 >0 : oriented counterclockwise
• 𝑂𝑟𝑖𝑒𝑛𝑡 𝑝1 , 𝑝2 , 𝑝3 =0 : collinear
• 𝑂𝑟𝑖𝑒𝑛𝑡 𝑝1 , 𝑝2 , 𝑝3 <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 𝑝2 onto stack 𝐻.
3. for 𝑖 = 3 to 𝑛 do:
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 𝐻𝐵 ) do
(a) While (ab is not a lower tangent to 𝐻𝐴 ) move a clockwise
(b) While (ab is not a lower tangent to 𝐻𝐵 ) move b counterclockwise
(4) Return ab.
• 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 𝑝𝑖 which minimize the angle
between 𝑝𝑖−2 𝑝𝑖−1 and 𝑝𝑖−1 𝑝𝑖 .(Use polar coordinate
system)
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.
2.
3.
divide vertices into partitions
apply Graham’s scan on each partition
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
n = 32
Set m = 8
CS504 Presentation
Chan’s Algorithm
• Stage 1
n = 32
Set m = 8
r=4
CS504 Presentation
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
(After Stage 1)
m=8
r=4
CS504 Presentation
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
m=4
(−∞, 0)
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
2, 4, 8, … , 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 ℎ
𝑡
2
𝑛 log 2
𝑡=1
𝑛2𝑡 ≤ 𝑛 21+lg lg ℎ = 2𝑛 2lg lg ℎ
=
𝑡=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