Lecture 14
Lecture 14
Applications
Collision avoidance
Fitting ranges with a line
Smallest box
Shape Analysis
3
Convexity
A set S is convex,
if x,y in S implies that
the segment xy is a subset of S
y
∣xv∣
=
∣xy∣
v = αx+βy ∣vy∣
x =
∣xy∣
5
Convex Combination
αi ≥ 0 for all I
x1
α1 + α 2 + … + α k = 1
α1x1 + α2x2 + α3x3
x3
x2
6
Convex Hull
Definition I
The convex hull of a set of points S is
the set of all convex combinations of points of S
7
Convex Hull
Definition II
The convex hull of a set of points S
in d dimensions is
the set of all convex combinations of d+1 (or fewer)
points of S
Definition III
The convex hull of a set of points S is
the intersection of all convex sets that contain S
9
Convex Hull
Definition IV
The convex hull of a set of points S is
the intersection of all halfspaces that contain S
10
Convex Hull
Definition V
The convex hull of a set of points S is
the smallest convex polygon that encloses S
11
Convex Hull
Definition VI
The convex hull of a set of points S is
the enclosing convex polygon with smallest area
12
Convex Hull
Definition VII
The convex hull of a set of points S in the plane is
the union of all the triangles determined by points in S
13
Output
Extreme points
are the vertices of the convex hull at which the
interior angle is strictly convex
15
Naive Algorithms
Nonextreme Points
A point is nonextreme iff it is inside some triangle
whose vertices are points of the set and is not itself
a corner of that triangle
16
Naive Algorithms
O(n4) !!!
17
Extreme Edges
e Ө
x
20
Gift Wrapping
Similar to Quicksort
It is easy to discard many points
But may not work always
Running time:
Best case: O(n log n)
Worst case: O(n2)
22
Quickhull
Algorithm: QUICKHULL(a, b, S)
If S = Ø then return
else
c ← index of point with max distance from ab
A ← points strictly right of (a, c)
B ← points strictly right of (c, b)
return QUICKHULL(a, c, A) + ( c ) + QUICKHULL(c, b, B)
23
Quickhull
Start with the leftmost
and rightmost vertices
a
24
Quickhull
Points in the triangle acb
are interior to the hull
a
25
Quickhull
26
Quickhull
27
Quickhull
28
Quickhull
29
Quickhull
Running Time:
Initial extremes a,b and separating S: O(n)
Finding extreme point c and eliminating points in
triangle acb: O(n)
Recursive steps: T(n) = O(n) + T(α) + T(β)
Best case: T(n) = 2T(n/2) + O(n) = O(n log n)
Worst case: T(n) = O(n) + T(n-1) = O(n2)
30
Graham's Scan
3
4
1
Stack S 2
5
v 8
6
7
33
Graham's Scan
3
2 4
1 1
2
5
v 8
6
7
34
Graham's Scan
3
2 4
Right turn!
1 1
5 2
v 8
6
7
35
Graham's Scan
3
3 4
1 1
5 2
v 8
6
7
36
Graham's Scan
5 2
v 8
6
7
37
Graham's Scan
5 3
4
3 4
1 Left Turn, OK! 1
5 2
v 8
6
7
38
Graham's Scan
3
5 4
4
3 1
1
5 2
Right Turn!
v 8
6
7
39
Graham's Scan
3
6 4
4
3 1
1
5 2
v 8
6
7
40
Graham's Scan
7 3
6 4
4
3 1
1
5 2
v 8
6
Left Turn, OK!
7
41
Graham's Scan
8
7 3
6 4
4
3 1
1
5 2
v 8
6
8
7 3
6 4
4
3 1
1
5 2
v 8
Left Turn, OK!
6
7
43
Running Time
3 8
1
4
v 7
5
6
46
Solutions
6
2
7
4
1
8
v
48
Solutions
Hull collinearities
require a strict left turn
Sorting collinearities
Arbitrary solutions cause hull overlaps
or bugs in the implementation
16
i←1
S1 ← S
n1 ← n
while (ni > 3)
compute the convex hull H(Si) of Si
Si+1 ← Si – H(Si)
ni+1 ← ni – |H(Si)|
i←i+1