CS133 Computational Geometry Convex Hull 4/12/2018 1
Convex Hull Given a set of n points, find the minimal convex polygon that contains all the points 4/12/2018 2
Convex Hull Properties ΞΈ 4/12/2018 3
Convex Hull Representation The convex hull is represented by all its points sorted in CW/CCW order Special case: Three collinear points 4/12/2018 4
NaΓ―ve Convex Hull Algorithm Iterate over all possible line segments A line segment is part of the convex hull if all other points are to its left Emit all segments in a CCW order Running time π π 3 4/12/2018 5
NaΓ―ve Convex Hull Algorithm 4/12/2018 6
Graham Scan Algorithm 4/12/2018 7
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 8
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 9
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 10
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 11
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 12
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 13
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 14
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 15
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 16
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 17
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 18
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 19
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 20
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 21
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 22
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 23
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 24
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 25
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 26
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 27
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 28
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 29
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 30
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 31
Example 4/12/2018 32
Graham Scan Pseudo Code Select the point with minimum y Sort all points in CCW order {p 0 ,p 1 ,β¦, p n ) S = {p 0 ,p 1 } For i=2 to n While |S| > 2 && p i is to the right of S -2 ,S -1 S.pop S.push(p i ) 4/12/2018 33
Monotone Chain Algorithm Has some similarities with Graham scan algorithm Instead of sorting in CCW order, it sorts by one coordinate (e.g., x-coordinates) 4/17/2018 34
Example 4/17/2018 35
Pseudo Code Sort S by x U = {S 0 } For i = 1 to n while |U| > 1 && S i is to the left of π β2 π β1 U.pop U.push(S i ) L = {S 0 } While |L| > 1 && S i is to the right of π β2 π β1 L.pop L.push(S i ) 4/17/2018 36
Gift Wrapping Algorithm 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 Jarvis March Algorithm 4/17/2018 37
Gift Wrapping Example 4/17/2018 38
Gift Wrapping Example 4/17/2018 39
Gift Wrapping Example 4/17/2018 40
Gift Wrapping Example 4/17/2018 41
Gift Wrapping Example 4/17/2018 42
Gift Wrapping Example 4/17/2018 43
Gift Wrapping Example 4/17/2018 44
Gift Wrapping Example 4/17/2018 45
Gift Wrapping Example 4/17/2018 46
Gift Wrapping Pseudo Code 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 O(n.k) 4/17/2018 47
Divide & Conquer Convex Hull ConvexHull(S) Splits S into two subsets S1 and S2 Ch1 = ConvexHull(S1) Ch2 = ConvexHull(S2) Return Merge(Ch1, Ch2) 4/17/2018 48
Merge: Upper Tangent 4/17/2018 49
Merge: Upper Tangent 4/17/2018 50
Merge: Upper Tangent 4/17/2018 51
Merge: Lower Tangent 4/17/2018 52
Merge: Lower Tangent 4/17/2018 53
Merge: Lower Tangent 4/17/2018 54
Merge: Lower Tangent 4/17/2018 55
Merge: Lower Tangent 4/17/2018 56
Merge: Lower Tangent 4/17/2018 57
Merge Step Upper Tangent(L,R) P i = Right most point in L P j = Left most point in R Do Done = true While P i+1 is to the right of π π π π i++; done = false While P j-1 is to the left of π π π π j--; done = false 4/17/2018 58
Analysis Sort step: O(n log n) Merge step: O(n) Recursive part T(n)=2T(n/2)+O(n) T(n)=O(n log n) Overall running time O(n log n) 4/17/2018 59
Incremental Convex Hull 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 4/19/2018 60
Case 1: p inside CH 4/19/2018 61
Case 2: p on CH 4/19/2018 62
Case 3: p outside CH 4/19/2018 63
Case 3: p outside CH 4/19/2018 64
Analysis of the Insert Function Test whether the point is inside, outside, or on the polygon O(n) Find the two tangents O(n) A more efficient algorithm can have an amortized running time of O(log n) 4/19/2018 65
Quick Hull 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 4/19/2018 66
Quick Hull 4/19/2018 67
Quick Hull How to split the points across the line segment? 4/19/2018 68
Quick Hull How to select the farthest point? 4/19/2018 69
Quick Hull 4/19/2018 70
Quick Hull 4/19/2018 71
Quick Hull How to split the points into three subsets? 4/19/2018 72
Quick Hull 4/19/2018 73
Quick Hull 4/19/2018 74
Quick Hull 4/19/2018 75
Quick Hull 4/19/2018 76
Quick Hull 4/19/2018 77
Quick Hull 4/19/2018 78
Quick Hull 4/19/2018 79
Example 4/19/2018 80
Running Time Analysis π π = π π 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 π 4/19/2018 81
Recommend
More recommend