Convex Hell 362 dnc CS 16: Convex Hull Whoops, I mean... Convex - - PDF document

convex hell
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

CS 16: Convex Hull dnc

362

Welcome to...

Convex Hell

slide-2
SLIDE 2

CS 16: Convex Hull dnc

363

Whoops, I mean...

Convex Hull

What’s a Convex Hull?

slide-3
SLIDE 3

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

slide-4
SLIDE 4

CS 16: Convex Hull dnc

365

Convexity

You know what convex means, right? A polygon P is said to be convex if:

  • 1. P is non-intersecting; and
  • 2. for any two points p and q on the boundary
  • f P, segment pq lies entirely inside P

Eh? What’s convex? convex non convex

slide-5
SLIDE 5

CS 16: Convex Hull dnc

366

Why Convex Hulls?

Who cares about convex hulls? I don’t ... ... but robots do!

  • bstacle

start end shortest path avoiding the

  • bstacle
slide-6
SLIDE 6

CS 16: Convex Hull dnc

367

The Package Wrapping Algorithm

slide-7
SLIDE 7

CS 16: Convex Hull dnc

368

Package Wrap

  • given the current point, how do we compute

the next point?

  • set up an orientation tournament using the

current point as the anchor-point...

  • the next point is selected as the point that

beats all other points at CCW orientation, i.e., for any other point, we have

  • rientation(c, p, q) = CCW

c q p

slide-8
SLIDE 8

CS 16: Convex Hull dnc

369

Time Complexity of Package Wrap

  • For every point on the hull we examine all

the other points to determine the next point

  • Notation:
  • N: number of points
  • M: number of hull points (M ≤ N)
  • Time complexity:
  • Θ(MN)
  • Worst case: Θ(N2)
  • all the points are on the hull (M=N)
  • Average case: Θ(N log N) — Θ(N4/3)
  • for points randomly distributed inside

a square, M = Θ(log N) on average

  • for points randomly distributed inside

a circle, M = Θ(N1/3) on average

slide-9
SLIDE 9

CS 16: Convex Hull dnc

370

Package Wrap has worst-case time complexity O( N2 ) Which is bad...

N2

But in 1972, Nabisco needed a better cookie - so they hired R. L. Graham, who came up with...

slide-10
SLIDE 10

CS 16: Convex Hull dnc

371

Rave Reviews:

  • “Almost linear!”
  • Sedgewick
  • “It’s just a sort!”
  • Atul
  • “Two thumbs up!”
  • Siskel and Ebert
  • Nabisco says...

The Graham Scan Algorithm “A better crunch!” and history was made.

slide-11
SLIDE 11

CS 16: Convex Hull dnc

372

Graham Scan

  • Form a simple polygon (connect the dots as

before)

  • Remove points at concave angles
slide-12
SLIDE 12

CS 16: Convex Hull dnc

373

Graham Scan How Does it Work?

Start with the lowest point (anchor point)

slide-13
SLIDE 13

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

slide-14
SLIDE 14

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?)

slide-15
SLIDE 15

CS 16: Convex Hull dnc

376

Graham Scan: Phase 2

  • keep the path and the hull points in two se-

quences

  • elements are removed from the beginning
  • f the path sequence and are inserted and

deleted from the end of the hull sequence

  • orientation is used to decide whether to ac-

cept or reject the next point

cur prev next

slide-16
SLIDE 16

CS 16: Convex Hull dnc

377

c p n right turn! Discard c (p,c,n) is a c p n

slide-17
SLIDE 17

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

slide-18
SLIDE 18

CS 16: Convex Hull dnc

379

Time Complexity of Graham Scan

  • Phase 1 takes time O(N logN)
  • points are sorted by angle around the

anchor

  • Phase 2 takes time O(N)
  • each point is inserted into the sequence

exactly once, and

  • each point is removed from the

sequence at most once

  • Total time complexity O(N log N)
slide-19
SLIDE 19

CS 16: Convex Hull dnc

380

How to Increase Speed

  • Wipe out a lot of the points you know won’t

be on the hull! This is interior elimination

  • Here’s a good way to do interior elimina-

tion if the points are randomly distributed in a square with horizontal and verticall sides: NE SE NW SW

  • Find the farthest points in the SW, NW,

NE, and SE directions

  • Eliminate the points inside the

quadrilateral (SW, NW, NE, SE)

  • Do Graham Scan on the remaining

points (only Ο(√N) points are left on average!)