cs133
play

CS133 Computational Geometry Convex Hull 4/12/2018 1 Convex Hull - PowerPoint PPT Presentation

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


  1. CS133 Computational Geometry Convex Hull 4/12/2018 1

  2. Convex Hull Given a set of n points, find the minimal convex polygon that contains all the points 4/12/2018 2

  3. Convex Hull Properties ΞΈ 4/12/2018 3

  4. 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

  5. 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

  6. NaΓ―ve Convex Hull Algorithm 4/12/2018 6

  7. Graham Scan Algorithm 4/12/2018 7

  8. Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 8

  9. Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 9

  10. Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 10

  11. Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 11

  12. Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 12

  13. Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 13

  14. Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 14

  15. Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 15

  16. Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 16

  17. Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 17

  18. Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 18

  19. Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 19

  20. Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 20

  21. Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 21

  22. Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 22

  23. Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 23

  24. Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 24

  25. Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 25

  26. Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 26

  27. Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 27

  28. Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 28

  29. Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 29

  30. Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 30

  31. Graham Scan Algorithm 5 11 3 7 4 10 8 6 14 2 1 13 12 9 15 0 4/12/2018 31

  32. Example 4/12/2018 32

  33. 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

  34. 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

  35. Example 4/17/2018 35

  36. 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

  37. 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

  38. Gift Wrapping Example 4/17/2018 38

  39. Gift Wrapping Example 4/17/2018 39

  40. Gift Wrapping Example 4/17/2018 40

  41. Gift Wrapping Example 4/17/2018 41

  42. Gift Wrapping Example 4/17/2018 42

  43. Gift Wrapping Example 4/17/2018 43

  44. Gift Wrapping Example 4/17/2018 44

  45. Gift Wrapping Example 4/17/2018 45

  46. Gift Wrapping Example 4/17/2018 46

  47. 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

  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) 4/17/2018 48

  49. Merge: Upper Tangent 4/17/2018 49

  50. Merge: Upper Tangent 4/17/2018 50

  51. Merge: Upper Tangent 4/17/2018 51

  52. Merge: Lower Tangent 4/17/2018 52

  53. Merge: Lower Tangent 4/17/2018 53

  54. Merge: Lower Tangent 4/17/2018 54

  55. Merge: Lower Tangent 4/17/2018 55

  56. Merge: Lower Tangent 4/17/2018 56

  57. Merge: Lower Tangent 4/17/2018 57

  58. 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

  59. 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

  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 4/19/2018 60

  61. Case 1: p inside CH 4/19/2018 61

  62. Case 2: p on CH 4/19/2018 62

  63. Case 3: p outside CH 4/19/2018 63

  64. Case 3: p outside CH 4/19/2018 64

  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) 4/19/2018 65

  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 4/19/2018 66

  67. Quick Hull 4/19/2018 67

  68. Quick Hull How to split the points across the line segment? 4/19/2018 68

  69. Quick Hull How to select the farthest point? 4/19/2018 69

  70. Quick Hull 4/19/2018 70

  71. Quick Hull 4/19/2018 71

  72. Quick Hull How to split the points into three subsets? 4/19/2018 72

  73. Quick Hull 4/19/2018 73

  74. Quick Hull 4/19/2018 74

  75. Quick Hull 4/19/2018 75

  76. Quick Hull 4/19/2018 76

  77. Quick Hull 4/19/2018 77

  78. Quick Hull 4/19/2018 78

  79. Quick Hull 4/19/2018 79

  80. Example 4/19/2018 80

  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 π‘œ 4/19/2018 81

Recommend


More recommend