CS 16: Convex Hull dnc
362
Welcome to...
Convex Hell 362 dnc CS 16: Convex Hull Whoops, I mean... Convex - - PDF document
CS 16: Convex Hull Welcome to... Convex Hell 362 dnc CS 16: Convex Hull Whoops, I mean... Convex Hull Whats a Convex Hull? 363 dnc CS 16: Convex Hull What is the Convex Hull? Let S be a set of points in the plane. Intuition: Imagine
CS 16: Convex Hull dnc
362
Welcome to...
CS 16: Convex Hull dnc
363
Whoops, I mean...
What’s a Convex Hull?
CS 16: Convex Hull dnc
364
What is the 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 rub- ber-band stretched around the pegs. Formal definition: the convex hull of S is the smallest convex polygon that contains all the points of S
CS 16: Convex Hull dnc
365
Convexity
You know what convex means, right? A polygon P is said to be convex if:
Eh? What’s convex? convex non convex
CS 16: Convex Hull dnc
366
Why Convex Hulls?
Who cares about convex hulls? I don’t ... ... but robots do!
start end shortest path avoiding the
CS 16: Convex Hull dnc
367
The Package Wrapping Algorithm
CS 16: Convex Hull dnc
368
Package Wrap
the next point?
current point as the anchor-point...
beats all other points at CCW orientation, i.e., for any other point, we have
c q p
CS 16: Convex Hull dnc
369
Time Complexity of Package Wrap
the other points to determine the next point
a square, M = Θ(log N) on average
a circle, M = Θ(N1/3) on average
CS 16: Convex Hull dnc
370
Package Wrap has worst-case time complexity O( N2 ) Which is bad...
But in 1972, Nabisco needed a better cookie - so they hired R. L. Graham, who came up with...
CS 16: Convex Hull dnc
371
Rave Reviews:
The Graham Scan Algorithm “A better crunch!” and history was made.
CS 16: Convex Hull dnc
372
Graham Scan
before)
CS 16: Convex Hull dnc
373
Graham Scan How Does it Work?
Start with the lowest point (anchor point)
CS 16: Convex Hull dnc
374
Graham Scan: Phase 1
Now, form a closed simple path traversing the points by increasing angle with respect to the an- chor point
CS 16: Convex Hull dnc
375
Graham Scan: Phase 2 The anchor point and the next point on the path must be on the hull (why?)
CS 16: Convex Hull dnc
376
Graham Scan: Phase 2
quences
deleted from the end of the hull sequence
cept or reject the next point
cur prev next
CS 16: Convex Hull dnc
377
c p n right turn! Discard c (p,c,n) is a c p n
CS 16: Convex Hull dnc
378
c p n right turn! (p,c,n) is a c p n right turn! (p,c,n) is a c p n
CS 16: Convex Hull dnc
379
Time Complexity of Graham Scan
anchor
exactly once, and
sequence at most once
CS 16: Convex Hull dnc
380
How to Increase Speed
be on the hull! This is interior elimination
tion if the points are randomly distributed in a square with horizontal and verticall sides: NE SE NW SW
NE, and SE directions
quadrilateral (SW, NW, NE, SE)
points (only Ο(√N) points are left on average!)