Computational Geometry

Similar documents
CS 532: 3D Computer Vision 11 th Set of Notes

Line segment intersection. Family of intersection problems

CS 372: Computational Geometry Lecture 3 Line Segment Intersection

2 A Plane Sweep Algorithm for Line Segment Intersection

2 Line Segment Intersection

Computational Geometry

CMSC 754 Computational Geometry 1

Computational Geometry

CS 532: 3D Computer Vision 14 th Set of Notes

Computational Geometry

Introduction to Algorithms

Polygon Partitioning. Lecture03

Trapezoidal Maps. Notes taken from CG lecture notes of Mount (pages 60 69) Course page has a copy

Notes and Answers to Homework Exam 1, Geometric Algorithms, 2017

Computing intersections in a set of line segments: the Bentley-Ottmann algorithm

Simple Graph. General Graph

Multidimensional Divide and Conquer 2 Spatial Joins

Computational Geometry

Flavor of Computational Geometry. Voronoi Diagrams. Shireen Y. Elhabian Aly A. Farag University of Louisville

CS S Lecture February 13, 2017

External-Memory Algorithms with Applications in GIS - (L. Arge) Enylton Machado Roberto Beauclair

Computational Geometry

6.854J / J Advanced Algorithms Fall 2008

Lecture 25 Spanning Trees

HW Graph Theory Name (andrewid) - X. 1: Draw K 7 on a torus with no edge crossings.

GIS Data Models. 4/9/ GIS Data Models

Balanced Binary Search Trees. Victor Gao

Intersection. Segment-Segment Intersection

Graphs and Discrete Structures

Geometric and Thematic Integration of Spatial Data into Maps

Planar Point Location

Computational Geometry

CMPS 3130/6130 Computational Geometry Spring Voronoi Diagrams. Carola Wenk. Based on: Computational Geometry: Algorithms and Applications

1/60. Geometric Algorithms. Lecture 1: Introduction. Convex Hulls

Line Arrangement. Chapter 6

Plane Sweep Algorithms

Advanced Algorithms Computational Geometry Prof. Karen Daniels. Fall, 2012

More about The Competition

Geometric Algorithms. Geometric search: overview. 1D Range Search. 1D Range Search Implementations

Today. Types of graphs. Complete Graphs. Trees. Hypercubes.

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 24 Solid Modelling

arxiv: v1 [cs.cg] 8 Jan 2018

Line Arrangements. Applications

Tutte s Theorem: How to draw a graph

Elementary maths for GMT. Algorithm analysis Part II

7 Voronoi Diagrams. The Post Office Problem

Tangencies between disjoint regions in the plane

The Simplex Algorithm

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

27 Geometric Intersection

GEOMETRIC SEARCHING PART 1: POINT LOCATION

Smallest Intersecting Circle for a Set of Polygons

Spatially-Aware Information Retrieval on the Internet

Lecture 3: Art Gallery Problems and Polygon Triangulation

Strongly connected: A directed graph is strongly connected if every pair of vertices are reachable from each other.

Brief History. Graph Theory. What is a graph? Types of graphs Directed graph: a graph that has edges with specific directions

Lecture 16: Voronoi Diagrams and Fortune s Algorithm

Algorithms and Data Structures

Planar graphs. Chapter 8

A Distributed Approach to Fast Map Overlay

Computational Geometry

Multidimensional Data and Modelling - DBMS

Lecture 2 - Graph Theory Fundamentals - Reachability and Exploration 1

CS6100: Topics in Design and Analysis of Algorithms

Polygon decomposition. Motivation: Art gallery problem

Algorithms for Euclidean TSP

CS70 - Lecture 6. Graphs: Coloring; Special Graphs. 1. Review of L5 2. Planar Five Color Theorem 3. Special Graphs:

Efficient Algorithmic Techniques for Several Multidimensional Geometric Data Management and Analysis Problems

1 Appendix to notes 2, on Hyperbolic geometry:

Computational Geometry

Minimum Spanning Trees

Solutions to Problem Set 1

Lecture Notes on Tries

Implementing Geometric Algorithms. Wouter van Toll June 20, 2017

CS 270 Algorithms. Oliver Kullmann. Analysing BFS. Depth-first search. Analysing DFS. Dags and topological sorting.

Solutions to problem set 1

Key Graph Theory Theorems

Voronoi Diagrams. A Voronoi diagram records everything one would ever want to know about proximity to a set of points

Algorithms and Data Structures

layers in a raster model

Testing Bipartiteness of Geometric Intersection Graphs David Eppstein

Divided-and-Conquer for Voronoi Diagrams Revisited. Supervisor: Ben Galehouse Presenter: Xiaoqi Cao

Lecture 3 February 23, 2012

Overview.! Manual Digitizing! Heads-up Digitizing! Common Errors! Summary! Heads-up Digitizing Tutorial

3. Voronoi Diagrams. 3.1 Definitions & Basic Properties. Examples :

Lecture 20 : Trees DRAFT

Notes on Minimum Spanning Trees. Red Rule: Given a cycle containing no red edges, select a maximum uncolored edge on the cycle, and color it red.

16.410/413 Principles of Autonomy and Decision Making

Applied Algorithm Design Lecture 3

CS60003 Algorithm Design and Analysis, Autumn

Bichromatic Line Segment Intersection Counting in O(n log n) Time

Lecture outline. Graph coloring Examples Applications Algorithms

Fortune s Algorithm. Notes from the book by de Berg, Van Krevald, Overmars, and Schwarzkpf

Orthogonal line segment intersection. Computational Geometry [csci 3250] Laura Toma Bowdoin College

Computer Science 210 Data Structures Siena College Fall Topic Notes: Priority Queues and Heaps

managing an evolving set of connected components implementing a Union-Find data structure implementing Kruskal s algorithm

Computational Geometry: Lecture 5

Computational Geometry

CSE331 Introduction to Algorithms Lecture 15 Minimum Spanning Trees

Problem Set 6 Solutions

Transcription:

for map overlay Lecture 2: for map overlay 1

Map layers Map overlay 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,... 2

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 1km from a river? What area of all lakes occurs at the geological soil type rock? 3

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) 4

The (easy) problem Problem Output-sensitive algorithms Some attempts 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 5

An easy, optimal algorithm? Problem Output-sensitive algorithms Some attempts 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 e i,e j S 2. do if e i and e j intersect 3. then report their intersection point Question: Why can we say that this algorithm is optimal? 6

Problem Output-sensitive algorithms Some attempts 7

Output-sensitive algorithm Problem Output-sensitive algorithms Some attempts 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 8

Intersection points in practice Problem Output-sensitive algorithms Some attempts 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(nlogn) time 9

First attempt Problem Output-sensitive algorithms Some attempts 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? 1D problem: Given a set of intervals on the real line, find all partly overlapping pairs x s 1 s 2 s 3 s 4 s 5 s 6 (s 1, s 2 ), (s 4, s 6 ), (s 5, s 6 ) 10

First attempt Problem Output-sensitive algorithms Some attempts 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 s i : for each s j in T, report the pair s i,s j. Then insert s i in T Right endpoint of s i : delete s i from T Question: Is this algorithm output-sensitive for 1D interval intersection? 11

First attempt Problem Output-sensitive algorithms Some attempts 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? 12

Second attempt Problem Output-sensitive algorithms Some attempts 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) 13

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 14

Sweep computed 15 unexplored

Sweep and status computed status 16 unexplored

Status and 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 17

s 1 s 3 s 2 s 4 s 5 add s 1 s 6 s 7 s 8 18

s 1 s 3 s 2 s 4 s 5 add s 2 after s 1 s 6 s 7 s 8 19

s 1 s 3 s 2 s 4 s 5 add s 3 between s 1 and s 2 s 6 s 7 s 8 20

s 1 s 3 s 2 s 4 s 5 add s 4 before s 1 s 6 s 7 s 8 21

s 1 s 3 s 2 s 4 s 5 s 6 s 7 report intersection (s 1,s 2 ); swap s 1 and s 3 s 8 22

s 1 s 3 s 2 s 4 s 5 remove s 2 s 6 s 7 s 8 23

s 1 s 3 s 2 s 4 s 5 remove s 1 s 6 s 7 s 8 24

s 1 s 3 s 2 s 4 s 5 add s 5 after s 3 s 6 s 7 s 8 25

s 1 s 3 s 2 s 4 s 5 s 6 s 7 report intersection (s 3,s 4 ); swap s 3 and s 4 s 8 26

... and so on... 27

The 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 28

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? 29

Event list and status 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 30

Status structure We use a balanced binary search tree with the line segments in the leaves as the status structure s 4 s 2 s 6 s 1 s 3 s 5 s 7 s 1 s 2 s 3 s 4 s 5 s 6 s 7 s 8 s 1 s 2 s 3 s 4 s 5 s 6 s 7 s 8 31

Status structure s 4 s 2 s 6 s 1 s 3 s 5 s 7 s 1 s 2 s 3 s 4 s 5 s 6 s 7 s 8 s 1 s 2 s 3 s 4 s 5 s 6 s 7 s 8 s 9 32 Upper endpoint: search, and insert

Status structure s 4 s 2 s 6 s 1 s 3 s 5 s 7 s 1 s 2 s 3 s 4 s 5 s 6 s 7 s 8 s 1 s 2 s 3 s 4 s 5 s 6 s 7 s 8 s 9 33 Upper endpoint: search, and insert

Status structure s 4 s 2 s 6 s 1 s 3 s 5 s 7 s 1 s 2 s 9 s 4 s 5 s 6 s 7 s 8 s 9 s 3 s 1 s 2 s 3 s 4 s 5 s 6 s 7 s 8 s 9 34 Upper endpoint: search, and insert

Status 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) 35

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 36

Finding events Lemma: Two line segments s i and s j 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 s i and s j, but below any other event Also: some earlier (= higher) event made s i and s j horizontally adjacent!!! s i s i s j s j 37

Event list The event list must be a balanced binary search tree, because during the sweep, we discover new events that will happen later We know upper endpoint events and lower endpoint events beforehand; we find intersection point events when the involved line segments become horizontal neighbors 38

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) 39

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

If the event is a lower endpoint event, and s is the line segment that ends at p: 1 Search with p in T, and delete s 2 Let s l and s r 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 p s 41

If the event is an intersection point event where s and s intersect at p: 1... 2... 3... 4... p s s 42

If the event is an intersection point event where s and s intersect at p: 1 Exchange s and s in T 2... 3... 4... p s s 43

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

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

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

s s Can it be that new horizontal neighbors already intersected above the sweep line? p Can it be that we insert a newly detected intersection point event, but it already occurs in Q? 47

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(logn) time 48

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 49

Initialization takes O(nlogn) time (to put all upper and lower endpoint events in Q) Each of the O(n + k) events takes O(logn) time The algorithm takes O(nlogn + k logn) time If k = O(n), then this is O(nlogn) Note that if k is really large, the brute force O(n 2 ) time algorithm is more efficient 50

Question: How much storage does the algorithm take? 51

Question: Given that the event list is a binary tree that may store O(k) = O(n 2 ) events, is the efficiency in jeopardy? 52

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 53

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? 54

Degenerate cases How efficiently is such a multi-event point handled? If U(p) + L(p) + C(p) = m, then the event takes O(mlogn) time What do we report? The intersection point itself Every pair of intersecting line segments The intersection point and every line segment involved Question: What is the output size in each of these three cases? 55

Degenerate cases Output size in case we report the intersection point itself: O(1) every pair of intersecting line segments: O(m 2 ) the intersection point and every line segment involved: O(m) 56

Degenerate cases Since m = O(n), does this imply that the whole algorithm takes O(k) O(mlogn) = O(k) O(nlogn) = O(nk logn) time? No, we can bound m over all intersections by the number of edges that arise in the subdivision: Note m 2E Euler s formula gives V E + F 2 for the subdivision induced by the line segments 57

Degenerate cases Every face has at least 3 edges and every edge contributes to exactly 2 faces, so 2E 3F Combine with Euler s formula V E + F 2, and we get: E 3V 6 Note V 2n + I with I intersections, so E 6n + 3I 6 We get m 2E 12n + 6I 12 58

Result For any set of n line segments in the plane, all I intersections can be computed in O(nlogn + I logn) time, and within this time bound, we can report for every intersection which line segments are involved 59

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 and incorporate them carefully 60