cs6234 16 Convexhull
cs6234 16 Convexhull
Shen Shiqi
Polar angle
In the plane, the polar angle θ is the counterclockwise angle from x-axis
at which a point in the x-y plane lies.
Orientation
b
• Calculating Orientation
CW
• Three kinds of orientation for three c
a
points (a, b, c)
• If △(a,b,c)>0 ⇒ counterclockwise
Why?
• Cross product
• Direction: right hand rule
is the scalar of
• Magnitude: the area of
the parallelogram that the
vectors span
Convexity
A shape or set is convex :
If for any two points that are part of the shape, the whole connecting
line segment is also part of the shape.
convex non-convex
Convex hull
Convex hull of a point set P, CH(P):
• Smallest convex set containing P
b
a
• Intersection of all convex sets containing P c
i
h
m d
g
k j
f
e
Convex hull problem
Give an algorithm that computes the convex hull of any given set of n
points in the plane efficiently.
3 4
5
7
O(n2*n)=O(n3)
Graham's Scan and Jarvis March
Wang Guanhua
Graham's Scan Algorithm
sorting order.
• Angle can be calculated by 1
vector cosine law 0 X
Step3: Push first 3 points
0
Next -to -top[S]
7 4
5
3
2
0
Complexity of Graham’s Scan
Phase 1: select a start
point O(n)
Phase 2: Sorting
O(n*log n)
Phase 3: O(n)
7 4
5
3
2
8
1
0
Jarvis March
Find an extreme point
0
Collinear
6
0
6
0
6
0
6
0
Time complexity
Order of n
Order of h
h : The number of points on convex hull
Himeshi De Silva
Chan’s algorithm
• Aims to improve the time complexity to a better value than that of
Graham’s Scan and Jarvis March
• Output sensitive
Key idea: The wrapping step of the Jarvis March can be made faster by
performing some preprocessing on the points
Chan’s algorithm
P - a set of n ≥
3 points in 2D
Chan’s algorithm: Phase 1
Chan’s algorithm: Phase 2
8) 7) p1
p1
p0
p0
Chan’s algorithm: Example
Phase 1
n = 20
m=5
Chan’s algorithm: Example
p1
p0
Chan’s algorithm: Example
p1
p0
Chan’s algorithm: Example
p2
p1
p0
Chan’s algorithm: Example
p3
p2
p1
Chan’s algorithm: Example
p3
p4 p2
p5
p1
The wrapping
must happen h p6
times
p8
p7
Selecting H
When
Time complexity of Chan’s algorithm
This procedure stops with the list of hull vertices as soon as the value
of H in the for-loop reaches or exceeds h.
Guo Qi
Correctness of Graham’s Scan
The correctness of Graham’s scan lies in two situations.
● Part 1 deals with nonleft turns;
pj
pj
pk pk
p2
... ...
p1 p1 p1
p0 p0 p0
Correctness of Graham’s Scan
Proof (cont’d): Note stack changes in two ways:
Case i: When points are popped from the stack S.
Case ii: When points are pushed onto the
stack S.
... ...
p1 p1
p0 p0
Correctness of Graham’s Scan
Claim 2: Each point popped from the stack is not a vertex of CH(P) and lies
inside new convex hull.
pk pk pk
p1 p1 p1
p0 p0 p0
Correctness of Graham’s Scan
Conclusion
pi
pk Proof (by contradiction):
Chen Zhenghai
Correctness of Chan’s Algorithm
Proof:
This algorithm preprocesses the input points and then uses Jarvis March to find
the convex hull.
Both algorithms have the same starting points: visual point and leftmost point.
Every iteration, it gets the same point as Jarvis March gets. (Assume that H is big
enough)
Thus speed up
Applications
● Shortest path
2 30 20
Two ingredients: A and B
3 35 40
B
Applications
● Hand tracking
https://www.youtube.com/watch?v=e
HLHNaGQUos
Appendix
Divide & Conquer
hull(S) = smallest convex set that contains S (points are stored in ccw order)
1. Sort all points of S with increasing x-coordinates
2. Algorithm conv(S, n)
if n < 4, then trivially solved
else
DIVIDE: Sl & Sr
RECUR: conv(Sl, n/2), conv(Sr, n/2)
MERGE: combine hull(Sl) and hull(Sr)
Divide & Conquer
Algorithm conv(S, n)
if n < 4, then trivially solved
else
DIVIDE: Sl & Sr
RECUR: conv(Sl, n/2), conv(Sr, n/2)
MERGE: combine hull(Sl) and hull(Sr)
Divide & Conquer
Algorithm conv(S, n)
if n < 4, then trivially solved
else
DIVIDE: Sl & Sr
RECUR: conv(Sl, n/2), conv(Sr, n/2)
MERGE: combine hull(Sl) and hull(Sr)
Sl Sr
Divide & Conquer
Algorithm conv(S, n) upper bridge
if n < 4, then trivially solved
else
DIVIDE: Sl & Sr
RECUR: conv(Sl, n/2), conv(Sr, n/2)
MERGE: combine hull(Sl) and hull(Sr)
lower bridge
Divide & Conquer
u : rightmost of hull(Sl)
succ(u) pred(v)
v : leftmost of hull(Sr)
u
succ : next point in ccw
v
prec : next point in cw pred(u)
w
Divide & Conquer
Procedure Find-lower-Bridge
u : rightmost of hull(Sl)
u
v : leftmost of hull(Sr)
v
while either pred(u) or succ(v) lies below uv
if pred(u) lies below then u:=pred(u)
else v = succ(v)
endwhile
return uv
Divide & Conquer
Procedure Find-lower-Bridge
u : rightmost of hull(Sl)
u
v : leftmost of hull(Sr)
v
while either pred(u) or succ(v) lies below uv u
endwhile
return uv
Divide & Conquer
Procedure Find-lower-Bridge
u : rightmost of hull(Sl)
v : leftmost of hull(Sr)
v
while either pred(u) or succ(v) lies below uv
if pred(u) lies below then u:=pred(u)
else v = succ(v) u v
endwhile
return uv
Divide & Conquer
Procedure Find-lower-Bridge
u : rightmost of hull(Sl)
v : leftmost of hull(Sr)
while either pred(u) or succ(v) lies below uv
if pred(u) lies below then u:=pred(u)
else v = succ(v) u v
lower bridge
Divide & Conquer
T(n) = 2T(n/2) + cn upper bridge
2T(n/2): Recursion
cn: Combine conv(Sl) and conv(Sr)
Master theorem
Easily calculate the running time without
doing an expansion
lower bridge
Divide & Conquer
T(n) = 2T(n/2) + cn
a=2, b=2
f(n) = cn ∈ ⊝(n)
d=1