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 cut Cake Cake 4/24/2018 3
Line Segment Intersections Given a set of line segments, each defined by two end points, find all intersecting line segments 4/24/2018 4
Line Segment Intersection 4/24/2018 5
Line Segment Intersection 4/24/2018 6
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
Plane-sweep Algorithm 4/24/2018 8
Plane-sweep Algorithm 4/24/2018 9
Plane-sweep Algorithm 4/24/2018 10
Plane-sweep Algorithm 4/24/2018 11
Plane-sweep Algorithm 4/24/2018 12
Plane-sweep Algorithm 4/24/2018 13
Plane-sweep Algorithm 4/24/2018 14
Plane-sweep Algorithm 4/24/2018 15
Plane-sweep Algorithm 4/24/2018 16
Plane-sweep Algorithm 4/24/2018 17
Plane-sweep Algorithm 4/24/2018 18
Plane-sweep Algorithm 4/24/2018 19
Plane-sweep Algorithm 4/24/2018 20
Plane-sweep Algorithm 4/24/2018 21
Plane-sweep Algorithm 4/24/2018 22
Plane-sweep Algorithm 4/24/2018 23
Plane-sweep Algorithm 4/24/2018 24
Plane-sweep Algorithm 4/24/2018 25
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
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
Example Sweep line state (in sorted order) 4/26/2018 28
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
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
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
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
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
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
Rectangle Intersection Given a set of rectangles, find all intersections 5/3/2018 35
Example r1 r2 r3 r4 5/3/2018 36
Example r1 r2 r3 r4 5/3/2018 37
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
NaΓ―ve Algorithm Test all pairs of rectangles and report the intersections Running time O(n 2 ) Is it optimal? 5/3/2018 39
Simple Plane-sweep Algo. r1 r2 r3 r4 5/3/2018 40
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
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
Interval Tree Structure X-center 5/3/2018 43
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
Augmented BST Credit: https://en.wikipedia.org/wiki/Interval_tree 5/3/2018 45
Polygon Intersection Given a set of polygons, find all intersecting polygons 5/3/2018 46
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
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
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
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
Computing the Intersection P Q 5/3/2018 51
Computing the Intersection P Q 5/3/2018 52
Computing the Intersection P Q 5/3/2018 53
Computing the Intersection P Q 5/3/2018 54
Computing the Intersection P Q 5/3/2018 55
Computing the Intersection P Q 5/3/2018 56
Computing the Intersection P Q 5/3/2018 57
Computing the Intersection P Q 5/3/2018 58
Computing the Intersection P Q 5/3/2018 59
Computing the Intersection P Q 5/3/2018 60
Computing the Intersection P Q 5/3/2018 61
Computing the Intersection P Q 5/3/2018 62
Computing the Intersection P Q 5/3/2018 63
Computing the Intersection P Q 5/3/2018 64
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
Case 3: Disjoint No intersection points Q P Neither π β π nor π β π The intersection is empty 5/3/2018 66
Special Case: Convex Polygons P Q 5/3/2018 67
Convex Polygon Overlaps Right-left Right-right Left-right left-left 5/3/2018 68
Left-right Split 5/3/2018 69
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
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
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
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
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
Recommend
More recommend