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 its points sorted in CW/CCW order Special case: Three collinear points 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 5
NaΓ―ve Convex Hull Algorithm 6
Graham Scan Algorithm 7
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 8
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 9
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 10
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 11
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 12
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 13
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 14
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 15
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 16
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 17
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 18
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 19
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 20
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 21
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 22
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 23
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 24
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 25
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 26
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 27
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 28
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 29
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 30
Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 31
Example 32
Graham Scan Pseudo Code 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
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) 34
Example 35
Pseudo Code 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
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 Jarviβs March Algorithm 37
Gift Wrapping Example 38
Gift Wrapping Example 39
Gift Wrapping Example 40
Gift Wrapping Example 41
Gift Wrapping Example 42
Gift Wrapping Example 43
Gift Wrapping Example 44
Gift Wrapping Example 45
Gift Wrapping Example 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 π(π β π) 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) 48
Divide & Conquer Convex Hull ConvexHull(S) Splits S into two subsets S1 and S2 Ch1 = ConvexHull(S1) Ch2 = ConvexHull(S2) Return Merge(Ch1, Ch2) ο ο 49
Merge: Upper Tangent 50
Merge: Upper Tangent 51
Merge: Upper Tangent 52
Merge: Lower Tangent 53
Merge: Lower Tangent 54
Merge: Lower Tangent 55
Merge: Lower Tangent 56
Merge: Lower Tangent 57
Merge: Lower Tangent 58
Merge Step 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
Analysis Sort step: π π β log π Merge step: π π Recursive part π π π = 2π 2 + π β π π π = π π β log π Overall running time π π β log π 60
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 61
Case 1: p inside CH 62
Case 2: p on CH 63
Case 3: p outside CH 64
Case 3: p outside CH 65
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) 66
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 67
Quick Hull 68
Quick Hull How to split the points across the line segment? 69
Quick Hull How to select the farthest point? 70
Quick Hull 71
Quick Hull 72
Quick Hull How to split the points into three subsets? 73
Quick Hull 74
Quick Hull 75
Quick Hull 76
Quick Hull 77
Quick Hull 78
Quick Hull 79
Quick Hull 80
Example 81
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 π 82
Recommend
More recommend