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 3
Line Segment Intersections Given a set of line segments, each defined by two end points, find all intersecting line segments 4
Line Segment Intersection 5
Line Segment Intersection 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? 7
Plane-sweep Algorithm 8
Plane-sweep Algorithm 9
Plane-sweep Algorithm 10
Plane-sweep Algorithm 11
Plane-sweep Algorithm 12
Plane-sweep Algorithm 13
Plane-sweep Algorithm 14
Plane-sweep Algorithm 15
Plane-sweep Algorithm 16
Plane-sweep Algorithm 17
Plane-sweep Algorithm 18
Plane-sweep Algorithm 19
Plane-sweep Algorithm 20
Plane-sweep Algorithm 21
Plane-sweep Algorithm 22
Plane-sweep Algorithm 23
Plane-sweep Algorithm 24
Plane-sweep Algorithm 25
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
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
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
Plane-sweep Poor Behavior π π 2 29
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
Example Sweep line state (in sorted order) 31
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
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
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
Process Event Point (p) If π is an interior point Report π as an intersection Find π. π in π ( π. π = π π , π π+1 ) Swap( π π , π π+1 ) checkIntersection( π πβ1 , π π ) checkIntersection( π π+1 , π π+2 ) 35
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
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
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
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
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
Rectangle Intersection Given a set of orthogonal rectangles ( π ), find the set of all intersections between pairs of rectangles π 1 β© π 2 : π 1 , π 2 β π 41
Example r1 r2 r3 r4 42
Example r1 r2 r3 r4 43
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
NaΓ―ve Algorithm Test all pairs of rectangles and report the intersections Running time O(n 2 ) Is it optimal? 45
Simple Plane-sweep Algo. r1 r2 r3 r4 46
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
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
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
Augmented BST Credit: https://en.wikipedia.org/wiki/Interval_tree 51
Polygon Intersection Given a set of polygons, find all intersecting polygons 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
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
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
Case 1: Disjoint No intersection points Q P Neither π β π nor π β π The intersection is empty 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
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
Computing the Intersection P Q 59
Computing the Intersection P Q 60
Computing the Intersection P Q 61
Computing the Intersection P Q 62
Computing the Intersection P Q 63
Computing the Intersection P Q 64
Computing the Intersection P Q 65
Computing the Intersection P Q 66
Computing the Intersection P Q 67
Computing the Intersection P Q 68
Computing the Intersection P Q 69
Computing the Intersection P Q 70
Computing the Intersection P Q 71
Computing the Intersection P Q 72
Special Case: Convex Polygons P Q 73
Convex Polygon Overlaps Right-left Right-right Left-right left-left 74
Left-right Split 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