cs133
play

CS133 Computational Geometry Intersection Problems 4/24/2018 1 - PowerPoint PPT Presentation

CS133 Computational Geometry Intersection Problems 4/24/2018 1 Riddle: Fair Cake-cutting Using only one cut, how to split the cake into two equal pieces (by area)? Cake 4/24/2018 2 Riddle: Fair cake-cutting Cake with a hole! Still one


  1. CS133 Computational Geometry Intersection Problems 4/24/2018 1

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

  3. Riddle: Fair cake-cutting Cake with a hole! Still one cut Cake Cake 4/24/2018 3

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

  5. Line Segment Intersection 4/24/2018 5

  6. Line Segment Intersection 4/24/2018 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? 4/24/2018 7

  8. Plane-sweep Algorithm 4/24/2018 8

  9. Plane-sweep Algorithm 4/24/2018 9

  10. Plane-sweep Algorithm 4/24/2018 10

  11. Plane-sweep Algorithm 4/24/2018 11

  12. Plane-sweep Algorithm 4/24/2018 12

  13. Plane-sweep Algorithm 4/24/2018 13

  14. Plane-sweep Algorithm 4/24/2018 14

  15. Plane-sweep Algorithm 4/24/2018 15

  16. Plane-sweep Algorithm 4/24/2018 16

  17. Plane-sweep Algorithm 4/24/2018 17

  18. Plane-sweep Algorithm 4/24/2018 18

  19. Plane-sweep Algorithm 4/24/2018 19

  20. Plane-sweep Algorithm 4/24/2018 20

  21. Plane-sweep Algorithm 4/24/2018 21

  22. Plane-sweep Algorithm 4/24/2018 22

  23. Plane-sweep Algorithm 4/24/2018 23

  24. Plane-sweep Algorithm 4/24/2018 24

  25. Plane-sweep Algorithm 4/24/2018 25

  26. Plane-sweep Simple Impl. Input 𝑀 = π‘š 𝑗 π‘š 𝑗 = π‘š 𝑗 . π‘ž 1 , π‘š 𝑗 . π‘ž 2 Prepare a sorted list of all y coordinates S={} For each stop with a corresponding line π‘š 𝑗 If top point Compare π‘š 𝑗 to each 𝑑 ∈ 𝑇 Insert π‘š 𝑗 to S If end point Remove π‘š 𝑗 from S 4/24/2018 26

  27. 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 4/26/2018 27

  28. Example Sweep line state (in sorted order) 4/26/2018 28

  29. Algorithm Pseudo code Create a list of event points P P is always sorted by the y coordinate Initialize the state S to an empty list Initialize P with the first point (top point) of each line segment While P is not empty p  P.pop processEvent(p) 4/26/2018 29

  30. Process Event Point (p) If p is the top point Add p.l to S at the order p.x (p.l=S i ) checkIntersection(S i-1 , S i ) checkIntersection(S i , S i+1 ) Add the end point of p.l to P If p is the bottom point Remove p.l from S (p.l=S i before removal) checkIntersection(S i-1 ,S i ) If p is an interior point Report p as an intersection Find p.l in S (p.l=S i ) Swap(S i ,S i+1 ) checkIntersection(S i-1 , S i ) checkIntersection(S i , S i+1 ) 4/26/2018 30

  31. Check Intersection(l 1 , l 2 ) If l 1 does not intersect l 2 then return Compute the intersection p i of l 1 and l 2 If p i .y is above the sweep line then return If π‘ž 𝑗 ∈ 𝑄 then return Insert p i into P 4/26/2018 31

  32. Analysis Initial sort of starting points O(n log n) Number of processed event points (2n+k) For each event point Remove from P: O(log |P|) Insert or remove from S: O(log |S|) Check intersection with at most two lines: O(1) Insert a new event points: O(log |P|) Upper limit of |P| = 2n Upper limit of |S| = n Overall running time O((n+k)log n) 4/24/2018 32

  33. 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 4/26/2018 33

  34. 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 4/26/2018 34

  35. Rectangle Intersection Given a set of rectangles, find all intersections 5/3/2018 35

  36. Example r1 r2 r3 r4 5/3/2018 36

  37. Example r1 r2 r3 r4 5/3/2018 37

  38. Rectangle Primitives A 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)) 5/3/2018 38

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

  40. Simple Plane-sweep Algo. r1 r2 r3 r4 5/3/2018 40

  41. Simple Plane-sweep Algo. What is the state of the sweep line? What is an event? What processing should be done at each event? 5/3/2018 41

  42. 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 π‘Ÿ 5/3/2018 42

  43. Interval Tree Structure X-center 5/3/2018 43

  44. A Simpler Interval Tree Store the intervals in a BST ordered by i.x min Augment the BST with the value x max which stores the maximum value of all the intervals in the subtree 5/3/2018 44

  45. Augmented BST Credit: https://en.wikipedia.org/wiki/Interval_tree 5/3/2018 45

  46. Polygon Intersection Given a set of polygons, find all intersecting polygons 5/3/2018 46

  47. 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 5/3/2018 47

  48. 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 5/3/2018 48

  49. 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: Polygon boundaries intersect 1. Polygons are disjoint 2. One polygon is contained in the other polygon 3. 5/3/2018 49

  50. Test Case 1: 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 5/3/2018 50

  51. Computing the Intersection P Q 5/3/2018 51

  52. Computing the Intersection P Q 5/3/2018 52

  53. Computing the Intersection P Q 5/3/2018 53

  54. Computing the Intersection P Q 5/3/2018 54

  55. Computing the Intersection P Q 5/3/2018 55

  56. Computing the Intersection P Q 5/3/2018 56

  57. Computing the Intersection P Q 5/3/2018 57

  58. Computing the Intersection P Q 5/3/2018 58

  59. Computing the Intersection P Q 5/3/2018 59

  60. Computing the Intersection P Q 5/3/2018 60

  61. Computing the Intersection P Q 5/3/2018 61

  62. Computing the Intersection P Q 5/3/2018 62

  63. Computing the Intersection P Q 5/3/2018 63

  64. Computing the Intersection P Q 5/3/2018 64

  65. 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 5/3/2018 65

  66. Case 3: Disjoint No intersection points Q P Neither 𝑄 βŠ‚ 𝑅 nor 𝑅 βŠ‚ 𝑄 The intersection is empty 5/3/2018 66

  67. Special Case: Convex Polygons P Q 5/3/2018 67

  68. Convex Polygon Overlaps Right-left Right-right Left-right left-left 5/3/2018 68

  69. Left-right Split 5/3/2018 69

  70. Left-right Overlap Test Compare the end point of one line segment to the other line segment using Half space L R If the end point of R is to the right of the segment in L βž” Skip R. Why? 5/3/2018 70

  71. Left-right Overlap Test Compare the end point of one line segment to the other line segment using Half space L R Is the end point of R to the right of the segment in L? No! Do the line segments intersect? No! Switch to L Why? 5/3/2018 71

  72. Left-right Overlap Test Compare the end point of one line segment to the other line segment using Half space L R If the end point of L is to the left of the segment in R βž” Skip L 5/3/2018 72

  73. Left-right Overlap Test Compare the end point of one line segment to the other line segment using Half space L R Is the end point of L to the left of R? No! Do the line segments intersect? No! Switch to R 5/3/2018 73

  74. Left-right Overlap Test Compare the end point of one line segment to the other line segment using Half space L R Is the end point of R to the right of L? Yes! Skip R 5/3/2018 74

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend