160 likes | 317 Views
Line Segment Intersection. Computational Geometry, WS 2006/07 Lecture 3 – Part II Prof. Dr. Thomas Ottmann. Algorithmen & Datenstrukturen, Institut für Informatik Fakultät für Angewandte Wissenschaften Albert-Ludwigs-Universität Freiburg. Line Segment Intersection.
E N D
Line Segment Intersection Computational Geometry, WS 2006/07 Lecture 3 – Part II Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät für Angewandte Wissenschaften Albert-Ludwigs-Universität Freiburg
Line Segment Intersection • Motivation: Computing the overlay of several maps • The Sweep-Line-Paradigm: A visibilityproblem • Line Segment Intersection • Overlay of planar subdivisions Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann
Line segment intersection Input: SetS={s1...,sn } of n closed line segmentssi={(xi, yi), (x´i, y´i)} Output: All intersection points among the segments in S The intersection of two lines can be computed in time O(1). Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann
Sweep line principle Event queue: upper, lower, intersection points Status structure: Ordered set of active line segments Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann
Example: Segment Intersection Q T A .A B .B B .C C D .D C. .E E B. A. D. E. Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann
Data structures: Event Queue Q Operations: Initialisation (sequence of upper and lower endpoints of segments in decreasing y-order), min-delete, insertion (of intersection points) Implementation: Balanced search tree with order p < q py < qy or (py = qy and px < qx) Space: O(n + k),k = #intersections Time: Initialisation: O(n log n) Min-delete: O(log n) Insertion: O(log n) Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann
k i l k l i l m j i m j j k Data structures: Status structure T Operations: insertion, deletion, neighbor search, (changing order) Space: O(n) Time: O(log n) Balanced search tree Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann
Number of operations, total time n = #segments k = #intersections Number of operations on event queue Q: ≤ 2n+k, Number of operations on status structure T: ≤ 2n+k Result: Total time required to carry out the sweep-line algorithm for computing all k intersections in a set of n line segments is O((n+k) log n). The sweep-line algorithm is output sensitive! Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann
Proof:L is so close to p that siand sjare next to each other. Since siand sj are not yet adjacent at the beginning of the algorithm there is an event qwhere si and sj become adjacent and tested for intersection. L p si sj A simple neighborhood lemma Lemma : Let siand sj be two non-horizontal segments intersecting in a single point p and no third segment passing through p. Then there is an event point above p where siand sjbecome adjacent and are tested for intersection. Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann
Handling special cases 1 3 7 4 5 8 L P 1 3 2 Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann
Special cases I 1 1 3 5 3 7 4 5 8 8 7 3 L 4 P C(P) 7 5 4 1 1 3 L(P) 2 Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann
Special cases II 2 1 3 3 1 7 4 5 8 8 L 7 2 1 P U(P) C(P) 7 3 1 3 C(P) 2 Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann
if ( L(p) U(p) C(p) contains more than1 segment) then {report p as intersection; delete L(p) C(p) from T; insert U(p) C(p) into T;} if (U(p) C(p) = {}) then {Let sl and sr be left and right neighbours of p in T FindNewEvent(sl,sr,p) else s´ = leftmost segment of U(p) C(p) in T sl = left neighbour of s´ in T FindNewEvent(sl,s´,p) s´´ = rightmost segment of U(p) C(p) sr = right neighbour of s´´ in T FindNewEvent(s´´,sr,p) HandleEventPoint(p) Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann
FindNewEvent(s,s´,p) If (s and s´ intersect below the sweep line L or on it and to the right of the current event point p) and (the intersection of s and s´is not yet present in Q) then insert the intersection point into Q; Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann
Summary Theorem: Let S be a set of n line segments in the plane. All intersection points in S, with for each intersection point the segments involved in it, can be reported in O(n log n + k log n) time and O(n) space, where k is the size of the output.. k can be reduced to I, I = #intersections Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann