380 likes | 614 Views
CSE 4101/5101. Prof. Andy Mirzaian. Line Segments Intersections. Line Segments Intersections Thematic Map Overlay. Photos courtesy of ScienceGL. References:. [CLRS] chapter 33 [M. de Berge et al ’00] chapter 2 [Preparata-Shamos’85] chapter 7 [O’Rourke’98] chapter 7. Applications :
E N D
CSE 4101/5101 Prof. Andy Mirzaian Line Segments Intersections
Line Segments IntersectionsThematic Map Overlay Photos courtesy of ScienceGL
References: • [CLRS] chapter 33 • [M. de Berge et al ’00] chapter 2 • [Preparata-Shamos’85] chapter 7 • [O’Rourke’98] chapter 7 • Applications: • Graphics: hidden line/surface removal • GIS: Geographic Information Systems • Cartography • VLSI circuit layout • Pattern recognition • Optimization: Linear Programming • Arrangement of lines, planes, hyper-planes • Visibility, kernels, etc.
Line Segments Intersection Problem Given a setL={ l1,l2, … , ln}of n line segments in the plane, report all pair-wise intersections in L.(Modes: reporting, counting or disjointness.) • Naïve approach: check every pair in L in O(n2) time. • Can we make this output sensitive? • Suppose there are a total of R intersecting pairs to report, where 0 R (n2). • O(R + n log n) time is achievable for reporting mode. • O(n log n) time for counting & disjointness mode.
Special Case: rectilinear L Assume segments in L arevertical (blue)orhorizontal (red), and each intersection is between a red-blue pair. e.g., in VLSI
Special Case: rectilinear L Assume segments in L are vertical (blue) or horizontal (red), and each intersection is between a red-blue pair. Sweep-line d d c D a a e b b • Plane Sweep Method: vertical sweep-line moving left-to-right. • Active segments: horizontal segments that intersect the sweep-line. • Sweep event schedule: x-sorted segment endpoints (2 per red, 1 per blue). • Sweep Status: y-ordering of the active horizontal segments maintained in an efficient dictionary D.
Special Case: rectilinear L Assume segments in L are vertical (blue) or horizontal (red), and each intersection is between a red-blue pair. Sweep-line d d c c D a a e b b • Plane Sweep Method: vertical sweep-line moving left-to-right. • Active segments: horizontal segments that intersect the sweep-line. • Sweep event schedule: x-sorted segment endpoints (2 per red, 1 per blue). • Sweep Status: y-ordering of the active horizontal segments maintained in an efficient dictionary D.
Special Case: rectilinear L Assume segments in L are vertical (blue) or horizontal (red), and each intersection is between a red-blue pair. Sweep-line d e2 d c c e2 D a a e b b e1 e1 • Plane Sweep Method: vertical sweep-line moving left-to-right. • Active segments: horizontal segments that intersect the sweep-line. • Sweep event schedule: x-sorted segment endpoints (2 per red, 1 per blue). • Sweep Status: y-ordering of the active horizontal segments maintained in an efficient dictionary D.
Special Case: rectilinear L Assume segments in L are vertical (blue) or horizontal (red), and each intersection is between a red-blue pair. Sweep-line d c a e b • Plane Sweep Method: vertical sweep-line moving left-to-right. • Active segments: horizontal segments that intersect the sweep-line. • Sweep event schedule: x-sorted segment endpoints (2 per red, 1 per blue). • Sweep Status: y-ordering of the active horizontal segments maintained in an efficient dictionary D. • Computational Complexity: • O(n) space • O(R + n log n) time - reporting mode • O(n log n) time - counting or disjointness modes.
s2 D O(log n) forcounting or disjointness test RangeReport (s,D)O(Rs+ log n) time Rs = # with s s s1 s1 s2 Total time = O( n log n + s(Rs+ log n) ) = O(R + n log n). • Q {x-sorted end-points of segments in L} Sweep Schedule • D Sweep Status • for each event (p,s)Q in sorted order do O(n) iterations • if p is left-end of horizontal s then Insert (s,D) O(log n) time • if p is right-end of horizontal s then Delete (s,D) O(log n) time • if s is vertical then RangeReport (s,D) O(Rs+ log n) time • end AlgorithmRectilinear-Intersection-Report(L)
General Case Bentley-Ottman [1979], “Algorithms for reporting and counting geometric intersections,” IEEE Trans. Comput. C-28:643-647.O((R+n) log n) reporting time & O(n) space. D A sweep-line See also AAW E C B ECBAD EADC ECAD EACD EAD CBAD ED CBA BA A E Sweep status: Improved by: Balaban [1995], “An optimal algorithmfor finding segments intersections,”Proc. SoCG, pp:211-219.O(R + n log n) reporting time & O(n) space.
Bentley-Ottman • Data Structures: • Sweep Status D: an efficient dictionary to maintain the linear order of active segments in the order they intersect the sweep-line. • Sweep Schedule Q: a priority queue of sweep events (priority=x-coordinate). segments left/right end pointsEvent points = pair-wise segments intersection pointsBook-keeping:a constant number of two-way pointers between each segment and its contributed events in Q.
Bentley-Ottman Temporary assumption: No two events have the same priority. (lexicographic) FACT: Let p = li lj be an intersection event, and q its predecessor event. Just after q is processed, both li and lj are active and adjacent in the linear ordering of the sweep status D.Proof: The shaded region must be empty of segments. li p q lj Corollary: Every intersection event can eventually be detected and inserted into Q before the sweep-line gets past it.Proof:Each time the sweep status D changes, check its affected adjacent active segment pairs to see if they intersect to the right of the sweep-line.
Time = O( (R+n) log n ) Space used: |D| = O(n) size O(R+n) without “trimming” (see next slide) |Q| = O(n) with “trimming” Algorithm Bentley-Ottman(L) O( (R+n) log n ) time Q {the 2n end-points of segments in L} n=|L| D while Q do 2n+R iterations e DeleteMin(Q) O(log n) time ProcessEvent(e) O(log n) time end
ProcedureProcessEvent(e)O(log n ) time 1. Ife is left end-point of segment s then Insert (s,D); A Above(s,D); B Below(s,D) Insert As and/or Bs into Q if they are “future” events Trim: Delete AB from Q if it’s there 2.If e is right end-point of segment s then A Above(s,D); B Below(s,D); Delete(s,D) Insert AB into Q if it’s a “future” event 3.If e is si sjthen{ suppose si = Above(sj,D) } Interchange(si,sj,D); A Above(sj,D); B Below(si,D) Insert Asj and/or Bsi into Q if they are “future” events Trim: Delete Asi and Bsj from Q if they are thereREPORT (e = si sj) end A s e B A s e B A si e sj B
How to search in Dictionary D • D maintains the y-ordering of the active line segments along the sweep-line. • Each item in D is a line segment, with no explict “key”. • How do we search in D for an event point e? • Ask “is e vertically above/below node segment?”,then go to right/left subtree accordingly. B E D A D e E C C B A Search path of e in the dictionary sweep line
Generalizations of Bentley-Ottman • edges with common end-points edge – vertex intersections • Trapzoidization (or Vertical Visibility Map) These can be done during the plane-sweep without increase in computational complexity.
Sweep technique for intersection of other kinds of objects CONVEXNON-CONVEX A is above B Is A above B? A A B B
Proof: A,B [ (A,B P Q) (A,BP)(A,BQ) (AB P) (AB Q) (AB PQ) ]. P Q B A ax + by = c Examples of convex sets: Lines, line segments, convex polygons, half-planes, etc. Line: ax + by = c Half-plane: ax + by c (or ax + by c ) ax + by c ax + by c Intersection of two Convex Sets Fact 0: Intersection of any two convex sets is convex (possibly empty).
Intersection of two Convex Polygons Let P and Q be convex polygons with, respectively, n and m vertices. Consider the convex (possibly empty) polygon R = PQ. Fact 1: R has at most n+m vertices. Proof: Let e be any edge of P. e’ = eQ is convex, hence, either empty, a single vertex of Q, or a sub-segment of e. In the latter case e’ is an edge of R. (Similarly, with e an edge of Q and e’ = eP.) Each edge e of P or Q can contribute at most one such edge e’ to R. P and Q have n and m edges, respectively. Hence, R can have at most n+m edges.
Intersection of two Convex Polygons Fact 2:R = PQ can be computed in O(n+m) time. Proof: Use the plane-sweep method. The upper and lower chains of P and Q are x-monotone (from leftmost to rightmost vertex each). In O(n+m) time, merge these 4 x-sorted vertex-lists to obtain the n+m vertices of P and Q in x-sorted order. This forms the sweep-schedule. These n+m vertical sweep-lines partition the plane into n+m-1 vertical slabs. The intersection of each slab with P or Q is a trapezoid. The two trapezoids within a slab can be intersected in O(1) time. Hence, we can obtain PQ in O(n+m) time. slab
Intersection of n Half-Planes Problem:Given n half-planes H1, H2, … , Hn, compute their intersection R = H1 H2 … Hn . Input: Hi: ai x + bi y ci , i = 1..nOutput: convex polygon R (empty, bounded or unbounded). R
Intersection of n Half-Planes Problem:Given n half-planes H1, H2, … , Hn, compute their intersection R = H1 H2 … Hn . Divide-&-Conquerin O(n log n) time: (Use Facts 1 and 2.) (H1 … Hn/2) (H n/2 +1 … Hn ) Convex P, |P| n/2 T(n/2) time Convex Q, |Q| n/2 T(n/2) time Convex R = PQ, |R| |P|+|Q| nO(n) time T(n) = 2 T(n/2) + O(n) = O(n log n).
Linear Programming LP is a mathematical optimization problem: Given reals (aij), (bi), (cj), for i=1..n, j=1..d, Find reals (xj), j=1..d, to maximize c1 x1 + c2 x2 + … + cd xd subject to: a11 x1 + a12 x2 + … + a1d xdb1 a21 x1 + a22 x2 + … + a2d xdb2 an1 x1 + an2 x2 + … + and xdbn objective function constraints …
References: • [CLRS] chapter 29 • books on optimization listed on the course web page • Applications of LP: • Management science (Operations Research). • Engineering, technology, industry, commerce, economics. • Efficient resource allocation: • Airline transportation, • Communication network – opt. transmission routing, • Factoryinventory/production control, • Fund management, stock portfolio optimization. • Approximation of hard optimization problems. • …
Optimum x=5/3, y=1/4 x+y = y (1) (2) (5) (4) feasibleregion x (3) Objective -level x + y = . Increase : x + y maximize Example in 2D subject to: (5)
Optimum (x,y,z)=(0,0,3) z y x z maximize Example in 3D subject to:
2D Linear Programming 2D LP is a mathematical optimization problem:Given reals (aij), (bi), (cj), for i=1..n, j=1,2,Find a point (x,y) in the plane to maximize c1 x+ c2 y subject to: a11 x+ a12 yb1 a21 x+ a22 yb2 an1 x+ an2 ybn objective function n half-planes …
2D Linear Programming Objective value = c1 x+ c2 y Feasible region F increasing max = c1 x+ c2 y optimum F y x
2D Linear Programming • Feasible region F is the intersection of n half-planes. • F is possibly empty, bounded or unbounded convex polygon with n vertices. • F can be obtained in O(n log n) time by divide-&-conquer. • If F is empty, then LP is infeasible. • Otherwise, we can check its vertices, and its possibly up to 2 unbounded edges, to determine the optimum. • The latter step can be done by binary search in O(log n) time. • If objective changes but constraints do not, we can update the optimum in only O(log n) time. (We don’t need to start from scratch). • Megiddo’s prune-&-search technique solves 2D LP in O(n) time. To learn more about LP see my CSE6114 Lecture Slide on LP here.
An Art Gallery Problem We are given the floor-plan of an art gallery (with opaque walls) represented by a simple polygon P with n vertices. Is it possible to place a single point camera guard (with 360 vision) in the gallery so that it can “see” every point inside the gallery? • The set of all such points is called the “Kernel” of P. • If Kernel(P) is not empty, then P is called a “star” polygon. P
An Art Gallery Problem We are given the floor-plan of an art gallery (with opaque walls) represented by a simple polygon P with n vertices. Is it possible to place a single point camera guard (with 360 vision) in the gallery so that it can “see” every point inside the gallery? • The set of all such points is called the “Kernel” of P. • If Kernel(P) is not empty, then P is called a “star” polygon. • Kernel(P) is the intersection of n half-planes defined by P’s edges. P
An Art Gallery Problem We are given the floor-plan of an art gallery (with opaque walls) represented by a simple polygon P with n vertices. Is it possible to place a single point camera guard (with 360 vision) in the gallery so that it can “see” every point inside the gallery? • The set of all such points is called the “Kernel” of P. • If Kernel(P) is not empty, then P is called a “star” polygon. • Kernel(P) is the intersection of n half-planes defined by P’s edges. • Kernel(P) can be computed in O(n log n) time by divide-&-conquer. • It can be computed in O(n) time by a careful incremental method that scans the edges of P in order around its boundary. How? P
Nested Circles: We are given a set C = {C1 , ... , Cn} of n circles in the plane. Each circle is given by the xy-coordinates of its center and its radius. One of these circles is the bounding circle and encloses the remaining n -1 circles in C. All circles in C have disjoint boundaries. So, for any pair of circles Ci and Cj in C, either they are completely outside each other, or one encloses the other. Therefore, we may have several levels of nesting among these circles. (See Figure 1(a) below.) We say Ci is immediately enclosed by Cj, if Cj is the smallest circle that encloses Ci. This relationship corresponds to the parent-child relationship in the Nesting Tree of C. (See Figure 1(b) below.) The problem is: given C, construct its Nesting Tree by parent pointers, that is, output the array p[1.. n] such that p[i] = j means Ci is immediately enclosed by Cj .(a) Briefly describe a simple O(n2) time algorithm to solve the problem.(b) Design and analyze an O(n log n) time algorithm to solve the problem.
We are given a set T of n triangles and a set P of n points, all in the plane. The triangles in T have disjoint boundaries, but some triangles may enclose some others. There may be several nested levels of such enclosures. Design and analyze an O(n log n) time algorithm that reports all points in P that are outside all triangles in T. • Design efficient plane-sweep algorithms to decide whether a given set S of n objects from a certain object class is pair-wise disjoint for the following cases:(a) Objects are circular disks. (A disk includes the interior.)(b) Objects are circles. (A circle does not include the interior.)(c) Objects are axis-parallel rectangular areas. • We are given n axis-parallel rectangular areas in the plane. Assume the plane background is white and the given rectangle areas are painted blue. Design an O(n log n) time algorithm to compute the total blue area. • We are given two simple polygons P and Q with n and m vertices, respectively.(a) Design and analyze an efficient algorithm to test whether P is completely inside Q.(b) Show an O(n+m) time solution if in addition we know Q is convex. • Show the kernel of a given simple polygon can be computed in linear time.