Computational Geometry: Line segment intersection



Similar documents
INTERSECTION OF LINE-SEGMENTS

Computational Geometry. Lecture 1: Introduction and Convex Hulls

EE602 Algorithms GEOMETRIC INTERSECTION CHAPTER 27

Line Segment Intersection

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

From Last Time: Remove (Delete) Operation

Algorithms. Algorithms GEOMETRIC APPLICATIONS OF BSTS. 1d range search line segment intersection kd trees interval search trees rectangle intersection

A Note on Maximum Independent Sets in Rectangle Intersection Graphs

EQUATIONS and INEQUALITIES

Approximation of an Open Polygonal Curve with a Minimum Number of Circular Arcs and Biarcs

- Easy to insert & delete in O(1) time - Don t need to estimate total memory needed. - Hard to search in less than O(n) time

Shortest Path Algorithms

Arrangements And Duality

Linear Referencing Tutorial

Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * *

A binary heap is a complete binary tree, where each node has a higher priority than its children. This is called heap-order property

The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge,

5.4 Closest Pair of Points

Finding and counting given length cycles

Data Structures. Jaehyun Park. CS 97SI Stanford University. June 29, 2015

Cpt S 223. School of EECS, WSU

The minimum number of distinct areas of triangles determined by a set of n points in the plane

Graphs without proper subgraphs of minimum degree 3 and short cycles

Persistent Data Structures and Planar Point Location

Topology and Topological Rules Geometric properties that are maintained in spatial databases

Find-The-Number. 1 Find-The-Number With Comps

Heaps & Priority Queues in the C++ STL 2-3 Trees

Figure 2.1: Center of mass of four points.

Outline BST Operations Worst case Average case Balancing AVL Red-black B-trees. Binary Search Trees. Lecturer: Georgy Gimel farb

Big Data and Scripting. Part 4: Memory Hierarchies

Triangulation by Ear Clipping

Offline sorting buffers on Line

Special Situations in the Simplex Algorithm

Scan-Line Fill. Scan-Line Algorithm. Sort by scan line Fill each span vertex order generated by vertex list

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) Total 92.

Binary search algorithm

Sorting revisited. Build the binary search tree: O(n^2) Traverse the binary tree: O(n) Total: O(n^2) + O(n) = O(n^2)

6 March Array Implementation of Binary Trees

Binary Heaps. CSE 373 Data Structures

How to georectify an image in ArcMap 10

Persistent Data Structures

Binary Heap Algorithms

Dynamic Programming. Lecture Overview Introduction

Lecture 4 Online and streaming algorithms for clustering

Shortest Inspection-Path. Queries in Simple Polygons

E XPLORING QUADRILATERALS

CSC148 Lecture 8. Algorithm Analysis Binary Search Sorting

Loop Invariants and Binary Search

Algorithms and Data Structures

Degeneracy in Linear Programming

Introduction to PostGIS

1 Computational Geometry

Lesson 26: Reflection & Mirror Diagrams

Pro/ENGINEER Wildfire 5.0 Introduction to Surface Modeling

Distributed Computing over Communication Networks: Maximal Independent Set

Data Structures Fibonacci Heaps, Amortized Analysis

Using Linear Programming in Real-Life Problems

ASSIGNMENT 4 PREDICTIVE MODELING AND GAINS CHARTS

NCPC 2013 Presentation of solutions

MD5-26 Stacking Blocks Pages

Data Structure [Question Bank]

Approximation Algorithms

Linear Programming I

Connectivity and cuts

6.080 / Great Ideas in Theoretical Computer Science Spring 2008

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Linda Shapiro Winter 2015

Binary Search Trees. Data in each node. Larger than the data in its left child Smaller than the data in its right child

BALTIC OLYMPIAD IN INFORMATICS Stockholm, April 18-22, 2009 Page 1 of?? ENG rectangle. Rectangle

2x + y = 3. Since the second equation is precisely the same as the first equation, it is enough to find x and y satisfying the system

Algorithm Design and Analysis Homework #1 Due: 5pm, Friday, October 4, 2013 TA === Homework submission instructions ===

Project and Production Management Prof. Arun Kanda Department of Mechanical Engineering Indian Institute of Technology, Delhi

Activity 1: Using base ten blocks to model operations on decimals

Graph Theory Problems and Solutions

GRAPH THEORY LECTURE 4: TREES

SolidWorks Implementation Guides. Sketching Concepts

Cloud and Big Data Summer School, Stockholm, Aug Jeffrey D. Ullman

Data Warehousing und Data Mining

CS711008Z Algorithm Design and Analysis

Lecture 6 Online and streaming algorithms for clustering

Regions in a circle. 7 points 57 regions

The following is an overview of lessons included in the tutorial.

Introduction Solvability Rules Computer Solution Implementation. Connect Four. March 9, Connect Four

Understand the Sketcher workbench of CATIA V5.

Closest Pair Problem

Guessing Game: NP-Complete?

Tessellating with Regular Polygons

Angles and Quadrants. Angle Relationships and Degree Measurement. Chapter 7: Trigonometry

arxiv: v1 [math.co] 7 Mar 2012

Chapter 4 One Dimensional Kinematics

Duplicating Segments and Angles

Social Media Mining. Graph Essentials

or, put slightly differently, the profit maximizing condition is for marginal revenue to equal marginal cost:

ArcGIS Online. Visualizing Data: Tutorial 3 of 4. Created by: Julianna Kelly

E-Mapping Troubleshooting - page 1. Microsoft Silverlight 2. Why Use Microsoft Silverlight? 2. Which Version of Silverlight do I have?

2. Length and distance in hyperbolic geometry

Spatial Adjustment Tools: The Tutorial

Transcription:

: Line segment intersection Panos Giannopoulos Wolfgang Mulzer Lena Schlipf AG TI SS 2013

Tutorial room change: 055 this building!!! (from next monday on)

Outline Motivation Line segment intersection (and the sweep line paradigm) Assignment 3 CGAL and Google Summer of Code FU Berlin : SS 2013 3

Map layers Map layers In a geographic information system (GIS) data is stored in separate layers A layer stores the geometric information about some theme like land cover road network municipality boundaries red fox habitat... FU Berlin : SS 2013 4

Map overlay Map overlay Map overlay is the combination of two (or more) map layers It is needed to answer questions like: What is the total length of roads through forests? What is the total area of corn fields within 1 km from a river? What area of all lakes occurs at the geological soil type rock? FU Berlin : SS 2013 5

Map overlay Map overlay To solve map overlay questions we need (at the least) intersection points from two sets of line segments (possibly boundaries of regions) FU Berlin : SS 2013 5

Some attempts The (easy) problem The (easy) problem Let s first look at the easiest version of the problem: Given a set of of n line segments in the plane find all intersection points efficiently FU Berlin : SS 2013 6

Some attempts An easy optimal algorithm? An easy optimal algorithm? Algorithm FindIntersections(S) Input. A set S of line segments in the plane. Output. The set of intersection points among the segments in S. 1. for each pair of line segments ei ej S 2. do if ei and ej intersect 3. then report their intersection point Question: Why can we say that this algorithm is optimal? FU Berlin : SS 2013 7

Well.. Motivation Line segment intersection Problem Output-sensitive algorithms Some attempts FU Berlin : SS 2013 8

Line segment intersection Output-sensitive algorithms Some attempts Output sensitive algorithm Output-sensitive algorithm The asymptotic running time of an algorithm is always input-sensitive (depends on n) We may also want the running time to be output-sensitive: if the output is large it is fine to spend a lot of time but if the output is small we want a fast algorithm FU Berlin : SS 2013 9

Line segment intersection Output-sensitive algorithms Some attempts Intersection points in practice Intersection points in practice Question: How many intersection points do we typically expect in our application? If this number is k and if k = O(n) it would be nice if the algorithm runs in O(n log n) time FU Berlin : SS 2013 10

Line segment intersection Output-sensitive algorithms Some attempts First attempt First attempt Observation: Two line segments can only intersect if their y-spans have an overlap y So how about only testing pairs of line segments that intersect in the y-projection? x 1D problem: Given a set of intervals on the real line find all partly overlapping pairs s1 s2 s3 s4 s5 s6 (s1 s2 ) (s4 s6 ) (s5 s6 ) FU Berlin : SS 2013 11

Line segment intersection Output-sensitive algorithms Some attempts First attempt First attempt 1D problem: Given a set of intervals on the real line find all partly overlapping pairs Sort the endpoints and handle them from left to right; maintain currently intersected intervals in a balanced search tree T Left endpoint of si : for each sj in T report the pair si sj. Then insert si in T Right endpoint of si : delete si from T Question: Is this algorithm output-sensitive for 1D interval intersection? FU Berlin : SS 2013 11

Line segment intersection Output-sensitive algorithms Some attempts First attempt First attempt Back to the 2D problem: Determine the y-intervals of the 2D line segments Find the intersecting pairs of intervals with the 1D solution For every pair of intersecting intervals test whether the corresponding line segments intersect and if so report Question: Is this algorithm output-sensitive for 2D line segment intersection? FU Berlin : SS 2013 11

Line segment intersection Output-sensitive algorithms Some attempts Second attempt Second attempt Refined observation: Two line segments can only intersect if their y-spans have an overlap and they are adjacent in the x-order at that y-coordinate (they are horizontal neighbors) FU Berlin : SS 2013 12

Line segment intersection The plane sweep technique: Imagine a horizontal line passing over the plane from top to bottom solving the problem as it moves The sweep line stops and the algorithm computes at certain positions events The algorithm stores the relevant situation at the current position of the sweep line status The algorithm knows everything it needs to know above the sweep line and found all intersection points FU Berlin : SS 2013 13

Sweep Sweep computed unexplored FU Berlin : SS 2013 14

Sweep and status Sweep and status computed status unexplored FU Berlin : SS 2013 15

Status Statusand andevents events The status of this particular plane sweep algorithm at the current position of the sweep line is the set of line segments intersecting the sweep line ordered from left to right The events occur when the status changes and when output is generated event interesting y-coordinate FU Berlin : SS 2013 16

Introduction Events status structures Motivation Line segment intersection Example: s1 s3 s2 s4 add s1 s5 s6 s7 s8 FU Berlin : SS 2013 17

Introduction Events status structures Motivation Line segment intersection Example: s1 s3 s2 s4 add s2 after s1 s5 s6 s7 s8 FU Berlin : SS 2013 17

Introduction Events status structures Motivation Line segment intersection Example: s1 s3 s2 s4 add s3 between s1 and s2 s5 s6 s7 s8 FU Berlin : SS 2013 17

Introduction Events status structures Motivation Line segment intersection Example: s1 s3 s2 s4 add s4 before s1 s5 s6 s7 s8 FU Berlin : SS 2013 17

Introduction Events status structures Motivation Line segment intersection Example: s1 s3 s2 s4 report intersection (s1 s2 ); swap s1 and s3 s5 s6 s7 s8 FU Berlin : SS 2013 17

Introduction Events status structures Motivation Line segment intersection Example: s1 s3 s2 s4 remove s2 s5 s6 s7 s8 FU Berlin : SS 2013 17

Introduction Events status structures Motivation Line segment intersection Example: s1 s3 s2 s4 remove s1 s5 s6 s7 s8 FU Berlin : SS 2013 17

Introduction Events status structures Motivation Line segment intersection Example: s1 s3 s2 s4 add s5 after s3 s5 s6 s7 s8 FU Berlin : SS 2013 17

Introduction Events status structures Motivation Line segment intersection Example: s1 s3 s2 s4 report intersection (s3 s4 ); swap s3 and s4 s5 s6 s7 s8 FU Berlin : SS 2013 17

Example: Motivation Line segment intersection Introduction Events status structures... and so on... FU Berlin : SS 2013 17

The Theevents events When do the events happen? When the sweep line is at an upper endpoint of a line segment a lower endpoint of a line segment an intersection point of a line segment At each type the status changes; at the third type output is found too FU Berlin : SS 2013 18

Assume no degenerate cases Assume no degenerate cases We will at first exclude degenerate cases: No two endpoints have the same y-coordinate No more than two line segments intersect in a point... Question: Are there more degenerate cases? FU Berlin : SS 2013 19

Event Eventlist listand andstatus status structure structure The event list is an abstract data structure that stores all events in the order in which they occur The status structure is an abstract data structure that maintains the current status Here: The status is the subset of currently intersected line segments in the order of intersection by the sweep line FU Berlin : SS 2013 20

Status Statusstructure structure We use a balanced binary search tree with the line segments in the leaves as the status structure s4 s2 s6 s1 s1 s1 s3 s2 s3 s2 s5 s4 s3 s5 s4 s7 s6 s5 s7 s8 s6 s7 s8 FU Berlin : SS 2013 21

Status Statusstructure structure s4 s2 s6 s1 s1 s1 s3 s2 s3 s2 s5 s4 s3 s5 s4 s7 s6 s5 s9 s7 s8 s6 s7 s8 Upper endpoint: search and insert FU Berlin : SS 2013 21

Status Statusstructure structure s4 s2 s6 s1 s1 s1 s3 s2 s3 s2 s5 s4 s3 s5 s4 s7 s6 s5 s9 s7 s8 s6 s7 s8 Upper endpoint: search and insert FU Berlin : SS 2013 21

Status Statusstructure structure s4 s2 s6 s1 s1 s3 s2 s9 s9 s1 s5 s4 s5 s7 s6 s7 s8 s3 s2 s3 s4 s5 s9 s6 s7 s8 Upper endpoint: search and insert FU Berlin : SS 2013 21

Status Statusstructure structure Sweep line reaches lower endpoint of a line segment: delete from the status structure Sweep line reaches intersection point: swap two leaves in the status structure (and update information on the search paths) FU Berlin : SS 2013 21

Finding events Finding events Before the sweep algorithm starts we know all upper endpoint events and all lower endpoint events But: How do we know intersection point events??? (those we were trying to find...) Recall: Two line segments can only intersect if they are horizontal neighbors FU Berlin : SS 2013 22

Finding events Finding events si sj Lemma: Two line segments si and sj can only intersect after (= below) they have become horizontal neighbors Proof: Just imagine that the sweep line is ever so slightly above the intersection point of si and sj but below any other event Also: some earlier (= higher) event made si and sj horizontally adjacent!!! si sj FU Berlin : SS 2013 22

Subdivisions Event Eventlist list The event list must be a balanced binary search tree because during the sweep we discover new events that will happen later and we want to be able to test whether an event is already in the list We know upper endpoint events and lower endpoint events beforehand; we find intersection point events when the involved line segments become horizontal neighbors Geometric Algorithms Lecture 2: Line segment intersection and subdivisions FU Berlin : SS 2013 23

Structure of the sweep algorithm Structure of sweep algorithm Algorithm FindIntersections(S) Input. A set S of line segments in the plane. Output. The intersection points of the segments in S with for each intersection point the segments that contain it. 1. Initialize an empty event queue Q. Insert the segment endpoints into Q; when an upper endpoint is inserted the corresponding segment should be stored with it 2. Initialize an empty status structure T 3. while Q is not empty 4. do Determine next event point p in Q and delete it 5. HandleEventPoint(p) FU Berlin : SS 2013 24

If the event is an upper endpoint event and s is the line segment that starts at p: 1 2 3 Search with p in T and insert s p If s intersects its left neighbor in T then determine the intersection point and insert in Q s If s intersects its right neighbor in T then determine the intersection point and insert in Q FU Berlin : SS 2013 25

If the event is a lower endpoint event and s is the line segment that ends at p: 1 2 Search with p in T and delete s Let sl and sr be the left and right neighbors of s in T (before deletion). If they intersect below the sweep line then insert their intersection point as an event in Q s p FU Berlin : SS 2013 25

If the event is an intersection point event where s and s0 intersect at p: 1... 2... 3... 4... s s0 p FU Berlin : SS 2013 25

If the event is an intersection point event where s and s0 intersect at p: 1 Exchange s and s0 in T 2... 3... 4... s s0 p FU Berlin : SS 2013 25

If the event is an intersection point event where s and s0 intersect at p: 1 2 s Exchange s and s0 in T If s0 and its new left neighbor in T intersect below the sweep line then insert this intersection point in Q 3... 4... s0 p FU Berlin : SS 2013 25

If the event is an intersection point event where s and s0 intersect at p: 1 2 3 4 Exchange s and s0 in T If s0 and its new left neighbor in T intersect below the sweep line then insert this intersection point in Q s s0 p If s and its new right neighbor in T intersect below the sweep line then insert this intersection point in Q... FU Berlin : SS 2013 25

If the event is an intersection point event where s and s0 intersect at p: 1 2 3 4 Exchange s and s0 in T If s0 and its new left neighbor in T intersect below the sweep line then insert this intersection point in Q s s0 p If s and its new right neighbor in T intersect below the sweep line then insert this intersection point in Q Report the intersection point FU Berlin : SS 2013 25

Subdivisions s0 s Can it be that new horizontal neighbors already intersected above the sweep line? Can it be that we insert a newly detected intersection point event but it already occurs in Q? p Geometric Algorithms Lecture 2: Line segment intersection and subdivisions FU Berlin : SS 2013 25

Subdivisions s0 s Can it be that new horizontal neighbors already intersected above the sweep line? Can it be that we insert a newly detected intersection point event but it already occurs in Q? p Insert events only once! Geometric Algorithms Lecture 2: Line segment intersection and subdivisions FU Berlin : SS 2013 25

How much time to handle an event? At most one search in T and/or one insertion deletion or swap At most twice finding a neighbor in T At most one deletion from and two insertions in Q Since T and Q are balanced binary search trees handling an event takes only O(log n) time FU Berlin : SS 2013 26

How many events? 2n for the upper and lower endpoints k for the intersection points if there are k of them In total: O(n + k) events FU Berlin : SS 2013 26

Initialization takes O(n log n) time (to put all upper and lower endpoint events in Q) Each of the O(n + k) events takes O(log n) time The algorithm takes O(n log n + k log n) time If k = O(n) then this is O(n log n) Note that if k is really large the brute force O(n2 ) time algorithm is more efficient FU Berlin : SS 2013 26

Question: How much storage does the algorithm take? FU Berlin : SS 2013 26

Question: Given that the event list is a binary tree that may store O(k) = O(n2 ) events is the efficiency in jeopardy? FU Berlin : SS 2013 26

Subdivisions Solution: Only store intersection points of currently adjacent segments. Geometric Algorithms Lecture 2: Line segment intersection and subdivisions FU Berlin : SS 2013 26

Assignment: degenerate cases Degenerate cases How do we deal with degenerate cases? For two different events with the same y-coordinate we treat them from left to right the upper endpoint of a horizontal line segment is its left endpoint FU Berlin : SS 2013 27

Assignment: degenerate cases Degenerate cases How about multiply coinciding event points? p Let U(p) and L(p) be the line segments that have p as upper and lower endpoint and C(p) the ones that contain p Question: How do we handle this multi-event? FU Berlin : SS 2013 27

- conclusion Conclusion For every sweep algorithm: Define the status Choose the status structure and the event list Figure out how events must be handled (with sketches!) To analyze determine the number of events and how much time they take Then deal with degeneracies FU Berlin : SS 2013 28

Alternative assignment Program the plane sweep algorithm for finding line segment intersections! FU Berlin : SS 2013 29

Assignment 3 http: //page.mi.fu-berlin.de/panos/cg13/exercises/u03.pdf Due: 29/04! FU Berlin : SS 2013 30

CGAL and Google Summer of Code Program some geometric algorithm in CGAL for 3 months in the summer and get paid for it (5000 Euros..) FU Berlin : SS 2013 31