Convex Hull
Convex Hull
2012/10/23
Convex vs. Concave
P x y P x y
concave convex
The convex hull problem
concave polygon: convex polygon:
3
Graham’s Scan
• Start at point guaranteed to be on the hull.
(the point with the minimum y value)
• Sort remaining points by polar angles of
vertices relative to the first point.
• Go through sorted points, keeping vertices
of points that have left turns and dropping
points that have right turns.
Graham’s Scan
Graham’s Scan
Graham’s Scan
Graham’s Scan
Graham’s Scan
Graham’s Scan
Graham’s Scan
Graham’s Scan
Graham’s Scan
Graham’s Scan
Graham’s Scan
Graham’s Scan
Graham’s Scan
Graham’s Scan
Graham’s Runtime
• Graham’s scan is O(n log n) due to initial
sort of angles.
A more detailed algorithm
Convex Hull
by Divide-and-Conquer
• First, sort all points by their x coordinate.
– ( O(n log n) time)
• Then divide and conquer:
– Find the convex hull of the left half of points.
– Find the convex hull of the right half of
points.
– Merge the two hulls into one.
5