cs133
play

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


  1. CS133 Computational Geometry Convex Hull 1

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

  3. Convex Hull Properties ΞΈ 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

  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 5

  6. NaΓ―ve Convex Hull Algorithm 6

  7. Graham Scan Algorithm 7

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  32. Example 32

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

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

  35. Example 35

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

  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 Jarvi’s March Algorithm 37

  38. Gift Wrapping Example 38

  39. Gift Wrapping Example 39

  40. Gift Wrapping Example 40

  41. Gift Wrapping Example 41

  42. Gift Wrapping Example 42

  43. Gift Wrapping Example 43

  44. Gift Wrapping Example 44

  45. Gift Wrapping Example 45

  46. Gift Wrapping Example 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 𝑃(π‘œ β‹… 𝑙) 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) 48

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

  50. Merge: Upper Tangent 50

  51. Merge: Upper Tangent 51

  52. Merge: Upper Tangent 52

  53. Merge: Lower Tangent 53

  54. Merge: Lower Tangent 54

  55. Merge: Lower Tangent 55

  56. Merge: Lower Tangent 56

  57. Merge: Lower Tangent 57

  58. Merge: Lower Tangent 58

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

  60. Analysis Sort step: 𝑃 π‘œ β‹… log π‘œ Merge step: 𝑃 π‘œ Recursive part π‘œ π‘ˆ π‘œ = 2π‘ˆ 2 + 𝑑 β‹… π‘œ π‘ˆ π‘œ = 𝑃 π‘œ β‹… log π‘œ Overall running time 𝑃 π‘œ β‹… log π‘œ 60

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

  62. Case 1: p inside CH 62

  63. Case 2: p on CH 63

  64. Case 3: p outside CH 64

  65. Case 3: p outside CH 65

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

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

  68. Quick Hull 68

  69. Quick Hull How to split the points across the line segment? 69

  70. Quick Hull How to select the farthest point? 70

  71. Quick Hull 71

  72. Quick Hull 72

  73. Quick Hull How to split the points into three subsets? 73

  74. Quick Hull 74

  75. Quick Hull 75

  76. Quick Hull 76

  77. Quick Hull 77

  78. Quick Hull 78

  79. Quick Hull 79

  80. Quick Hull 80

  81. Example 81

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