cs133
play

CS133 Computational Geometry Intersection Problems 1 Riddle: Fair - PowerPoint PPT Presentation

CS133 Computational Geometry Intersection Problems 1 Riddle: Fair Cake-cutting Using only one straight-line cut, how to split the cake into two equal pieces (by area)? Cake 2 Riddle: Fair cake-cutting Mixed cake! Still one cut Cake Cake


  1. CS133 Computational Geometry Intersection Problems 1

  2. Riddle: Fair Cake-cutting Using only one straight-line cut, how to split the cake into two equal pieces (by area)? Cake 2

  3. Riddle: Fair cake-cutting Mixed cake! Still one cut Cake Cake 3

  4. Line Segment Intersections Given a set of line segments, each defined by two end points, find all intersecting line segments 4

  5. Line Segment Intersection 5

  6. Line Segment Intersection 6

  7. NaΓ―ve Algorithm Enumerate all possible pairs of lines Test for intersection Running time O(n 2 ) What is the lower bound of the running time? Worst case: O(n 2 ) Is this optimal? 7

  8. Plane-sweep Algorithm 8

  9. Plane-sweep Algorithm 9

  10. Plane-sweep Algorithm 10

  11. Plane-sweep Algorithm 11

  12. Plane-sweep Algorithm 12

  13. Plane-sweep Algorithm 13

  14. Plane-sweep Algorithm 14

  15. Plane-sweep Algorithm 15

  16. Plane-sweep Algorithm 16

  17. Plane-sweep Algorithm 17

  18. Plane-sweep Algorithm 18

  19. Plane-sweep Algorithm 19

  20. Plane-sweep Algorithm 20

  21. Plane-sweep Algorithm 21

  22. Plane-sweep Algorithm 22

  23. Plane-sweep Algorithm 23

  24. Plane-sweep Algorithm 24

  25. Plane-sweep Algorithm 25

  26. Elements of Plane-sweep The sweep line: Sweeps the plane in specific direction, e.g., top-down The state of the sweep line 𝑇 : A set of all line segments that intersect the sweep line at any position. The state changes as the line move. The event points 𝐹 : Is the set of points where the state 𝑇 changes. In this case, the end points of the line segments comprise the event points. 26

  27. Example: Event Points (4,10) π‘š 1 𝒛 π’Ž 𝒋 Start/End (1,7) π‘š 1 10 Start π‘š 2 7 π‘š 2 Start (5,6) π‘š 3 6 Start (3,5) (2,5) π‘š 3 π‘š 1 5 End 5 π‘š 2 End (3,3) π‘š 3 3 End 27

  28. Plane-sweep Simple Impl. Input 𝑀 = π‘š 𝑗 π‘š 𝑗 = π‘š 𝑗 . π‘ž 1 , π‘š 𝑗 . π‘ž 2 𝐹 = the list of 𝑧 -coordinates sorted in decreasing order 𝑇 = {} For each event with a corresponding line π‘š 𝑗 If top point Compare π‘š 𝑗 to each 𝑑 ∈ 𝑇 Insert π‘š 𝑗 to S If end point Remove π‘š 𝑗 from S 28

  29. Plane-sweep Poor Behavior 𝑃 π‘œ 2 29

  30. Bentley-Ottmann Algorithm An improved scan-line algorithm Maintains the state S in a sorted order to speed up checking a line segment against segments in S 30

  31. Example Sweep line state (in sorted order) 31

  32. Algorithm Pseudo code Create a list of event points 𝑄 𝑄 is always sorted by the 𝑧 coordinate Initialize the state 𝑇 to an empty list Initialize 𝑄 with the first point (top point) of each line segment While 𝑄 is not empty π‘ž  𝑄 .pop 𝑧 𝑑 = π‘ž. 𝑧 processEvent( π‘ž ) 32

  33. Process Event Point (p) // p is the top (starting) point If π‘ž is the top point Add π‘ž. π‘š to 𝑇 at the order π‘ž. 𝑦 ( π‘ž. π‘š = 𝑇𝑗 ) checkIntersection( 𝑇 π‘—βˆ’1 , 𝑇 𝑗 ) checkIntersection( 𝑇 𝑗 , 𝑇 𝑗+1 ) Add the end point of π‘ž. π‘š to 𝑄 33

  34. Process Event Point (p) // p is the bottom (ending) point If π‘ž is the bottom point // let π‘ž. π‘š be at position 𝑇 𝑗 before removal Remove π‘ž. π‘š from 𝑇 checkIntersection( 𝑇 π‘—βˆ’1 , 𝑇 𝑗 ) 34

  35. Process Event Point (p) If π‘ž is an interior point Report π‘ž as an intersection Find π‘ž. π‘š in 𝑇 ( π‘ž. π‘š = 𝑇 𝑗 , 𝑇 𝑗+1 ) Swap( 𝑇 𝑗 , 𝑇 𝑗+1 ) checkIntersection( 𝑇 π‘—βˆ’1 , 𝑇 𝑗 ) checkIntersection( 𝑇 𝑗+1 , 𝑇 𝑗+2 ) 35

  36. Check Intersection( π‘š 1 , π‘š 2 ) If π‘š 1 does not intersect π‘š 2 then return Compute the intersection π‘ž 𝑗 of π‘š 1 and π‘š 2 If π‘ž 𝑗 . 𝑧 is above the sweep line then return If π‘ž 𝑗 ∈ 𝑄 then return Insert π‘ž 𝑗 into 𝑄 36

  37. Sweep Line State ( 𝑇 ) A list of line segments [π‘š 𝑗 ] Sorted by the 𝑦 -coordinate of the intersections between π‘š 𝑗 and the sweep line π‘š 𝑗 0 . 𝑦 + Δ𝑦 π‘š 𝑗 [1] Δ𝑧 𝑧 𝑑 βˆ’ π‘š 𝑗 0 . 𝑧 , 𝑧 𝑑 𝑧 𝑑 Δ𝑧 Δ𝑦 π‘š 𝑗 [0] 37

  38. Analysis Initial sort of starting points 𝑃 π‘œ β‹… log π‘œ Number of processed event points 2π‘œ + 𝑙 For each event point Remove from P: 𝑃 log 𝑄 Insert or remove from S: 𝑃 log 𝑇 Check intersection with at most two lines: 𝑃 1 Insert a new event points: 𝑃 log 𝑄 Upper limit of 𝑄 = 2π‘œ Upper limit of 𝑇 = π‘œ Overall running time 𝑃 π‘œ + 𝑙 log π‘œ 38

  39. Corner Case 1: Horizontal Line If two points have the same y-coordinate, sort l 1 them by the x-coordinate l 2 Starting point l 3 39

  40. Corner Case 2: Three Intersecting Lines l 1 l 2 l 3 Allow the event point to store a list of all intersecting line segments When processed, reverse the order of all the lines 40

  41. Rectangle Intersection Given a set of orthogonal rectangles ( 𝑆 ), find the set of all intersections between pairs of rectangles 𝑠 1 ∩ 𝑠 2 : 𝑠 1 , 𝑠 2 ∈ 𝑆 41

  42. Example r1 r2 r3 r4 42

  43. Example r1 r2 r3 r4 43

  44. Rectangle Primitives An orthogonal rectangle is represented by its two corner points, lower and upper Test if two rectangles overlap Two rectangles overlap if both their x intervals and y-intervals overlap Intervals overlap [x1,x2], [x3,x4]: x4>=x1 and x2>=x3 R1(x1,y1,x2,y2) Γ— R2(x3,y3,x4,y4) βž” R3(Max(x1,x3), Max(y1,y3), Min(x2,x4), Min(y2,y4)) 44

  45. NaΓ―ve Algorithm Test all pairs of rectangles and report the intersections Running time O(n 2 ) Is it optimal? 45

  46. Simple Plane-sweep Algo. r1 r2 r3 r4 46

  47. Simple Plane-sweep Algo. What is the state of the sweep line? What is an event? What processing should be done at each event? 47

  48. Improved Plane-sweep Algo. Keep the sweep line state sorted But how? Interval tree A variation of BST Stores intervals Supports two operation Find all intervals that overlap a query point π‘ž Find all intervals that overlap a query interval π‘Ÿ 48

  49. A Simple Interval Tree Store the intervals in a BST ordered by 𝑗. 𝑦 π‘›π‘—π‘œ Augment the BST with the value 𝑦 𝑛𝑏𝑦 which stores the maximum value of all the intervals in the subtree 50

  50. Augmented BST Credit: https://en.wikipedia.org/wiki/Interval_tree 51

  51. Polygon Intersection Given a set of polygons, find all intersecting polygons 52

  52. Polygon Representation A polygon is represented as a sequence of points that form its boundary p6 A general polygon Corners might also contain p7 p4 holes, e.g., a grass area p5 with a lake inside For simplicity, we will only p3 deal with solid polygons p2 with no holes p8 p1 Edge or Segment 53

  53. Filter-and-refine Approach Convert all polygons to rectangles For each polygon, compute its minimum bounding rectangle (MBR) Filter: Find all overlapping rectangles Refine: Test the polygons that have overlapping MBBs 54

  54. Filter-and-refine Approach Filter step: Already studied Refine: How to find the intersection of two polygons? For any two polygons, there are three cases: Polygons are disjoint 1. One polygon is contained in the other polygon 2. Polygon boundaries intersect 3. 55

  55. Case 1: Disjoint No intersection points Q P Neither 𝑄 βŠ‚ 𝑅 nor 𝑅 βŠ‚ 𝑄 The intersection is empty 56

  56. Case 2: Contained No intersection points Q If 𝑄 βŠ‚ 𝑅 , then any corner of P is ∈ 𝑅 If 𝑅 βŠ‚ 𝑄 , then any corner of Q is ∈ 𝑄 P The intersection is the contained polygon 57

  57. Case 3: Intersecting If the boundaries of the two polygons overlap, then there is at least two polygon edges that overlap NaΓ―ve solution: Compute all intersections between every pair of edges 𝑃 𝑛 β‹… π‘œ Where 𝑛 and π‘œ are the sizes of the two polygons We can also use the line-segment sweep-line algorithm Run in 𝑃 𝑙 + 𝐽 log 𝑙 where 𝑙 = 𝑛 + π‘œ and 𝐽 is the number of intersections If we only need to test, we can stop at the first intersection 58

  58. Computing the Intersection P Q 59

  59. Computing the Intersection P Q 60

  60. Computing the Intersection P Q 61

  61. Computing the Intersection P Q 62

  62. Computing the Intersection P Q 63

  63. Computing the Intersection P Q 64

  64. Computing the Intersection P Q 65

  65. Computing the Intersection P Q 66

  66. Computing the Intersection P Q 67

  67. Computing the Intersection P Q 68

  68. Computing the Intersection P Q 69

  69. Computing the Intersection P Q 70

  70. Computing the Intersection P Q 71

  71. Computing the Intersection P Q 72

  72. Special Case: Convex Polygons P Q 73

  73. Convex Polygon Overlaps Right-left Right-right Left-right left-left 74

  74. Left-right Split 75

  75. Left-right Overlap Test Observation: the points of each half are monotone along the 𝑧 -axis Start with the top two segments from each half-hull Do they intersect? No! Since the segments that form R L each hull are monotone (i.e., going down), there is no chance for the top red segment to intersect the green half-hull 76

Recommend


More recommend