0% found this document useful (0 votes)
11 views27 pages

Convex Hulls

Uploaded by

fastaka.ft
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views27 pages

Convex Hulls

Uploaded by

fastaka.ft
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 27

CS 6463: AT Computational Geometry

Spring 2006

Convex Hulls
Carola Wenk

8/29/06 CS 6463: AT Computational Geometry 1


Convex Hull Problem
 Given a set of pins on a pinboard
and a rubber band around them.
How does the rubber band look
when it snaps tight?
 The convex hull of a point set is
one of the simplest shape
approximations for a set of points.

8/29/06 CS 6463: AT Computational Geometry 2


Convexity
 A set C  R2 is convex if for all two points p,qC the line
segment pq is fully contained in C.

convex non-convex

8/29/06 CS 6463: AT Computational Geometry 3


Convex Hull
 The convex hull CH(P) of a point set P  R2 is the smallest
convex set C  P. In other words CH(P) =  C .
CP
C convex

8/29/06 CS 6463: AT Computational Geometry 4


Convex Hull
 Observation: CH(P) is the unique convex polygon whose
vertices are points of P and which contains all points of P.
 We represent the convex hull as the sequence of points on
the convex hull polygon (the boundary of the convex hull),
in counter-clockwise order.
4
5 3

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)PP with p≠q // ordered pair
valid := true
for all rP, 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:=Epq // 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 AB can be computed from the
convex hulls of A and the convex
hull of B in O(n) linear time

A B

8/29/06 CS 6463: AT Computational Geometry 9


Finding the lower tangent
3
a = rightmost point of A
b = leftmost point of B 4 4=b
2

while T=ab not lower tangent to both


3
convex hulls of A and B do{ 5
5 a=2
while T not lower tangent to 6
convex hull of A do{ 1
7
a=a-1 1
} 0 0
while T not lower tangent to
convex hull of B do{ A B
b=b+1 left turn
} right turn
} check with
orientation test
8/29/06 CS 6463: AT Computational Geometry 10
Convex Hull: Runtime
 Preprocessing: sort the points by x-
coordinate
O(n log n) just once

 Divide the set of points into two


sets A and B: O(1)
 A contains the left n/2 points,
 B contains the right n/2 points
Recursively compute the convex T(n/2)
hull of A
Recursively compute the convex T(n/2)
hull of B
 Merge the two convex hulls O(n)
8/29/06 CS 6463: AT Computational Geometry 11
Convex Hull: Runtime
 Runtime Recurrence:
T(n) = 2 T(n/2) + cn

 Solves to T(n) = (n log n)

8/29/06 CS 6463: AT Computational Geometry 12


Recurrence
(Just like merge sort recurrence)
1. Divide: Divide set of points in half.
2. Conquer: Recursively compute convex
hulls of 2 halves.
3. Combine: Linear-time merge.
T(n) = 2 T(n/2) + O(n)
# subproblems subproblem size work dividing
and combining

8/29/06 CS 6463: AT Computational Geometry 13


Recurrence (cont’d)
(1) if n = 1;
T(n) =
2T(n/2) + (n) if n > 1.

• How do we solve T(n)? I.e., how do we


find out if it is O(n) or O(n2) or …?

8/29/06 CS 6463: AT Computational Geometry 14


Recursion tree
Solve T(n) = 2T(n/2) + dn, where d > 0 is constant.

8/29/06 CS 6463: AT Computational Geometry 15


Recursion tree
Solve T(n) = 2T(n/2) + dn, where d > 0 is constant.
T(n)

8/29/06 CS 6463: AT Computational Geometry 16


Recursion tree
Solve T(n) = 2T(n/2) + dn, where d > 0 is constant.
dn
T(n/2) T(n/2)

8/29/06 CS 6463: AT Computational Geometry 17


Recursion tree
Solve T(n) = 2T(n/2) + dn, where d > 0 is constant.
dn
dn/2 dn/2

T(n/4) T(n/4) T(n/4) T(n/4)

8/29/06 CS 6463: AT Computational Geometry 18


Recursion tree
Solve T(n) = 2T(n/2) + dn, where d > 0 is constant.
dn
dn/2 dn/2

dn/4 dn/4 dn/4 dn/4


(1)

8/29/06 CS 6463: AT Computational Geometry 19


Recursion tree
Solve T(n) = 2T(n/2) + dn, where d > 0 is constant.
dn
dn/2 dn/2
h = log n dn/4 dn/4 dn/4 dn/4

(1)

8/29/06 CS 6463: AT Computational Geometry 20


Recursion tree
Solve T(n) = 2T(n/2) + dn, where d > 0 is constant.
dn dn
dn/2 dn/2
h = log n dn/4 dn/4 dn/4 dn/4

(1)

8/29/06 CS 6463: AT Computational Geometry 21


Recursion tree
Solve T(n) = 2T(n/2) + dn, where d > 0 is constant.
dn dn
dn/2 dn/2 dn
h = log n dn/4 dn/4 dn/4 dn/4

(1)

8/29/06 CS 6463: AT Computational Geometry 22


Recursion tree
Solve T(n) = 2T(n/2) + dn, where d > 0 is constant.
dn dn
dn/2 dn/2 dn
h = log n dn/4 dn/4 dn/4 dn/4 dn


(1)

8/29/06 CS 6463: AT Computational Geometry 23


Recursion tree
Solve T(n) = 2T(n/2) + dn, where d > 0 is constant.
dn dn
dn/2 dn/2 dn
h = log n dn/4 dn/4 dn/4 dn/4 dn


(1) #leaves = n (n)

8/29/06 CS 6463: AT Computational Geometry 24


Recursion tree
Solve T(n) = 2T(n/2) + dn, where d > 0 is constant.
dn dn
dn/2 dn/2 dn
h = log n dn/4 dn/4 dn/4 dn/4 dn


(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)

8/29/06 CS 6463: AT Computational Geometry 26


Master theorem
T(n) = a T(n/b) + f (n) ,
where a  1, b > 1, and f is asymptotically positive.
CASE 1: f (n) = O(nlogba – )
 T(n) = (nlogba) .
CASE 2: f (n) = (nlogba logkn)
 T(n) = (nlogba logk+1n) .
CASE 3: f (n) = (nlogba + ) and a f (n/b)  c f (n)
 T(n) = ( f (n)) .
Convex hull: a = 2, b = 2  nlogba = n
 CASE 2 (k = 0)  T(n) = (n log n) .
8/29/06 CS 6463: AT Computational Geometry 27

You might also like