9/5/06CS 6463: AT Computational Geometry1 CS 6463: AT Computational Geometry Fall 2006 Plane Sweep Algorithms and Segment Intersection Carola Wenk.

Slides:



Advertisements
Similar presentations
Introduction to Algorithms
Advertisements

Two Segments Intersect?
Polygon Triangulation
Spatial Information Systems (SIS) COMP Terrain modeling and geometric problems (part 2)
Computational Geometry
Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals.
2/14/13CMPS 3120 Computational Geometry1 CMPS 3120: Computational Geometry Spring 2013 Planar Subdivisions and Point Location Carola Wenk Based on: Computational.
1/13/15CMPS 3130/6130: Computational Geometry1 CMPS 3130/6130: Computational Geometry Spring 2015 Convex Hulls Carola Wenk.
Brute-Force Triangulation
2/3/15CMPS 3130/6130 Computational Geometry1 CMPS 3130/6130 Computational Geometry Spring 2015 Triangulations and Guarding Art Galleries II Carola Wenk.
CS16: Introduction to Data Structures & Algorithms
One of the most important problems is Computational Geometry is to find an efficient way to decide, given a subdivision of E n and a point P, in which.
9/12/06CS 6463: AT Computational Geometry1 CS 6463: AT Computational Geometry Fall 2006 Triangulations and Guarding Art Galleries II Carola Wenk.
© The McGraw-Hill Companies, Inc., Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
1 Voronoi Diagrams. 2 Voronoi Diagram Input: A set of points locations (sites) in the plane.Input: A set of points locations (sites) in the plane. Output:
1 Closest Points A famous algorithmic problem... Given a set of points in the plane (cities in the U.S., transistors on a circuit board, computers on a.
Intersections. Intersection Problem 3 Intersection Detection: Given two geometric objects, do they intersect? Intersection detection (test) is frequently.
November 4, Algorithms and Data Structures Lecture XIV Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.
Robert Pless, CS 546: Computational Geometry Lecture #3 Last Time: Convex Hulls Today: Plane Sweep Algorithms, Segment Intersection, + (Element Uniqueness,
Computational Geometry -- Voronoi Diagram
17. Computational Geometry Chapter 7 Voronoi Diagrams.
Line Segment Intersection Computational Geometry, WS 2007/08 Lecture 3 – Part I Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik.
Lecture 12 : Special Case of Hidden-Line-Elimination Computational Geometry Prof. Dr. Th. Ottmann 1 Special Cases of the Hidden Line Elimination Problem.
Special Cases of the Hidden Line Elimination Problem Computational Geometry, WS 2007/08 Lecture 16 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen,
2 -1 Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
Hidden-Line Elimination Computational Geometry, WS 2006/07 Lecture 14 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.
Point Location Computational Geometry, WS 2007/08 Lecture 5 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät für.
Closest Pair of Points Computational Geometry, WS 2006/07 Lecture 9, Part II Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen,
Lecture 6: Point Location Computational Geometry Prof. Dr. Th. Ottmann 1 Point Location 1.Trapezoidal decomposition. 2.A search structure. 3.Randomized,
Voronoi Diagrams.
Line Segment Intersection Computational Geometry, WS 2006/07 Lecture 3 – Part II Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik.
Lecture 2 Line Segment Intersection Computational Geometry Prof.Dr.Th.Ottmann 1 Line Segment Intersection Motivation: Computing the overlay of several.
Line Segment Intersection Computational Geometry, WS 2006/07 Lecture 3 – Part I Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik.
Lection 1: Introduction Computational Geometry Prof.Dr.Th.Ottmann 1 History: Proof-based, algorithmic, axiomatic geometry, computational geometry today.
Lecture 2 Line Segment Intersection Computational Geometry Prof.Dr.Th.Ottmann 1 Line Segment Intersection Motivation: Computing the overlay of several.
Important Problem Types and Fundamental Data Structures
Brute-Force Triangulation
Advanced Algorithm Design and Analysis (Lecture 9) SW5 fall 2004 Simonas Šaltenis E1-215b
1 Geometric Intersection Determining if there are intersections between graphical objects Finding all intersecting pairs Brute Force Algorithm Plane Sweep.
9/7/06CS 6463: AT Computational Geometry1 CS 6463: AT Computational Geometry Fall 2006 Triangulations and Guarding Art Galleries Carola Wenk.
Chapter Tow Search Trees BY HUSSEIN SALIM QASIM WESAM HRBI FADHEEL CS 6310 ADVANCE DATA STRUCTURE AND ALGORITHM DR. ELISE DE DONCKER 1.
UNC Chapel Hill M. C. Lin Line Segment Intersection Chapter 2 of the Textbook Driving Applications –Map overlap problems –3D Polyhedral Morphing.
14/13/15 CMPS 3130/6130 Computational Geometry Spring 2015 Windowing Carola Wenk CMPS 3130/6130 Computational Geometry.
Center for Graphics and Geometric Computing, Technion 1 Computational Geometry Chapter 8 Arrangements and Duality.
Center for Graphics and Geometric Computing, Technion 1 Computational Geometry Chapter 8 Arrangements and Duality.
2/19/15CMPS 3130/6130 Computational Geometry1 CMPS 3130/6130 Computational Geometry Spring 2015 Voronoi Diagrams Carola Wenk Based on: Computational Geometry:
CMPS 3130/6130 Computational Geometry Spring 2015
Computational Geometry: Intersection Search Joseph S. B. Mitchell Stony Brook University.
CMPS 3130/6130 Computational Geometry Spring 2015
Lecture 15 Computational Geometry Geometry sweeping Geometric preliminaries Some basics geometry algorithms.
9/8/10CS 6463: AT Computational Geometry1 CS 6463: AT Computational Geometry Fall 2010 Triangulations and Guarding Art Galleries Carola Wenk.
Center for Graphics and Geometric Computing, Technion 1 Computational Geometry Chapter 9 Line Arrangements.
1/20/15CMPS 3130/6130 Computational Geometry1 CMPS 3130/6130 Computational Geometry Spring 2015 Plane Sweep Algorithms I Carola Wenk.
Polygon Triangulation
Computational Geometry
CMPS 3130/6130 Computational Geometry Spring 2017
Computational Geometry
CMPS 3130/6130 Computational Geometry Spring 2017
Algorithm design techniques Dr. M. Gavrilova
CMPS 3130/6130 Computational Geometry Spring 2017
Computational Geometry Capter:1-2.1
Segment Trees Basic data structure in computational geometry.
CMPS 3130/6130 Computational Geometry Spring 2017
CMPS 3130/6130 Computational Geometry Spring 2017
Kinetic Collision Detection for Convex Fat Objects
Computational Geometry
CMPS 3120: Computational Geometry Spring 2013
Algorithms and Data Structures Lecture XIV
Presentation transcript:

9/5/06CS 6463: AT Computational Geometry1 CS 6463: AT Computational Geometry Fall 2006 Plane Sweep Algorithms and Segment Intersection Carola Wenk

9/5/06CS 6463: AT Computational Geometry2 Closest Pair Problem: Given P  R 2, |P|=n, find the distance of the closest pair in P

9/5/06CS 6463: AT Computational Geometry3 Plane Sweep: An Algorithm Design Technique Simulate sweeping a vertical line from left to right across the plane. Maintain cleanliness property: At any point in time, to the left of sweep line everything is clean, i.e., properly processed. Sweep line status: Store information along sweep line Events: Discrete points in time when sweep line status needs to be updated

9/5/06CS 6463: AT Computational Geometry4 Plane Sweep: An Algorithm Design Technique Simulate sweeping a vertical line from left to right across the plane. Maintain cleanliness property: At any point in time, to the left of sweep line everything is clean, i.e., properly processed. Sweep line status: Store information along sweep line Events: Discrete points in time when sweep line status needs to be updated Algorithm Generic_Plane_Sweep: Initialize sweep line status S at time x=-  Store initial events in event queue Q, a priority queue ordered by x-coordinate while Q ≠  // extract next event e: e = Q.extractMin(); // handle event: Update sweep line status Discover new upcoming events and insert them into Q

9/5/06CS 6463: AT Computational Geometry5 Plane sweep for Closest Pair Problem: Given P  R 2, |P|=n, find the distance of the closest pair in P Sweep line status: –Store current distance Δ of closest pair of points to the left of sweep line –Store points in Δ-strip left of sweep line –Store pointer to leftmost point in strip Events: All points in P. No new events will be added. → Presort P by x-coordinate. Cleanliness property

9/5/06CS 6463: AT Computational Geometry6 Plane sweep for Closest Pair, II Presort P by x-coordinate How to store points in Δ-strip? –Store points in Δ-strip left of sweep line in a balanced binary search tree, ordered by y-coordinate → Add and delete point and search in O(log n) time Event handling: –New event: Sweep line advances to point p  P –Update sweep line status: Delete points outside Δ-strip from search tree by using previous leftmost point in strip and x-order on P Find points at distance  Δ from p by performing two searches → Constant number of points, see lemma from previous class Check distance of these points to p, and possibly update Δ –No new events necessary to discover O(n log n) O(n log n) total O(n log n + nc) total O(n  c) total Total runtime: O(n log n)

9/5/06CS 6463: AT Computational Geometry7 Balanced Binary Search Tree -- a bit different key[x] is the maximum key of any leaf in the left subtree of x.

9/5/06CS 6463: AT Computational Geometry x x  x x > x key[x] is the maximum key of any leaf in the left subtree of x. Balanced Binary Search Tree -- a bit different

9/5/06CS 6463: AT Computational Geometry R ANGE -Q UERY ([7, 41]) x x  x x > x Balanced Binary Search Tree -- a bit different

9/5/06CS 6463: AT Computational Geometry10 Plane Sweep: An Algorithm Design Technique Plane sweep algorithms (also called sweep line algorithms) are a special kind of incremental algorithms Their correctness follows inductively by maintaining the cleanliness property Common runtimes in the plane are O(n log n): –n events are processed –Update of sweep line status takes O(log n) –Update of event queue: O(log n) per event

9/5/06CS 6463: AT Computational Geometry11 Geometric Intersections Important and basic problem in Computational Geometry Solid modeling: Build shapes by applying set operations (intersection, union). Robotics: Collision detection and avoidance Geographic information systems: Overlay two subdivisions (e.g., road network and river network) Computer graphics: Ray shooting to render scenes

9/5/06CS 6463: AT Computational Geometry12 Line Segment Intersection Input: A set S={s 1, …, s n } of (closed) line segments in R 2 Output: All intersection points between segments in S

9/5/06CS 6463: AT Computational Geometry13 Line Segment Intersection n line segments can intersect as few as 0 and as many as =O(n 2 ) times Simple algorithm: Try out all pairs of line segments → Takes O(n 2 ) time → Is optimal in worst case Challenge: Develop an output-sensitive algorithm –Runtime depends on size k of the output –Here: 0  k  c n 2, where c is a constant –Our algorithm will have runtime: O( (n+k) log n) –Best possible runtime: O( n log n + k) → O(n 2 ) in worst case, but better in general n2n2

9/5/06CS 6463: AT Computational Geometry14 Complexity Why is runtime O( n log n + k) optimal? The element uniqueness problem requires  (n log n) time in algebraic decision tree model of computation (Ben-Or ’83) Element uniqueness : Given n real numbers, are all of them distinct? Solve element uniqueness using line segment intersection : –Take n numbers, convert into vertical line segments. There is an intersection iff there are duplicate numbers. –If we could solve line segment intersection in o(n log n) time, i.e., strictly faster than Θ(n log n), then element uniqueness could be solved faster. Contradiction.

9/5/06CS 6463: AT Computational Geometry15 Intersection of two line segments Two line segments ab and cd Write in terms of convex combinations: p(s) = (1-s) a + s b for 0  s  1 q(t) = (1-t) c + t d for 0  t  1 Intersection if p(s)=q(t)  Equation system (1-s) a x + s b x = (1-t) c x + t d x (1-s) a y + s b y = (1-t) c y + t d y Solve for s and t. In division, if divisor = 0 then line segments are parallel (or collinear). Otherwise get rational numbers for s and t. Either use floating point arithmetic or exact arithmetic.

9/5/06CS 6463: AT Computational Geometry16 Plane sweep algorithm Cleanliness property: –All intersections to the left of sweep line l have been reported Sweep line status: –Store segments that intersect the sweep line l, ordered along the intersection with l. Events: –Points in time when sweep line status changes combinatorially (i.e., the order of segments intersecting l changes) → Endpoints of segments (insert in beginning) → Intersection points (compute on the fly during plane sweep)

9/5/06CS 6463: AT Computational Geometry17 General position Assume that “nasty” special cases don’t happen: –No line segment is vertical –Two segments intersect in at most one point –No three segments intersect in a common point

9/5/06CS 6463: AT Computational Geometry18 Event Queue Need to keep events sorted: –Lexicographic order (first by x-coordinate, and if two events have same x-coordinate then by y-coordinate) Need to be able to remove next point, and insert new points in O(log n) time Need to make sure not to process same event twice  Use a priority queue (heap), and possibly extract multiples  Or, use balanced binary search tree

9/5/06CS 6463: AT Computational Geometry19 Sweep Line Status Store segments that intersect the sweep line l, ordered along the intersection with l. Need to insert, delete, and find adjacent neighbor in O(log n) time Use balanced binary search tree, storing the order in which segments intersect l in leaves b c d e cbedcbed

9/5/06CS 6463: AT Computational Geometry20 Event Handling 1.Left segment endpoint –Add segment to sweep line status –Test adjacent segments on sweep line l for intersection with new segment (see Lemma) –Add new intersection points to event queue a b c d e cbdcbd cbedcbed

9/5/06CS 6463: AT Computational Geometry21 Event Handling 2. Intersection point –Report new intersection point –Two segments change order along l → Test new adjacent segments for new intersection points (to insert into event queue) a b c d e cebdcebd cbedcbed Note: “new” intersection might have been detected before.

9/5/06CS 6463: AT Computational Geometry22 Event Handling 3. Right segment endpoint –Delete segment from sweep line status –Two segments become adjacent. Check for intersection points (to insert in event queue) a b c d e ecbdecbd ecdecd

9/5/06CS 6463: AT Computational Geometry23 Intersection Lemma Lemma: Let s, s’ be two non-vertical segments whose interiors intersect in a single point p. Assume there is no third segment passing through p. Then there is an event point to the left of p where s and s’ become adjacent (and hence are tested for intersection). Proof: Consider placement of sweep line infinitesimally left of p. s and s’ are adjacent along sweep line. Hence there must have been a previous event point where s and s’ become adjacent. p s s’

9/5/06CS 6463: AT Computational Geometry24 Runtime Sweep line status updates: O(log n) Event queue operations: O(log n), as the total number of stored events is  2n + k, and each operation takes time O(log(2n+k)) = O(log n 2 ) = O(log n) There are O(n+k) events. Hence the total runtime is O((n+k) log n) k = O(n 2 )