Convex hull

39
Convex hull smallest convex se containing all the points

description

smallest convex set containing all the points. Convex hull. smallest convex set containing all the points. Convex hull. smallest convex set containing all the points. Convex hull. 3. 2. start = 1. 1.next = 2 = 3.prev 2.next = 3 = 4.prev 3.next = 4 = 1.prev 4.next = 1 = 2.prev. - PowerPoint PPT Presentation

Transcript of Convex hull

Page 1: Convex hull

Convex hull smallest convex setcontaining all the points

Page 2: Convex hull

Convex hull smallest convex setcontaining all the points

Page 3: Convex hull

Convex hull smallest convex setcontaining all the points

representation = circular doubly-linked list of pointson the boundary of the convex hull

1

2

3

4

1.next = 2 = 3.prev2.next = 3 = 4.prev3.next = 4 = 1.prev4.next = 1 = 2.prev

start = 1

Page 4: Convex hull

Jarvis march

find the left-most point

(assume no 3 points colinear)

s

Page 5: Convex hull

Jarvis march

find the point that appears most to the right looking from s

(assume no 3 points colinear)

s

Page 6: Convex hull

Jarvis march (assume no 3 points colinear)

s

p

find the point that appears most to the right looking from p

Page 7: Convex hull

Jarvis march (assume no 3 points colinear)

Page 8: Convex hull

Jarvis march (assume no 3 points colinear)

Page 9: Convex hull

Jarvis march (assume no 3 points colinear)

s point with smallest x-coordp srepeat PRINT(p) q point other than p for i from 1 to n do if i p and point i to the right of line (p,q) then q i p quntil p = s

Page 10: Convex hull

Jarvis march (assume no 3 points colinear)

Running time = O(n.h)

Page 11: Convex hull

Graham scan (assume no 3 points colinear)

start with a simple polygon containing all the pointsfix it in time O(n)

O(n log n)homework

Page 12: Convex hull

Graham scan (assume no 3 points colinear)

Page 13: Convex hull

Graham scan (assume no 3 points colinear)

Page 14: Convex hull

Graham scan (assume no 3 points colinear)

Page 15: Convex hull

Graham scan (assume no 3 points colinear)

Page 16: Convex hull

Graham scan (assume no 3 points colinear)

Page 17: Convex hull

Graham scan (assume no 3 points colinear)

Page 18: Convex hull

Graham scan (assume no 3 points colinear)

A startB next(A)C next(B)

repeat 2n times if C is to the right of AB then A.next C; C.prev A B A A prev(A) else A B B C C next(C)

Page 19: Convex hull

Closest pair of points

Page 20: Convex hull

Closest pair of points

Page 21: Convex hull

Closest pair of points

2T(n/2) min(left,right)

Page 22: Convex hull

Closest pair of points

2T(n/2) min(left,right)

Page 23: Convex hull

Closest pair of points

2T(n/2) min(left,right)

Page 24: Convex hull

Closest pair of points

X sort the points by x-coordinateY sort the points by y-coordinate

pre-processing

Closest-pair(S) if |S|=1 then return if |S|=2 then return the distance of the pair split S into S1 and S2 by the X-coord 1 Closest-pair(S1), 2 Closest-pair(S2) min(1,2) for points x in according to Y check 12 points around x, update if a closer pair found

Page 25: Convex hull

Smallest enclosing disc

Page 26: Convex hull

Smallest enclosing disc

Page 27: Convex hull

Smallest enclosing disc

The smallest enclosing disc is unique.Claim #1:

Page 28: Convex hull

Smallest enclosing disc

The smallest enclosing disc is unique.Claim #1:

Page 29: Convex hull

Smallest enclosing disc

SED(S) pick a random point x S (c,r) SED(S-{x}) if xDisc(c,r) then return (c,r) else return SED-with-point(S,x)

Page 30: Convex hull

Smallest enclosing discSED(S) pick a random point x S (c,r) SED(S-{x}) if xDisc(c,r) then return (c,r) else return SED-with-point(S,x)

SED-with-point(S,y) pick a random point x S (c,r) SED-with-point(S-{x},y) if xDisc(c,r) then return (c,r) else return SED-with-2-points(S,y,x)

Page 31: Convex hull

Smallest enclosing discSED(S) pick a random point x S (c,r) SED(S-{x}) if xDisc(c,r) then return (c,r) else return SED-with-point(S,x)

SED-with-2-point(S,y,z) pick a random point x S (c,r) SED-with-2-points(S-{x},y,z) if xDisc(c,r) then return (c,r) else return circle given by x,y,z

SED-with-point(S,y) pick a random point x S (c,r) SED-with-point(S-{x},y) if xDisc(c,r) then return (c,r) else return SED-with-2-points(S,y,x)

Page 32: Convex hull

Running time ?SED(S) pick a random point x S (c,r) SED(S-{x}) if xDisc(c,r) then return (c,r) else return SED-with-point(S,x)

SED-with-2-point(S,y,z) pick a random point x S (c,r) SED-with-2-points(S-{x},y,z) if xDisc(c,r) then return (c,r) else return circle given by x,y,z

SED-with-point(S,y) pick a random point x S (c,r) SED-with-point(S-{x},y) if xDisc(c,r) then return (c,r) else return SED-with-2-points(S,y,x)

Page 33: Convex hull

Running time ?SED(S) pick a random point x S (c,r) SED(S-{x}) if xDisc(c,r) then return (c,r) else return SED-with-point(S,x)

SED-with-2-point(S,y,z) pick a random point x S (c,r) SED-with-2-points(S-{x},y,z) if xDisc(c,r) then return (c,r) else return circle given by x,y,z

SED-with-point(S,y) pick a random point x S (c,r) SED-with-point(S-{x},y) if xDisc(c,r) then return (c,r) else return SED-with-2-points(S,y,x)

O(n)

Page 34: Convex hull

Running time ?SED(S) pick a random point x S (c,r) SED(S-{x}) if xDisc(c,r) then return (c,r) else return SED-with-point(S,x)

SED-with-point(S,y) pick a random point x S (c,r) SED-with-point(S-{x},y) if xDisc(c,r) then return (c,r) else return SED-with-2-points(S,y,x)

T(n) = T(n-1) + 2

nSED-with-2-points

T(n) = O(n)

O(n)

Page 35: Convex hull

Running time ?SED(S) pick a random point x S (c,r) SED(S-{x}) if xDisc(c,r) then return (c,r) else return SED-with-point(S,x)

T(n) = T(n-1) + 2

nSED-with-point

T(n) = O(n)

O(n)

Page 36: Convex hull

Smallest enclosing disc

Claim #2:

md(I,B) = smallest enclosing disc with B on the boundary and I inside

if x is inside md(I,B) then md(I {x},B) = md(I,B)

Page 37: Convex hull

Smallest enclosing disc

Claim #3:

md(I,B) = smallest enclosing disc with B on the boundary and I inside

if x is outside of md(I,B) then md(I {x},B) = md(I,B {x})

Page 38: Convex hull

Smallest enclosing disc

Claim #3:

md(I,B) = smallest enclosing disc with B on the boundary and I inside

if x is outside of md(I,B) then md(I {x},B) = md(I,B {x})

md(I,B) md(l {x},B)

x

Page 39: Convex hull

Smallest enclosing disc

Claim #3:

md(I,B) = smallest enclosing disc with B on the boundary and I inside

if x is outside of md(I,B) then md(I {x},B) = md(I,B {x})

Claim #2:if x is inside md(I,B) then md(I {x},B) = md(I,B)

Claim #1:md(I,B) is unique