Convex Hulls
Convex Hulls
Spring 2006
Convex Hulls
Carola Wenk
convex non-convex
6
2
0 1
8/29/06 CS 6463: AT Computational Geometry 5
A First Try
Algorithm SLOW_CH(P):
/* CH(P) = Intersection of all half-planes that are defined by the directed line through
ordered pairs of points in P and that have all remaining points of P on their left */
Input: Point set P R2
Output: A list L of vertices describing the CH(P) in counter-clockwise order
E:=
for all (p,q)PP with p≠q // ordered pair
valid := true
for all rP, r≠p and r≠q
if r lies to the left of directed line through p and q // takes constant time
valid := false
if valid then
E:=Epq // directed edge
Construct from E sorted list L of vertices of CH(P) in counter-clockwise order
• Runtime: O(n3) , where n = |P|
• How to test that a point lies to the left?
8/29/06 CS 6463: AT Computational Geometry 6
Orientation Test / Halfplane Test
r p
q
q q r
p r p
• positive orientation • negative orientation • zero orientation
(counter-clockwise) (clockwise) • r lies on the line pq
• r lies to the left of pq • r lies to the right of pq
1 p x py
• Orient(p,q,r) = det 1 qx qy ,where p = (px,py)
1 r x ry
• Can be computed in constant time
8/29/06 CS 6463: AT Computational Geometry 7
Convex Hull: Divide & Conquer
Preprocessing: sort the points by x-
coordinate
Divide the set of points into two
sets A and B:
A contains the left n/2 points,
B contains the right n/2 points
Recursively compute the convex
hull of A
A B
Recursively compute the convex
hull of B
Merge the two convex hulls
8/29/06 CS 6463: AT Computational Geometry 8
Merging
Find upper and lower tangent
With those tangents the convex hull
of AB can be computed from the
convex hulls of A and the convex
hull of B in O(n) linear time
A B
(1)
(1)
(1)
(1)
…
(1)
…
(1) #leaves = n (n)
…
(1) #leaves = n (n)
Total(n log n)
8/29/06 CS 6463: AT Computational Geometry 25
The divide-and-conquer
design paradigm
1. Divide the problem (instance) into
subproblems.
a subproblems, each of size n/b
2. Conquer the subproblems by
solving them recursively.
3. Combine subproblem solutions.
Runtime is f(n)