Computational Geometry · Lecture Line Segment Intersection
Total Page:16
File Type:pdf, Size:1020Kb
Computational Geometry · Lecture Line Segment Intersection INSTITUT FUR¨ THEORETISCHE INFORMATIK · FAKULTAT¨ FUR¨ INFORMATIK Tamara Mchedlidze · Darren Strash 26.10.2015 1 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection Aside: Organizational Items 2 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection Overlaying Map Layers Example: Given two different map layers whose intersection is of interest. Land use + Precipitation = Map combining themes 3 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection Overlaying Map Layers Example: Given two different map layers whose intersection is of interest. Land use + Precipitation = Map combining themes Regions are polygons Polygons are line segments Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection Problem Formulation Given: Set S = fs1; : : : ; sng of line segments in the plane Output: all intersections of two or more line segments for each intersection, the line segments involved. 4 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection Problem Formulation Given: Set S = fs1; : : : ; sng of line segments in the plane Output: all intersections of two or more line segments for each intersection, the line segments involved. Def: Line segments are closed 4 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection Problem Formulation Given: Set S = fs1; : : : ; sng of line segments in the plane Output: all intersections of two or more line segments for each intersection, the line segments involved. Def: Line segments are closed Discussion: { How can you solve this problem naively? { Is this already optimal? { Are their better approaches? 4 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection The Sweep-Line Method: An Example 5 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection The Sweep-Line Method: An Example Events 5 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection The Sweep-Line Method: An Example 5 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection The Sweep-Line Method: An Example sweep line 5 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection The Sweep-Line Method: An Example 5 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection The Sweep-Line Method: An Example 5 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection The Sweep-Line Method: An Example 5 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection The Sweep-Line Method: An Example 5 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection The Sweep-Line Method: An Example 5 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection The Sweep-Line Method: An Example 5 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection The Sweep-Line Method: An Example 5 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection The Sweep-Line Method: An Example 5 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection The Sweep-Line Method: An Example 5 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection The Sweep-Line Method: An Example 5 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection The Sweep-Line Method: An Example 5 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection The Sweep-Line Method: An Example 5 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection The Sweep-Line Method: An Example 5 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection The Sweep-Line Method: An Example 5 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection The Sweep-Line Method: An Example 5 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection The Sweep-Line Method: An Example 5 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection The Sweep-Line Method: An Example 5 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection The Sweep-Line Method: An Example 5 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection Data Structures 1.) Event Queue Q define p ≺ q ,def: yp > yq _ (yp = yq ^ xp < xq) p q ` 6 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection Data Structures 1.) Event Queue Q define p ≺ q ,def: yp > yq _ (yp = yq ^ xp < xq) p q ` Store events by ≺ in a balanced binary search tree ! e.g., AVL tree, red-black tree, . 6 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection Data Structures 1.) Event Queue Q define p ≺ q ,def: yp > yq _ (yp = yq ^ xp < xq) p q ` Store events by ≺ in a balanced binary search tree ! e.g., AVL tree, red-black tree, . Operations insert, delete and nextEvent in O(log jQj) time 6 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection Data Structures 1.) Event Queue Q define p ≺ q ,def: yp > yq _ (yp = yq ^ xp < xq) p q ` Store events by ≺ in a balanced binary search tree ! e.g., AVL tree, red-black tree, . Operations insert, delete and nextEvent in O(log jQj) time 2.) Sweep-Line Status T ` Stores ` cut lines ordered from left to right 6 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection Data Structures 1.) Event Queue Q define p ≺ q ,def: yp > yq _ (yp = yq ^ xp < xq) p q ` Store events by ≺ in a balanced binary search tree ! e.g., AVL tree, red-black tree, . Operations insert, delete and nextEvent in O(log jQj) time 2.) Sweep-Line Status T ` Stores ` cut lines ordered from left to right Required operations insert, delete, findNeighbor 6 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection Data Structures 1.) Event Queue Q define p ≺ q ,def: yp > yq _ (yp = yq ^ xp < xq) p q ` Store events by ≺ in a balanced binary search tree ! e.g., AVL tree, red-black tree, . Operations insert, delete and nextEvent in O(log jQj) time 2.) Sweep-Line Status T ` Stores ` cut lines ordered from left to right Required operations insert, delete, findNeighbor This is also a balanced binary search tree with line segments stored in the leaves! 6 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection Algorithm FindIntersections(S) Input: Set S of line segments Output: Set of all intersection points and the line segments involved Q ;; T ; foreach s 2 S do Q.insert(upperEndPoint(s)) Q.insert(lowerEndPoint(s)) while Q= 6 ; do p Q:nextEvent() Q.deleteEvent(p) handleEvent(p) 7 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection Algorithm FindIntersections(S) Input: Set S of line segments Output: Set of all intersection points and the line segments involved Q ;; T ; foreach s 2 S do Q.insert(upperEndPoint(s)) What happens Q.insert(lowerEndPoint(s)) with duplicates? while Q= 6 ; do p Q:nextEvent() Q.deleteEvent(p) handleEvent(p) 7 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection Algorithm FindIntersections(S) Input: Set S of line segments Output: Set of all intersection points and the line segments involved Q ;; T ; foreach s 2 S do Q.insert(upperEndPoint(s)) What happens Q.insert(lowerEndPoint(s)) with duplicates? while Q= 6 ; do p Q:nextEvent() Q.deleteEvent(p) handleEvent(p) This is the core of the algorithm! 7 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection Algorithm handleEvent(p) U(p) Line segments with p as upper endpoint L(p) Line segments with p as lower endpoint C(p) Line segments with p as interior point if jU(p) [ L(p) [ C(p)j ≥ 2 then return p and U(p) [ L(p) [ C(p) remove L(p) [ C(p) from T add U(p) [ C(p) to T if U(p) [ C(p) = ; then //sl and sr, neighbors of p in T Q check if sl and sr intersect below p else //s0 and s00 leftmost and rightmost line segment in U(p) [ C(p) 0 Q check if sl and s intersect below p 00 Q check if sr and s intersect below p 8 Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection Algorithm handleEvent(p) U(p) Line segments with p as upper endpointStored with p in Q L(p) Line segments with p as lower endpoint C(p) Line segments with p as interior point if jU(p) [ L(p) [ C(p)j ≥ 2 then return p and U(p) [ L(p) [ C(p) remove L(p) [ C(p) from T add U(p) [ C(p) to T if U(p) [ C(p) = ; then //sl and sr, neighbors of p in T Q check if sl and sr intersect below p else //s0 and s00 leftmost and rightmost line segment in U(p) [ C(p) 0 Q check