0% found this document useful (0 votes)
9 views96 pages

cs6234 16 Convexhull

The document discusses convex hulls, defining them as the smallest convex set containing a given set of points. It presents three algorithms for computing convex hulls: Graham's Scan, Jarvis March, and Chan's algorithm, detailing their steps, complexities, and proofs of correctness. Applications and properties of convex shapes are also explored, emphasizing the significance of orientation and convexity in the algorithms.

Uploaded by

Anant Nimkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views96 pages

cs6234 16 Convexhull

The document discusses convex hulls, defining them as the smallest convex set containing a given set of points. It presents three algorithms for computing convex hulls: Graham's Scan, Jarvis March, and Chan's algorithm, detailing their steps, complexities, and proofs of correctness. Applications and properties of convex shapes are also explored, emphasizing the significance of orientation and convexity in the algorithms.

Uploaded by

Anant Nimkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 96

Convex Hulls

Guo Qi, Chen Zhenghai, Wang Guanhua, Shen


Shiqi, Himeshi De Silva
Outline
• Introduction: Background & Definition of convex hull
• Three algorithms
• Graham’s Scan
• Jarvis March
• Chan’s algorithm
• Proof of these algorithms
• Application
Introduction

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)

• Clockwise (CW): right turn c


CCW
• Counterclockwise (CCW): left turn b
a
• Collinear (COLL): no turn
• The orientation can be characterized by
the sign of the determinant △(a,b,c)
c
• If △(a,b,c)<0 ⇒ clockwise b COLL
a
• If △(a,b,c)=0 ⇒ collinear

• 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.

• Inputs: location of n points

• Outputs: a convex polygon ⇒ a sorted sequence of the points,


clockwise (CW) or counterclockwise (CCW) along the boundary
inputs= a set of point
p1,p2,p3,p4,p5,p6,p7,p8,p9

outputs= representation of the convex hull


p4,p5,p8,p2,p9
How to develop an algorithm?
Properties:
a
• The vertices of the convex hull b

are always points from the


c
input
• The supporting line of any f
d
convex hull edge has all e
input points to one side
Simple method
1

3 4
5
7

O(n2*n)=O(n3)
Graham's Scan and Jarvis March
Wang Guanhua
Graham's Scan Algorithm

Step 1. Find the lowest point p (guaranteed to be in)


Step 2. Sort points around p (in polar angle) in increasing
angle
Step 3. Walk around to remove concave angle.
(keep points with left turns, & drop those with right turns)
Graham's Scan
Step1: Select a start point

• Select a extreme point as a start


point with the minimum y-
coordinate.

• If there are more than one points


have minimum y-coordinate, select
the leftmost one.

Start point: with minimum y-coordinate and


leftmost
Step 2: Sort points by Ypolar angle
• Sort the points by polar angle in
counterclockwise order. 6
• If more than one point has the
same angle, remove all but the 7 4
one that is farthest from the 5
3
start point.
• This algorithm will work in this 2

sorting order.
• Angle can be calculated by 1
vector cosine law 0 X
Step3: Push first 3 points

• Add first 3 points into the result 6


set.
Let S be the result set. 7 4
• Push(p0, S) 5
3
• Push(p1, S)
• Push(p2, S) 2

Stack S: <p0, p1, p2>


Step4: Work around all points by sorting
order

• 1->2->3 is left turn. 6


• Push (p3, S)
7 4
5
3
top[S]
2

0
Next -to -top[S]

Stack S: <p0, p1, p2>


Step4: Work around all points by sorting
order Y

• 2->3->4 is left turn. 6


• Push (p4, S)
7 4
5
3
2

Stack S: <p0, p1, p2, p3>


Step4: Work around all points by sorting
order Y

• 3->4->5 is left turn. 6


• Push (p5, S)
7 4
5
3
2

Stack S: <p0, p1, p2, p3, p4>


Step4: Work around all points by sorting
order
• 4->5->6 is non-left turn. 6
• Pop (p5, S)
7 4
5
3
2

Stack S: <p0, p1, p2, p3, p4, p5>


Step4: Work around all points by sorting
order

• 3->4->6 is non-left turn. 6


• Pop (p4, S)
7 4
5
3
2

Stack S: <p0, p1, p2, p3, p4>


Step4: Work around all points by sorting
order
Collinear

• 2->3->6 is non-left turn. 6


• Pop (p3, S)
7 4
5
3
2

Stack S: <p0, p1, p2, p3>


Step4: Work around all points by sorting
order

• 2->6->7 is left turn. 6


• Push (p6, S)
7 4
5
3
2

Stack S: <p0, p1, p2>


Step4: Work around all points by sorting
order

• 6->7->0 is left turn. 6


• Push (p7, S)
7 4
5
3
2

Set S: <p0, p1, p2, p6, p7>


• Finally, we get a Convex hull. 6

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)

● Each point is inserted into


the sequence exactly
once, and
● Each point is removed
from the sequence at
most once
O(n*logn)
Jarvis March
Also named as Gift Wrapping
6

7 4
5
3
2
8
1

0
Jarvis March
Find an extreme point

Choose a leftmost point as 6


start point, if there are more
than one points, choose the 7 4
5
point with minimum y- 3
coordinate. 2
8
1

Leftmost point with minimum y


coordinate
Jarvis March
Y

● Find a next point P that 6


virtual point, start point and
this point can form the 7 4
biggest angle. 5
3

● pv, p0, p7 form the biggest 2


8
angle. 1

virtual point pv (0, -∞)


6

● Point 6 forms the biggest


angle with point 7 and 0 7 4
5
3
2
8
1

0
Collinear
6

● Point 2 forms the biggest


angle with point 6 and 7. 7 4
5
3
2
8 Farthest
1

0
6

● Point 1 forms the biggest


angle with point 2 and 6. 7 4
5
3
2
8
1

0
6

● Point 0 forms the biggest


angle with point 2 and 1. 7 4
5
3
2
8
1

0
6

● It returns to start point 0,


the algorithm ends here. 7 4
5
3
2
8
1

0
Time complexity

Order of n

Order of h
h : The number of points on convex hull

Time complexity: O(nh)


Graham Scan vs. Jarvis March
• Time complexity of Jarvis March not necessarily
worse than Graham’s scan

Is better in the case of small h (h < logn)

• Which to use depends on,


The application

What usually happens in practice


Chan’s algorithm

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

The wrapping is done H


times

The algorithm will only return the convex hull when H ≥ h

Therefore how can the desired answer be obtained?


Selecting H
Since the value of h is not known in advance, we use a sequence of
H's to "guess" its value
Time complexity of Chan’s algorithm
Time complexity of Chan’s algorithm

Because this is done


up to h times,
Time complexity of Chan’s algorithm

Since h is H in the algorithm

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.

Therefore the number of iterations of the loop is

The tth iteration of the loop takes

Therefor the total time complexity is,


Algorithms Correctness

Guo Qi
Correctness of Graham’s Scan
The correctness of Graham’s scan lies in two situations.
● Part 1 deals with nonleft turns;

● Part 2 deals with left turns.


Claim 1: The points on stack always form the vertices of a convex polygon.

Proof: The claim holds


immediately after line 5.
p2
Points p0, p1, and p2 form a
p1
triangle.
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.

Case i. Here we rely on the geometric property: If a


vertex is removed from a convex polygon, then the
resultingp polygon is convex.
p
i k

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.

Case ii. If pi is pushed onto the stack:


● By the choice of p0 and p1, pi lies above the
extension of the line p0p1.
● By the fact, a left turn occurs at pj, pi lies below pi
the extension of the line joining p k and pj.
p pj
● By the order of polar angle, pi lies left of the line
j

joining p0 and pj. p


k pk

... ...

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.

Proof: Suppose that point pj is popped from the stack because


angle pkpjpi makes a nonleft turn as shown in the figure.

Since points are ordered in increasing polar angle around anchor


p0, there exists a triangle Δp0pipk with pj either in the interior of the
triangle or on the line segment joining p i and pk. In either case,
point pj cannot be a vertex of CH(P). pj pi

pk pk pk

... ... ...

p1 p1 p1

p0 p0 p0
Correctness of Graham’s Scan
Conclusion

Since each point popped from the stack is not a


vertex of CH(P) (by Claim 2). And the points on
stack always form the vertices of a convex
polygon (by Claim 1). Therefore, Graham’s Scan
is correct.
Correctness of Jarvis March
Jarvis March relies on the following two facts:

1. The leftmost point must be one vertex of


the convex hull;

2. If point p is a vertex of the convex hull,


then the points furthest clockwise and
counterclockwise are also vertices of the
convex hull.
Correctness of Jarvis March
If point p is a vertex of the convex hull, then p’s furthest counterclockwise is also a
vertex of the convex hull.

pi
pk Proof (by contradiction):

pj W.L.O.G, consider the case at pi .


Then, pk is the furthest counterclockwise.

p2 Suppose pk is not a vertex of the convex hull. However, since pi is a


vertex of the convex hull, it must connect with one other vertex.
p1
p0 In this case, vertices will fall on two sides of the edge. Contradiction!
Correctness of Jarvis March
Conclusion

Since we start at a vertex which must be one of


the convex hull (the leftmost vertex). And each
iteration we add a vertex which must be one of
the convex hull (the counterclockwise of current
vertex).
Since the convex hull has at most h vertices.
Thus, Jarvis March is correct.
Algorithms Correctness and Application

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)

So it is correct because Jarvis March is correct.


Applications
● Fast collision detection

Costly exact collision detection

Need to handle 2 polygons with


18 vertices even if they stay far away
from each other
Applications
● Fast collision detection

If compute convex hull

Handle 2 polygons with 10 vertices

Failing convex hull intersection test


means two objects definitely don't
collide and we can skip the costly
exact collision detection step.

Thus speed up
Applications
● Shortest path

Computing the convex hull of all points


(including s and t).

In order to get from s to t, the shortest


path will either be the straight line from s
to t (if the obstacle doesn't intersect it)
or one of the two polygonal chains of the
convex hull.
Applications
● Creating new mixture
A B
We have some existing mixtures with
known ingredient quantities. 1 10 10

2 30 20
Two ingredients: A and B
3 35 40

We want to create a new mixture with …...


specific ingredient quantities. 10 5 35
Applications
● Creating new mixture

Assuming that new mixture can be created by


the linear combination of existing mixtures.

Given a finite number of points in a


real vector space.

where the real numbers satisfy and


Applications
● Creating new mixture A

How to test whether we can create


3
the new mixture or not?
2
First, we compute the convex hull of
all existing mixture points

Then, test if the new mixture point is


inside the convex hull. 1
4

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 lies below uv means cw(uvw)


u
succ(v)
v

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

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)
v : leftmost of hull(Sr)
v
while either pred(u) or succ(v) lies below uv u

if pred(u) lies below then u:=pred(u)


else v = succ(v) 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

endwhile lower bridge


return uv
Divide & Conquer
Procedure Find-upper-Bridge
u : rightmost of hull(Sl)
u
v : leftmost of hull(Sr)
v
while either succ(u) or pred(v) lies below uv
if succ(u) lies below then u:=succ(u)
else v = prev(v)
endwhile lower bridge
return uv
Divide & Conquer
Procedure Find-upper-Bridge
v
u : rightmost of hull(Sl)
u
v : leftmost of hull(Sr)
v
while either succ(u) or pred(v) lies below uv
if succ(u) lies below then u:=succ(u)
else v = prev(v)
endwhile lower bridge
return uv
Divide & Conquer
Procedure Find-upper-Bridge
u v
u : rightmost of hull(Sl)
u
v : leftmost of hull(Sr)
while either succ(u) or pred(v) lies below uv
if succ(u) lies below then u:=succ(u)
else v = prev(v)
endwhile lower bridge
return uv
Divide & Conquer
Procedure Find-upper-Bridge upper bridge
u v
u : rightmost of hull(Sl)
v : leftmost of hull(Sr)
while either succ(u) or pred(v) lies below uv
if succ(u) lies below then u:=succ(u)
else v = prev(v)
endwhile lower bridge
return uv
Divide & Conquer
Algorithm conv(S, n) upper bridge
u1 v1
if n < 4, then trivially solved
else
DIVIDE: Sl & Sr
RECUR: conv(Sl, n/2), conv(Sr, n/2)
u0
MERGE: combine hull(Sl) and hull(Sr) v0

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

T(n)=⊝(n log n) (a=bd =2)


Applications
● Fundamental content to computational geometry;
(e.g. Voronoi diagrams)
● Computer visualization, ray tracing;
(e.g. video games, replacement of bounding boxes)
● Path finding;
(e.g. embedded AI of Mars mission rovers)
● Visual pattern matching;
(e.g. detecting car license plates)
● Verification methods;
(e.g. bounding of Number Decision Diagrams)
How to perform the binary search in Chan’s
Intuition of binary search in Chan’s
Intuition of binary search in Chan’s
Intuition of binary search in Chan’s

You might also like