CS133
Computational Geometry
Convex Hull
1
CS133 Computational Geometry Convex Hull 1 Convex Hull Given a - - PowerPoint PPT Presentation
CS133 Computational Geometry Convex Hull 1 Convex Hull Given a set of n points, find the minimal convex polygon that contains all the points 2 Convex Hull Properties 3 Convex Hull Representation The convex hull is represented by all
Convex Hull
1
Given a set of n points, find the minimal convex polygon that contains all the points
2
3
ΞΈ
The convex hull is represented by all its points sorted in CW/CCW order Special case: Three collinear points
4
Iterate over all possible line segments A line segment is part of the convex hull if all
Emit all segments in a CCW order Running time π π3
5
6
7
8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
21
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
24
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
25
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
26
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
27
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
28
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
29
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
30
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
31
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
32
Select the point with minimum π§ Sort all points in CCW order π0, π1, β¦ , ππ π = π0, π1 For π = 2 to π
While |π| > 2 && ππ is to the right of πβ2, πβ1
π.pop
π.push(ππ)
33
Has some similarities with Graham scan algorithm Instead of sorting in CCW order, it sorts by
34
35
Sort π by π¦ π = {π0} For π = 1 to π
while |π| > 1 && ππ is to the left of πβ2πβ1
π.pop
π.push(ππ)
π = {π0}
While |π| > 1 && ππ is to the right of πβ2πβ1
π.pop
π.push(ππ)
36
Start with a point on the convex hull Find more points on the hull one at a time Terminate when the first point is reached back Also knows as Jarviβs March Algorithm
37
38
39
40
41
42
43
44
45
46
Gift Wrapping(S)
CH= {} CH << Left most point do
Start point = CH.last End point = CH[0] For each point s β S
If Start point = End Point OR s is to the left of ππ’ππ π’ πππππ’, πΉππ πππππ’ End point = s
CH << End point
Running time π(π β π)
47
ConvexHull(S)
Splits S into two subsets S1 and S2 Ch1 = ConvexHull(S1) Ch2 = ConvexHull(S2) Return Merge(Ch1, Ch2)
48
ConvexHull(S)
Splits S into two subsets S1 and S2 Ch1 = ConvexHull(S1) Ch2 = ConvexHull(S2) Return Merge(Ch1, Ch2)
49
50
51
52
53
54
55
56
57
58
Upper Tangent(π, π)
ππ = Right most point in π ππ = Left most point in π Do
Done = true While π
π+1 is to the right of ππππ
π + +; done = false
While π
πβ1 is to the left of ππππ
π β β; done = false
59
Sort step: π π β log π Merge step: π π Recursive part
π π = 2π
π 2 + π β π
π π = π π β log π
Overall running time π π β log π
60
Start with an initial convex hull Add one additional point to the convex hull Given a convex hull CH and a point p, how to compute the convex hull of {CH, p}? Think: Insert an element into a sorted list
61
62
63
64
65
Test whether the point is inside, outside, or
Find the two tangents O(n) A more efficient algorithm can have an amortized running time of O(log n)
66
If we can have a divide-and-conquer algorithm similar to merge sort β¦ why not having an algorithm similar to quick sort? Sketch
Find a pivot Split the points along the pivot Recursively process each side
67
68
69
How to split the points across the line segment?
70
How to select the farthest point?
71
72
73
How to split the points into three subsets?
74
75
76
77
78
79
80
81
π π = π π1 + π π2 + π π Worst case π1 = π β π or π2 = π β π, where π is a small constant (e.g., k=1)
π π = π π2
Best case π1 = π and π2 = π, where π is a small constant
In this case, most of the points are pruned π π = π π
Average case, π1 = π½π and π2 = πΎπ, where π½ < 1 and πΎ < 1
π π = π π log π
82