INTERSECTION OF LINE-SEGMENTS



Similar documents
Computational Geometry: Line segment intersection

A Note on Maximum Independent Sets in Rectangle Intersection Graphs

Line Segment Intersection

Computational Geometry. Lecture 1: Introduction and Convex Hulls

EE602 Algorithms GEOMETRIC INTERSECTION CHAPTER 27

Persistent Data Structures and Planar Point Location

Finding and counting given length cycles

Graphs without proper subgraphs of minimum degree 3 and short cycles

Shortest Path Algorithms

5.4 Closest Pair of Points

TOWARDS AN AUTOMATED HEALING OF 3D URBAN MODELS

Offline sorting buffers on Line

- 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

Solving Geometric Problems with the Rotating Calipers *

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)

Binary Space Partitions

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

1 Computational Geometry

Closest Pair Problem

Connectivity and cuts

Triangulation by Ear Clipping

Fast approximation of the maximum area convex. subset for star-shaped polygons

A fast and robust algorithm to count topologically persistent holes in noisy clouds

Shortcut sets for plane Euclidean networks (Extended abstract) 1

1. A student followed the given steps below to complete a construction. Which type of construction is best represented by the steps given above?

Closest Pair of Points. Kleinberg and Tardos Section 5.4

Geometry: Unit 1 Vocabulary TERM DEFINITION GEOMETRIC FIGURE. Cannot be defined by using other figures.

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

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

root node level: internal node edge leaf node Data Structures & Algorithms McQuain

8.1 Min Degree Spanning Tree

Final Review Geometry A Fall Semester

Binary Heaps. CSE 373 Data Structures

Chapter 13: Query Processing. Basic Steps in Query Processing

Chapter 3.1 Angles. Geometry. Objectives: Define what an angle is. Define the parts of an angle.

Vector storage and access; algorithms in GIS. This is lecture 6

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

Catalan Numbers. Thomas A. Dowling, Department of Mathematics, Ohio State Uni- versity.

Analysis of a Search Algorithm

Persistent Data Structures

Analysis of Algorithms I: Optimal Binary Search Trees

Intersection of a Line and a Convex. Hull of Points Cloud

Full and Complete Binary Trees

1/1 7/4 2/2 12/7 10/30 12/25

On the effect of forwarding table size on SDN network utilization

Arrangements And Duality

6.852: Distributed Algorithms Fall, Class 2

Lecture 1: Course overview, circuits, and formulas

THE PROBLEM WORMS (1) WORMS (2) THE PROBLEM OF WORM PROPAGATION/PREVENTION THE MINIMUM VERTEX COVER PROBLEM

Removing Local Extrema from Imprecise Terrains

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

Analysis of Algorithms, I

Efficient Recovery of Secrets

each college c i C has a capacity q i - the maximum number of students it will admit

MATHEMATICAL INDUCTION. Mathematical Induction. This is a powerful method to prove properties of positive integers.

External Memory Geometric Data Structures

Binary Image Scanning Algorithm for Cane Segmentation

Cpt S 223. School of EECS, WSU

Line and Polygon Clipping. Foley & Van Dam, Chapter 3

Shortest Inspection-Path. Queries in Simple Polygons

1 if 1 x 0 1 if 0 x 1

CSC2420 Spring 2015: Lecture 3

Factoring Patterns in the Gaussian Plane

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

136 CHAPTER 4. INDUCTION, GRAPHS AND TREES

Disjoint Compatible Geometric Matchings

Lecture 17 : Equivalence and Order Relations DRAFT

Analysis of Algorithms I: Binary Search Trees

Binary Heap Algorithms

Geometry Chapter Point (pt) 1.1 Coplanar (1.1) 1.1 Space (1.1) 1.2 Line Segment (seg) 1.2 Measure of a Segment

5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

Lecture 6: Binary Search Trees CSCI Algorithms I. Andrew Rosenberg

Didacticiel Études de cas. Association Rules mining with Tanagra, R (arules package), Orange, RapidMiner, Knime and Weka.

2) What is the structure of an organization? Explain how IT support at different organizational levels.

Sample Questions Csci 1112 A. Bellaachia

5. Binary objects labeling

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

Data Structure [Question Bank]

Data Structures and Algorithm Analysis (CSC317) Intro/Review of Data Structures Focus on dynamic sets

Fast Sequential Summation Algorithms Using Augmented Data Structures

INDISTINGUISHABILITY OF ABSOLUTELY CONTINUOUS AND SINGULAR DISTRIBUTIONS

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

Collinear Points in Permutations

Home Page. Data Structures. Title Page. Page 1 of 24. Go Back. Full Screen. Close. Quit

Solutions to Homework 6

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.

WOLLONGONG COLLEGE AUSTRALIA. Diploma in Information Technology

arxiv: v1 [cs.dc] 7 Dec 2014

INCIDENCE-BETWEENNESS GEOMETRY

Approximation Algorithms

The Butterfly, Cube-Connected-Cycles and Benes Networks

An approach to data enrichment of building features using Delaunay triangulation for automatic map generalization

Transcription:

INTERSECTION OF LINE-SEGMENTS Vera Sacristán Discrete and Algorithmic Geometry Facultat de Matemàtiques i Estadística Universitat Politècnica de Catalunya

Problem Input: n line-segments in the plane, s i = (p i, q i ), i =... n. Output: the k = O(n ) intersections of line-segment pairs, (x, y, i, j).

Problem Input: n line-segments in the plane, s i = (p i, q i ), i =... n. Output: the k = O(n ) intersections of line-segment pairs, (x, y, i, j). Some applications (in addition to those that you already know) Geographic information systems Detecting the intersections among the elements of the different layers of information (cities, roads, services,...) Realistic visualization Eliminating the hidden portions of a scene

Problem Input: n line-segments in the plane, s i = (p i, q i ), i =... n. Output: the k = O(n ) intersections of line-segment pairs, (x, y, i, j). Brute force solution Check the intersection of the ( n ) pairs of line-segments. This algorithm runs in Θ(n ) time.

Problem Input: n line-segments in the plane, s i = (p i, q i ), i =... n. Output: the k = O(n ) intersections of line-segment pairs, (x, y, i, j). Brute force solution Check the intersection of the ( n ) pairs of line-segments. This algorithm runs in Θ(n ) time. Problem complexity The problem has complexity Ω(n ), because there exist line-segment configurations with ( n ) intersections.

Problem Input: n line-segments in the plane, s i = (p i, q i ), i =... n. Output: the k = O(n ) intersections of line-segment pairs, (x, y, i, j). Brute force solution Check the intersection of the ( n ) pairs of line-segments. This algorithm runs in Θ(n ) time. Problem complexity The problem has complexity Ω(n ), because there exist line-segment configurations with ( n ) intersections.

Problem Input: n line-segments in the plane, s i = (p i, q i ), i =... n. Output: the k = O(n ) intersections of line-segment pairs, (x, y, i, j). Brute force solution Check the intersection of the ( n ) pairs of line-segments. This algorithm runs in Θ(n ) time. Problem complexity The problem has complexity Ω(n ), because there exist line-segment configurations with ( n ) intersections. Nevertheless, there exist sets of n line-segments with a number of intersections substantially smaller than ( n ).

Problem Input: n line-segments in the plane, s i = (p i, q i ), i =... n. Output: the k = O(n ) intersections of line-segment pairs, (x, y, i, j). Brute force solution Check the intersection of the ( n ) pairs of line-segments. This algorithm runs in Θ(n ) time. Problem complexity The problem has complexity Ω(n ), because there exist line-segment configurations with ( n ) intersections. Nevertheless, there exist sets of n line-segments with a number of intersections substantially smaller than ( n ). Output-sensitive solution Algorithm whose running time depends on the number of intersections to be reported.

Problem Input: n line-segments in the plane, s i = (p i, q i ), i =... n. Output: the k = O(n ) intersections of line-segment pairs, (x, y, i, j).

Problem Input: n line-segments in the plane, s i = (p i, q i ), i =... n. Output: the k = O(n ) intersections of line-segment pairs, (x, y, i, j). Solution Sweep line algorithm

Problem Input: n line-segments in the plane, s i = (p i, q i ), i =... n. Output: the k = O(n ) intersections of line-segment pairs, (x, y, i, j). Solution Sweep line algorithm A straight line (vertical, in this case) scans the object (the line segments) and allows detecting and computing the desired elements (intersection points), leaving the problem solved behind it. The sweeping process is discretized.

Problem Input: n line-segments in the plane, s i = (p i, q i ), i =... n. Output: the k = O(n ) intersections of line-segment pairs, (x, y, i, j). Solution Sweep line algorithm A straight line (vertical, in this case) scans the object (the line segments) and allows detecting and computing the desired elements (intersection points), leaving the problem solved behind it. The sweeping process is discretized. Essential elements of a sweep line algorithm: Sweep line Data structure storing the information of the objects intersected by the sweeping line, sorted along the line. Events queue Priority queue keeping the information of the algorithm stops, i.e., all the positions where the sweep line stracture changes.

Problem Input: n line-segments in the plane, s i = (p i, q i ), i =... n. Output: the k = O(n ) intersections of line-segment pairs, (x, y, i, j). Observation If two line-segments have disjoint projections onto a given line, then they are disjoint.

Problem Input: n line-segments in the plane, s i = (p i, q i ), i =... n. Output: the k = O(n ) intersections of line-segment pairs, (x, y, i, j). Observation If two line-segments have disjoint projections onto a given line, then they are disjoint.

Problem Input: n line-segments in the plane, s i = (p i, q i ), i =... n. Output: the k = O(n ) intersections of line-segment pairs, (x, y, i, j). Observation If two line-segments have disjoint projections onto a given line, then they are disjoint. Observation When sweeping a set of line-segments with a line, two intersecting line-segments need to be consecutive in the sweeping line right before their intersection point.

Problem Input: n line-segments in the plane, s i = (p i, q i ), i =... n. Output: the k = O(n ) intersections of line-segment pairs, (x, y, i, j). Observation If two line-segments have disjoint projections onto a given line, then they are disjoint. Observation When sweeping a set of line-segments with a line, two intersecting line-segments need to be consecutive in the sweeping line right before their intersection point.

Problem Input: n line-segments in the plane, s i = (p i, q i ), i =... n. Output: the k = O(n ) intersections of line-segment pairs, (x, y, i, j). Observation If two line-segments have disjoint projections onto a given line, then they are disjoint. Observation When sweeping a set of line-segments with a line, two intersecting line-segments need to be consecutive in the sweeping line right before their intersection point.

Problem Input: n line-segments in the plane, s i = (p i, q i ), i =... n. Output: the k = O(n ) intersections of line-segment pairs, (x, y, i, j). Observation If two line-segments have disjoint projections onto a given line, then they are disjoint. Observation When sweeping a set of line-segments with a line, two intersecting line-segments need to be consecutive in the sweeping line right before their intersection point.

Problem Input: n line-segments in the plane, s i = (p i, q i ), i =... n. Output: the k = O(n ) intersections of line-segment pairs, (x, y, i, j). Observation If two line-segments have disjoint projections onto a given line, then they are disjoint. Observation When sweeping a set of line-segments with a line, two intersecting line-segments need to be consecutive in the sweeping line right before their intersection point.

Bentley-Ottman s algorithm This is a sweep-line algorithm.

Bentley-Ottman s algorithm This is a sweep-line algorithm. Hypothesis (to be eliminated later on). There are no repeated abscissae, i.e.: there are no vertical line-segments, and no two endpoints of two line-segments, no two intersection points of line-segments, no endpoint and intersection point, lie in the same vertical line.. At each intersection point, only two line-segments intersect.

Bentley-Ottman s algorithm This is a sweep-line algorithm. Hypothesis (to be eliminated later on). There are no repeated abscissae, i.e.: there are no vertical line-segments, and no two endpoints of two line-segments, no two intersection points of line-segments, no endpoint and intersection point, lie in the same vertical line.. At each intersection point, only two line-segments intersect. Sweep line Stabbed line-segments, in vertical order.

Bentley-Ottman s algorithm This is a sweep-line algorithm. Hypothesis (to be eliminated later on). There are no repeated abscissae, i.e.: there are no vertical line-segments, and no two endpoints of two line-segments, no two intersection points of line-segments, no endpoint and intersection point, lie in the same vertical line.. At each intersection point, only two line-segments intersect. Sweep line Stabbed line-segments, in vertical order. Events All endpoints of the line-segments (known a priori). All intersection points of line-segments (found on the fly).

Bentley-Ottman s algorithm

Bentley-Ottman s algorithm Input: n line-segments in the plane, s i = (p i, q i ), i =... n. Output: the k = O(n ) intersections of line-segment pairs, (x, y, i, j).

Bentley-Ottman s algorithm Input: n line-segments in the plane, s i = (p i, q i ), i =... n. Output: the k = O(n ) intersections of line-segment pairs, (x, y, i, j). Initialization: - Sort the n endpoints by abscissa and store the information in E. - Line L starts empty.

Advance While E do:. p = min E. If p = start(s), then: Insert s in L If s and s intersect to the right of p, insert their intersection point in E and report it (if needed). Do the same for s +.. If p = end(s), then: If s and s + intersect to the right of p, insert their intersection point in E and report it (if needed). Delete s from L. If p = s s with s < L s, then: If s and s intersect to the right of p, insert their intersection point in E and report it (if needed). Do the same for s + and s. Transpose s and s in L. Delete p from E

p p p p p q q q p q q q

p p p p p q q q p q q q

p p p p p q q q p q q q

s p p p p p q q q p q q q

s p p p p q q q p q q q

s s p p p p q q q p q q q

s s p p p p q q q p q q q

s s p p p p q q q p q q q

s s p p p q q q p q q q

s s s p p p q q q p q q q

s s s p p p q q q p q q q

s s s p p p q q q p q q q r r

s s s p p p q q q p q q q r r

s s s p p p q q q p q q q r r

s s s p p q q q p q q q r r

s s s s p p q q q p q q q r r

s s s s p p q q q p q q q r r

s s s s p p q q q p q q q r r r r

s s s s p p q q q p q q q r r r r

s s s s p p q q q p q q q r r r r r r

s s s s p p q q q p q q q r r r r r r

s s s s p q q q p q q q r r r r r r

s s s s s p q q q p q q q r r r r r r

s s s s s p q q q p q q q r r r r r r

s s s s s p q q q p q q q r r r r r r

s s s s s q q q p q q q r r r r r r

s s s s s q q q p q q q r r r r r r

s s s s q q q p q q q r r r r r r

s s s s q q q p q q q r r r r r r

s s s s r r r q q p q q q r r r

s s s s r r r q q p q q q r r r

s s s s r r r q q p q q q r r r

s s s s r r r q q p q q q r r r

s s s s r r r q q p q q q r r r

s s s s r r r q q p q q q r r r

s s s s r r q q p q q q r r r

s s s s r r q q p q q q r r r

s s s s r r q q p q q q r r r

s s s s r r q q p q q q r r r

s s s s r r q q p q q q r r r

s s s s r q q p q q q r r r

s s s s r q q p q q q r r r

s s s s r q q p q q q r r r

s s s s r q q p q q q r r r

s s s s r q q p q q q r r r r r

s s s s r q q p q q q r r r r r

s s s s q q p q q q r r r r r

s s s s q q p q q q r r r r r

s s s q q p q q q r r r r r

s s s q q p q q q r r r r r

s s s q q p q q q r r r r r

s s s q p q q q r r r r r

s s s q p q q q r r r r r

s s q p q q q r r r r r

s s p q q q r r r r r

s s s p q q q r r r r r

s s s p q q q r r r r r

s s s p q q q r r r r r

s s s p q q q r r r r r r r

s s s p q q q r r r r r r r

s s s r q q q r r r r r r

s s s r q q q r r r r r r

s s s r q q q r r r r r r

s s s r q q q r r r r r r

s s s r q q q r r r r r r

s s s q q q r r r r r r

s s s q q q r r r r r r

s s q q q r r r r r r

s s r q q r r r r r

s s r q q r r r r r

s s r q q r r r r r

s s q q r r r r r

s s q q r r r r r

s q q r r r r r

s q r r r r r

s q r r r r r

r r r r r

Bentley-Ottman s Algorithm

Bentley-Ottman s Algorithm Correctness The algorithm finds all intersections (due to Observation ). The algorithm does not find any faked intersection (all intersections are checked).

Bentley-Ottman s Algorithm Correctness The algorithm finds all intersections (due to Observation ). The algorithm does not find any faked intersection (all intersections are checked). Dealing with degenerate cases In order to deal with input data containing more than one point sharing the same abscissa, the event queue E must store the points in lexicographical order (and not only by abscissae). The algorithm can trivially detect whether two or more line-segments intersect in more than one point (i.e., intersect in a line-segment), since it stops at their endpoints. A slight modification also allows to deal with input data in which three or more line-segments intersect at the same point: in this case, the algorithm inverts their order in the sweep line at the intersection point event.

Bentley-Ottman s Algorithm Data structures

Bentley-Ottman s Algorithm Data structures Sweep line, L: Keeps the total order of the stabbed line-segments and supports: insert(s) delete(s) transpose(s, s ) previous(s) next(s) A dictionary (balanced binary tree) allows to perform each of these operations in O(log n) time.

Bentley-Ottman s Algorithm Data structures Events queue, E: Keeps the total order of the events and supports: minimum (report and extract) insert(p) memberq(p) A priority queue (balanced binary tree) allows to perform each of these operations in O(log n) time.

Bentley-Ottman s Algorithm Complexity (time)

Bentley-Ottman s Algorithm Complexity (time) Initialization: O(n log n) Advance (performed n + k times):. O(log n)... O(log n). O(log n) Total: O((n + k) log n) Initialization: - Sort the n endpoints by abscissa and store the information in E. - Line L starts empty. Advance While E do:. p = min E. If p = start(s), then.... If p = end(s), then.... If p = s s with s < L s, then.... Delete p from E

Bentley-Ottman s Algorithm Complexity (time) Initialization: O(n log n) Advance (performed n + k times):. O(log n)... O(log n). O(log n) Total: O((n + k) log n) The previous counting corresponds to the non degenerated case. When each intersection point, v i, may correspond to more than two intersecting line-segments, the total running time of the advance step of the algorithm is O(( k i= degree(v i)) log n). However, considering the points v i as vertices of the graph: k degree(v i ) e = O(e) = O(v) = O(n + k) = O(n + k). i=

Bentley-Ottman s Algorithm Complexity (space)

Bentley-Ottman s Algorithm Complexity (space) At each step of the algorithm, the sweep line stores at most n line-segments.

Bentley-Ottman s Algorithm Complexity (space) At each step of the algorithm, the sweep line stores at most n line-segments. In the formulation exposed so far, the event queue may at some point store all intersection points, which are k = O(n ).

Bentley-Ottman s Algorithm Complexity (space) At each step of the algorithm, the sweep line stores at most n line-segments. In the formulation exposed so far, the event queue may at some point store all intersection points, which are k = O(n ). However, a slight modification allows the event queue to store, at each step of the algorithm, at most n intersection events. This can be achieved if, at each step, E only stores intersection points of line-segments adjacent in L, and the intersection points are deleted from E whenever the intersecting segments become non adjacent.

The decision problem

The decision problem Input: n line-segments in the plane, s i = (p i, q i ), i =... n. Output: there is / there is not a pair of intersecting line-segments, and report a witness.

The decision problem Input: n line-segments in the plane, s i = (p i, q i ), i =... n. Output: there is / there is not a pair of intersecting line-segments, and report a witness. Solution Bentley-Ottman s algorithm solves this problem in O(n log n) time.

The decision problem Input: n line-segments in the plane, s i = (p i, q i ), i =... n. Output: there is / there is not a pair of intersecting line-segments, and report a witness. Solution Bentley-Ottman s algorithm solves this problem in O(n log n) time. Lower bound The decision problem has complexity Ω(n log n).

The decision problem Input: n line-segments in the plane, s i = (p i, q i ), i =... n. Output: there is / there is not a pair of intersecting line-segments, and report a witness. Solution Bentley-Ottman s algorithm solves this problem in O(n log n) time. Lower bound The decision problem has complexity Ω(n log n). Proof: by reduction from unicity of integers. Given x,..., x n N, compute p i = (x i, 0), q i = (x i, ) and s i = (p i, q i ). There exists a pair of intersecting line-segments if and only if there exist duplicate numbers in the original set. If you don t like degeneracies, consider the following points: p i = (x i i, 0) and q i = (x i + i, ).

The problem of reporting all intersections

The problem of reporting all intersections Corollary The problem of reporting all intersection has complexity Ω(k + n log n), because Reporting requires Ω(k) time Deciding requires Ω(n log n) time

The problem of reporting all intersections Corollary The problem of reporting all intersection has complexity Ω(k + n log n), because Reporting requires Ω(k) time Deciding requires Ω(n log n) time Optimal algorithm An algorithm by Chazelle and Edelsbrunner solves this problem in Θ(k + n log n) time.

The problem of reporting all intersections Corollary The problem of reporting all intersection has complexity Ω(k + n log n), because Reporting requires Ω(k) time Deciding requires Ω(n log n) time Optimal algorithm An algorithm by Chazelle and Edelsbrunner solves this problem in Θ(k + n log n) time. Consequences Deciding whether a polygon is simple can be solved in O(n log n) time. Deciding whether two simple polygons intersect can be solved in O(n log n) time.

TO LEARN MORE F. Preparata, M. Shamos, Computational Geometry: An introduction, Springer. M. de Berg, O. Cheong, M. van Kreveld, M. Overmars: Computational Geometry: Alhorithms and Applications, Springer. J-D. Boissonnat, M. Yvinec, Algorithmic Geometry, Cambridge University Press.