Computational Geometry. Lecture 17

Similar documents
Computational Geometry

Orthogonal range searching. Range Trees. Orthogonal range searching. 1D range searching. CS Spring 2009

Range Searching and Windowing

Computational Geometry

Computational Geometry

CMSC 754 Computational Geometry 1

Lecture 8: Orthogonal Range Searching

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

Computational Geometry

Lecture 7: Computational Geometry

Computational Geometry

COT5405: GEOMETRIC ALGORITHMS

Lecture 3: Art Gallery Problems and Polygon Triangulation

January 10-12, NIT Surathkal Introduction to Graph and Geometric Algorithms

CS 372: Computational Geometry Lecture 3 Line Segment Intersection

Computational Geometry [csci 3250]

Polygon Triangulation

CSE2331/5331. Topic 6: Binary Search Tree. Data structure Operations CSE 2331/5331

Computational Geometry

Hidden Surface Elimination: BSP trees

GEOMETRIC SEARCHING PART 1: POINT LOCATION

Geometric Algorithms. 1. Objects

Binary Search Trees > = 2014 Goodrich, Tamassia, Goldwasser. Binary Search Trees 1

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

1D Range Searching (cont) 5.1: 1D Range Searching. Database queries

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

CSE Data Structures and Introduction to Algorithms... In Java! Instructor: Fei Wang. Binary Search Trees. CSE2100 DS & Algorithms 1

CS6100: Topics in Design and Analysis of Algorithms

Line segment intersection (I): Orthogonal line segment intersection. Computational Geometry [csci 3250] Laura Toma Bowdoin College

Point Enclosure and the Interval Tree

Problem Set 6 Solutions

Range Searching II: Windowing Queries

Module 4: Index Structures Lecture 13: Index structure. The Lecture Contains: Index structure. Binary search tree (BST) B-tree. B+-tree.

Polygon decomposition. Motivation: Art gallery problem

Computational Geometry [csci 3250]

Lecture 3 February 9, 2010

Advanced Algorithm Design and Analysis (Lecture 12) SW5 fall 2005 Simonas Šaltenis E1-215b

Computational Geometry

Prof. Gill Barequet. Center for Graphics and Geometric Computing, Technion. Dept. of Computer Science The Technion Haifa, Israel

Geometric Data Structures

Geometry. Zachary Friggstad. Programming Club Meeting

Orthogonal range searching. Orthogonal range search

Orthogonal Range Search and its Relatives

Computational Geometry

Polygon Triangulation. (slides partially by Daniel Vlasic )

Sorted Arrays. Operation Access Search Selection Predecessor Successor Output (print) Insert Delete Extract-Min

Range searching. with Range Trees

Computation Geometry Exercise Range Searching II

Computational Geometry. Geometry Cross Product Convex Hull Problem Sweep Line Algorithm

Trapezoid and Chain Methods

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

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

Lecture 9 March 15, 2012

Average case analysis of dynamic geometric optimization

Massive Data Algorithmics

CS 410/584, Algorithm Design & Analysis, Lecture Notes 8!

CSE 5311 Notes 13: Computational Geometry

CMSC 754 Computational Geometry 1

Multidimensional Indexing The R Tree

AN OUTPUT-SENSITIVE ALGORITHM FOR COMPUTING VISIBILITY GRAPHS*

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

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

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

I/O-Algorithms Lars Arge Aarhus University

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

Planar Point Location

Projects & Polygon Triangulation

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

CS 410/584, Algorithm Design & Analysis, Lecture Notes 8

Field: We have been doing geometry eg linear programming. But in computational geometry, key difference in focus: low dimension d

Polygon Partitioning. Lecture03

1 The range query problem

Geometric Data Structures

I/O-Algorithms Lars Arge

External Memory Algorithms for Geometric Problems. Piotr Indyk (slides partially by Lars Arge and Jeff Vitter)

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

Trees. Reading: Weiss, Chapter 4. Cpt S 223, Fall 2007 Copyright: Washington State University

Chapter 3. Sukhwinder Singh

Generalized kernels of polygons under rotation

Polygon Triangulation. (slides partially by Daniel Vlasic )

VORONOI DIAGRAM PETR FELKEL. FEL CTU PRAGUE Based on [Berg] and [Mount]

Line segment intersection. Family of intersection problems

Range Reporting. Range Reporting. Range Reporting Problem. Applications

Range-Aggregate Queries Involving Geometric Aggregation Operations

DDS Dynamic Search Trees

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

1/25 Warm Up Find the value of the indicated measure

Geometric Streaming Algorithms with a Sorting Primitive (TR CS )

Geometric Data Structures

CMPS 2200 Fall 2017 Red-black trees Carola Wenk

CPSC / Sonny Chan - University of Calgary. Collision Detection II

Using Bounding Volume Hierarchies Efficient Collision Detection for Several Hundreds of Objects

Computational Geometry

would be included in is small: to be exact. Thus with probability1, the same partition n+1 n+1 would be produced regardless of whether p is in the inp

Polygon Triangulation

Connected Components of Underlying Graphs of Halving Lines

The Art Gallery Problem: An Overview and Extension to Chromatic Coloring and Mobile Guards

Range Reporting. Range reporting problem 1D range reporting Range trees 2D range reporting Range trees Predecessor in nested sets kd trees

Accelerating Geometric Queries. Computer Graphics CMU /15-662, Fall 2016

Lecture 6: Analysis of Algorithms (CS )

Transcription:

Computational Geometry Lecture 17

Computational geometry Algorithms for solving geometric problems in 2D and higher. Fundamental objects: Basic structures: point line segment line point set polygon L17.2

Computational geometry Algorithms for solving geometric problems in 2D and higher. Fundamental objects: Basic structures: point line segment line triangulation convex hull L17.3

Orthogonal range searching Input: n points in d dimensions E.g., representing a database of n records each with d numeric fields Query: Axis-aligned box (in 2D, a rectangle) Report on the points inside the box: Are there any points? How many are there? List the points. L17.4

Orthogonal range searching Input: n points in d dimensions Query: Axis-aligned box (in 2D, a rectangle) Report on the points inside the box Goal: Preprocess points into a data structure to support fast queries Primary goal: Static data structure In 1D, we will also obtain a dynamic data structure supporting insert and delete L17.5

1D range searching In 1D, the query is an interval: First solution using ideas we know: Interval trees Represent each point x by the interval [x, x]. Obtain a dynamic structure that can list k answers in a query in O(k lg n) time. L17.6

1D range searching In 1D, the query is an interval: Second solution using ideas we know: Sort the points and store them in an array Solve query by binary search on endpoints. Obtain a static structure that can list k answers in a query in O(k + lg n) time. Goal: Obtain a dynamic structure that can list k answers in a query in O(k + lg n) time. L17.7

1D range searching In 1D, the query is an interval: New solution that extends to higher dimensions: Balanced binary search tree New organization principle: Store points in the leaves of the tree. Internal nodes store copies of the leaves to satisfy binary search property: Node x stores in key[x] the maximum key of any leaf in the left subtree of x. L17.8

Example of a 1D range tree 1 17 43 6 8 12 14 26 35 41 42 59 61 L17.9

Example of a 1D range tree 17 x 8 42 x > x 1 14 35 43 1 6 12 17 26 41 43 59 6 8 12 14 26 35 41 42 59 61 L17.10

Example of a 1D range query 17 x 8 42 x > x 1 14 35 43 1 6 12 17 26 41 43 59 6 8 12 14 26 35 41 42 59 61 RANGE-QUERY([7, 41]) L17.11

General 1D range query root split node L17.12

Pseudocode, part 1: Find the split node 1D-RANGE-QUERY(T, [x 1, x 2 ]) w root[t] while w is not a leaf and (x 2 key[w] or key[w] < x 1 ) do if x 2 key[w] then w left[w] else w right[w] w is now the split node [traverse left and right from w and report relevant subtrees] L17.13

Pseudocode, part 2: Traverse left and right from split node 1D-RANGE-QUERY(T, [x 1, x 2 ]) [find the split node] w is now the split node if w is a leaf then output the leaf w if x 1 key[w] x 2 else v left[w] Left traversal while v is not a leaf do if x 1 key[v] then output the subtree rooted at right[v] v left[v] else v right[v] output the leaf v if x 1 key[v] x 2 [symmetrically for right traversal] L17.14

Analysis of 1D-RANGE-QUERY Query time: Answer to range query represented by O(lg n) subtrees found in O(lg n) time. Thus: Can test for points in interval in O(lg n) time. Can count points in interval in O(lg n) time if we augment the tree with subtree sizes. Can report the first k points in interval in O(k + lg n) time. Space: O(n) Preprocessing time: O(n lg n) L17.15

2D range trees Store a primary 1D range tree for all the points based on x-coordinate. Thus in O(lg n) time we can find O(lg n) subtrees representing the points with proper x-coordinate. How to restrict to points with proper y-coordinate? L17.16

2D range trees Idea: In primary 1D range tree of x-coordinate, every node stores a secondary 1D range tree based on y-coordinate for all points in the subtree of the node. Recursively search within each. L17.17

Analysis of 2D range trees Query time: In O(lg 2 n) = O((lg n) 2 ) time, we can represent answer to range query by O(lg 2 n) subtrees. Total cost for reporting k points: O(k + (lg n) 2 ). Space: The secondary trees at each level of the primary tree together store a copy of the points. Also, each point is present in each secondary tree along the path from the leaf to the root. Either way, we obtain that the space is O(n lg n). Preprocessing time: O(n lg n) L17.18

d-dimensional range trees Each node of the secondary y-structure stores a tertiary z-structure representing the points in the subtree rooted at the node, etc. Query time: O(k + lg d n) to report k points. Space: O(n lg d 1 n) Preprocessing time: O(n lg d 1 n) Best data structure to date: Query time: O(k + lg d 1 n) to report k points. Space: O(n (lg n / lg lg n) d 1 ) Preprocessing time: O(n lg d 1 n) L17.19

Primitive operations: Crossproduct Given two vectors v 1 = (x 1, y 1 ) and v 2 = (x 2, y 2 ), is their counterclockwise angle convex (< 180º), v 2 v 1 reflex (> 180º), or v 1 borderline (0 or 180º)? convex reflex Crossproduct v 1 v 2 = x 1 y 2 y 1 x 2 = v 1 v 2 sin. Thus, sign(v 1 v 2 ) = sign(sin ) > 0 if convex, < 0 if reflex, = 0 if borderline. v 2 L17.20

Primitive operations: Orientation test Given three points p 1, p 2, p 3 are they in clockwise (cw) order, in counterclockwise (ccw) order, or collinear? (p 2 p 1 ) (p 3 p 1 ) > 0 if ccw < 0 if cw = 0 if collinear p 1 p 3 p 2 cw p 1 p 1 ccw p 2 collinear p 3 p 2 p 3 L17.21

Primitive operations: Sidedness test Given three points p 1, p 2, p 3 are they in clockwise (cw) order, in counterclockwise (ccw) order, or collinear? Let L be the oriented line from p 1 to p 2. Equivalently, is the point p 3 right of L, p 2 left of L, or p 1 on L? cw p 1 p 3 p 1 ccw p 2 collinear p 3 p 2 p 3 L17.22

Line-segment intersection Given n line segments, does any pair intersect? Obvious algorithm: O(n 2 ). e d a b c f L17.23

Sweep-line algorithm Sweep a vertical line from left to right (conceptually replacing x-coordinate with time). Maintain dynamic set S of segments that intersect the sweep line, ordered (tentatively) by y-coordinate of intersection. Order changes when new segment is encountered, segment existing segment finishes, or endpoints two segments cross Key event points are therefore segment endpoints. L17.24

a d e e e b a a d d e d b e e a c c c c d b d d d b b b b b b f f f f a d e c b f L17.25

Sweep-line algorithm Process event points in order by sorting segment endpoints by x-coordinate and looping through: For a left endpoint of segment s: Add segment s to dynamic set S. Check for intersection between s and its neighbors in S. For a right endpoint of segment s: Remove segment s from dynamic set S. Check for intersection between the neighbors of s in S. L17.26

Analysis Use red-black tree to store dynamic set S. Total running time: O(n lg n). L17.27

Correctness Theorem: If there is an intersection, the algorithm finds it. Proof: Let X be the leftmost intersection point. Assume for simplicity that only two segments s 1, s 2 pass through X, and no two points have the same x-coordinate. At some point before we reach X, s 1 and s 2 become consecutive in the order of S. Either initially consecutive when s 1 or s 2 inserted, or became consecutive when another deleted. L17.28