November 4, 20021 Algorithms and Data Structures Lecture XIV Simonas Šaltenis Nykredit Center for Database Research Aalborg University

Slides:



Advertisements
Similar presentations
Two Segments Intersect?
Advertisements

Polygon Triangulation
Spatial Information Systems (SIS) COMP Terrain modeling and geometric problems (part 2)
Computational Geometry
2/9/06CS 3343 Analysis of Algorithms1 Convex Hull  Given a set of pins on a pinboard  And a rubber band around them  How does the rubber band look when.
1/13/15CMPS 3130/6130: Computational Geometry1 CMPS 3130/6130: Computational Geometry Spring 2015 Convex Hulls Carola Wenk.
October 31, Algorithms and Data Structures Lecture XIII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
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.
Computing Convex Hulls CLRS 33.3
Convex Hull obstacle start end Convex Hull Convex Hull
CS16: Introduction to Data Structures & Algorithms
What is Computational Geometry? Study of Data Structures and Algorithms for Geometric Problems 1970 ’ s: Need for Computational Geometry Recognized; Progress.
9/12/06CS 6463: AT Computational Geometry1 CS 6463: AT Computational Geometry Fall 2006 Triangulations and Guarding Art Galleries II Carola Wenk.
Convex Hulls in Two Dimensions Definitions Basic algorithms Gift Wrapping (algorithm of Jarvis ) Graham scan Divide and conquer Convex Hull for line intersections.
CS4413 Divide-and-Conquer
Introduction to Algorithms Rabie A. Ramadan rabieramadan.org 6 Ack : Carola Wenk nad Dr. Thomas Ottmann tutorials.
Computational Geometry
8/29/06CS 6463: AT Computational Geometry1 CS 6463: AT Computational Geometry Spring 2006 Convex Hulls Carola Wenk.
Advanced Algorithm Design and Analysis (Lecture 10) SW5 fall 2004 Simonas Šaltenis E1-215b
Computational Geometry for the Tablet PC
5/17/2015 1:32 AMConvex Hull1 obstacle start end.
What does that mean? To get the taste we will just look only at some sample problems... [Adapted from S.Suri]
ADA: 16. CG Topics1 Objective o an examination of four important CG topics o just a taster of a very large research area Algorithm Design and Analysis.
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.
9/5/06CS 6463: AT Computational Geometry1 CS 6463: AT Computational Geometry Fall 2006 Plane Sweep Algorithms and Segment Intersection Carola Wenk.
Intersections. Intersection Problem 3 Intersection Detection: Given two geometric objects, do they intersect? Intersection detection (test) is frequently.
Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.
Query Processing in Databases Dr. M. Gavrilova.  Introduction  I/O algorithms for large databases  Complex geometric operations in graphical querying.
Robert Pless, CS 546: Computational Geometry Lecture #3 Last Time: Convex Hulls Today: Plane Sweep Algorithms, Segment Intersection, + (Element Uniqueness,
N Line Segments Problem Given a set of n line segments in the plane, determine whether or not any intersection exists. It is not required to output all.
November 5, Algorithms and Data Structures Lecture VIII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Lecture 12 : Special Case of Hidden-Line-Elimination Computational Geometry Prof. Dr. Th. Ottmann 1 Special Cases of the Hidden Line Elimination Problem.
Chapter 4: Divide and Conquer The Design and Analysis of Algorithms.
Lecture 4: Divide and Conquer III: Other Applications and Examples Shang-Hua Teng.
Closest Pair of Points Computational Geometry, WS 2006/07 Lecture 9, Part II Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen,
Voronoi Diagrams.
Design and Analysis of Algorithms - Chapter 41 Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two.
Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances.
AALG, lecture 11, © Simonas Šaltenis, Range Searching in 2D Main goals of the lecture: to understand and to be able to analyze the kd-trees and.
Lecture 2 Line Segment Intersection Computational Geometry Prof.Dr.Th.Ottmann 1 Line Segment Intersection Motivation: Computing the overlay of several.
Brute-Force Triangulation
Geometric Algorithms1 segment intersection orientation point inclusion simple closed path.
Advanced Algorithm Design and Analysis (Lecture 9) SW5 fall 2004 Simonas Šaltenis E1-215b
CSE53111 Computational Geometry TOPICS q Preliminaries q Point in a Polygon q Polygon Construction q Convex Hulls Further Reading.
1 Geometric Intersection Determining if there are intersections between graphical objects Finding all intersecting pairs Brute Force Algorithm Plane Sweep.
1 Computational Geometry Instructor: yedeshi
UNC Chapel Hill M. C. Lin Line Segment Intersection Chapter 2 of the Textbook Driving Applications –Map overlap problems –3D Polyhedral Morphing.
Computational Geometry (35/33) Line Segments and cross-product Segment intersection and Sweep Line Convex Hull and Graham’s Scan, Jarvis’s march Divide-and-Conquer.
1 Closest Pair of Points (from “Algorithm Design” by J.Kleinberg and E.Tardos) Closest pair. Given n points in the plane, find a pair with smallest Euclidean.
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
15. Computational Geometry Topics
UNC Chapel Hill M. C. Lin Computing Voronoi Diagram For each site p i, compute the common inter- section of the half-planes h(p i, p j ) for i  j, using.
Lecture 15 Computational Geometry Geometry sweeping Geometric preliminaries Some basics geometry algorithms.
1/20/15CMPS 3130/6130 Computational Geometry1 CMPS 3130/6130 Computational Geometry Spring 2015 Plane Sweep Algorithms I Carola Wenk.
Polygon Triangulation
Advanced Algorithms Analysis and Design
Query Processing in Databases Dr. M. Gavrilova
CMPS 3130/6130 Computational Geometry Spring 2017
Convex Hull obstacle start end 11/21/2018 4:05 AM Convex Hull
Computational Geometry (35/33)
Computational Geometry Capter:1-2.1
Convex Hull 1/1/ :28 AM Convex Hull obstacle start end.
Algorithms and Data Structures Lecture XIII
CHAPTER 33 Computational Geometry
Convex Hull obstacle start end 4/30/2019 5:21 PM Convex Hull
Introduction to Algorithms
Algorithms and Data Structures Lecture XIV
Given a list of n  8 integers, what is the runtime bound on the optimal algorithm that sorts the first eight? O(1) O(log n) O(n) O(n log n) O(n2)
Presentation transcript:

November 4, Algorithms and Data Structures Lecture XIV Simonas Šaltenis Nykredit Center for Database Research Aalborg University

November 4, This Lecture Introduction to computational geometry Points and lines in 2D space Line sweep technique Closest pair of points using divide-and-conquer

November 4, Computational Geometry The term first appeared in the 70’s Originally referred to computational aspects of solid/geometric modeling Later as the field of algorithm design and analysis for discrete geometry Algorithmic basis for many scientific & engineering disciplines GIS, robotics, computer graphics, computer vision, CAD/CAM, VLSI design, etc.

November 4, Point: defined by a pair of coordinates (x,y) Segment: portion of a straight line between two points – their convex combinaiton Polygon: a circular sequence of points (vertices) and segments (edges) between them Geometric Objects in Plane A B

November 4, Some Geomtric Problems Segment intersection: Given two segments, do they intersect? Simple closed path: Given a set of points, find a non-intersecting polygon with vertices on the points

November 4, Some Geomtric Problems (2) Inclusion in polygon: Is a point inside or outside a polygon?

November 4, Segment Intersection Test whether segments (a,b) and (c,d) intersect. How do we do it? We could start by writing down the equations of the lines through the segments, then test whether the lines intersect, then... An alternative (and safer) approach is based in the notion of orientation of an ordered triplet of points in the plane

November 4, Orientation in the Plane The orientation of an ordered triplet of points in the plane can be counterclockwise (left turn) clockwise (right turn) collinear (no turn) counterclockwise (left turn) clockwise (right turn) collinear (no turn)

November 4, Intersection and Orientation Two segments (p 1,q 1 ) and (p 2,q 2 ) intersect if and only if one of the following two conditions is satisfied General case: (p 1,q 1,p 2 ) and (p 1,q 1,q 2 ) have different orientations and (p 2,q 2,p 1 ) and (p 2,q 2,q 1 ) have different orientations Special case (p 1,q 1,p 2 ), (p 1,q 1,q 2 ), (p 2,q 2,p 1 ), and (p 2,q 2,q 1 ) are all collinear and the x-projections of (p 1,q 1 ) and (p 2,q 2 ) intersect the y-projections of (p 1,q 1 ) and (p 2,q 2 ) intersect

November 4, Orientation Examples General case: (p 1,q 1,p 2 ) and (p 1,q 1,q 2 ) have different orientations and (p 2,q 2,p 1 ) and (p 2,q 2,q 1 ) have different orientations

November 4, Orientation Examples (2)

November 4, Orientation Examples (3) Special case (p 1,q 1,p 2 ), (p 1,q 1,q 2 ), (p 2,q 2,p 1 ), and (p 2,q 2,q 1 ) are all collinear and the x-projections of (p 1,q 1 ) and (p 2,q 2 ) intersect the y-projections of (p 1,q 1 ) and (p 2,q 2 ) intersect

November 4, Computing the Orientation slope of segment (p 1,p 2 ):  = (y 2 -y 1 )/(x 2 -x 1 ) slope of segment (p 2,p 3 ):  = (y 3 -y 2 )/(x 3 -x 2 ) Orientation test counterclockwise (left turn):  clockwise (right turn):  collinear (no turn): 

November 4, Computing the Orientation (2) The orientation depends on whether the following expression is positive, negative, or 0 (y 2 -y 1 )(x 3 -x 2 ) - (y 3 -y 2 )(x 2 -x 1 ) = ? This is a cross product of two vectors

November 4, Determining Intersections Given a set of n segments, we want to determine whether any two line segments intersect A brute force approach would take O(n 2 ) time (testing each with every other segment for intersection)

November 4, Determining Intersections (2) It can be done faster by using a powerfull comp. geometry technique, called plane-sweeping. Two sets of data are maintained: sweep-line status: the set of segments intersecting the sweep line l event-point schedule: where updates to l are required l : sweep line event point

November 4, Plane Sweeping Algorithm Each segment end point is an event point At an event point, update the status of the sweep line & perform intersection tests left end point: a new segment is added to the status of l and it’s tested against the rest right end point: it’s deleted from the status of l Only testing pairs of segments for which there is a horizontal line that intersects both segments This might be not good enough. It may still be inefficient, O(n 2 ) for some cases

November 4, Plane Sweep Algorithm (2) To include the idea of being close in the horizontal direction, only test segments that are adjacent in the vertical direction Only test a segment with the ones above and below (predecessor and successor, rings a bell…) the ”above-below” relationship among segments does not change unless there is an intersection New “status”: ordered sequence of segments

November 4, Plane Sweeping Algorithm (3) b a c d e ababa bcabca bcadbcad bcdbcd cdcd ecdecd eded e

November 4, Pseudo Code AnySegmentsIntersect(S) 01 T   02 sort the end points of the segments in S from left to right, breaking ties by putting points with lower y-coords first 03 for each point p in the sorted list of end points do 04 if p is the left end point of a segment s then 05 Insert(T,s) 06 if (Above(T,s) exists and intersects s) or (Below(T,s) exists and intersects s) then 07 return TRUE 08 if p is the right end point of a segment s then 09 if both Above(T,s) and Below(T,s) exist and Above(T,s) intersects Below(T,s) then 10 return TRUE 11 Delete(T,s) 12 return FALSE

November 4, Implementing Event Queue Define an order on event points Store the event points in a priority queue both insertion or deletion takes O(log n) time, where n is the number of events, and fetching minimum – O(1) For our algorithm sorted array is enough, because the set of events does not change. Maintain the status of l using a binary search treeT (e.g., red-black tree) the up-to-down order of segments on the line l the left-to-right order of in-order traversal of T each update and search takes O(log n)

November 4, Status and Structure l SjSj SkSk SlSl SmSm SiSi SiSi SjSj SkSk SlSl SmSm T

November 4, Running Time Sorting the segments takes O(n log n) time The loop is executed once for every end point (2n) taking each time O(log n) time (e.g., red-black tree operation) The total running time is O(n log n)

November 4, Closest Pair Given a set P of N points, find p,q  P, such that the distance d(p, q) is minimum Algorithms for determining the closest pair: Brute Force O(n 2 ) Divide and Conquer O(n log n) Sweep-Line O(n log n)

November 4, Brute Force Compute all the distances d(p,q) and select the minimum distance Running time O(n 2 )

November 4, Divide and Conquer Sort points on the x-coordinate and divide them in half Closest pair is either in one of the halves or has a member in each half

November 4, Divide and Conquer (2) Phase 1: Sort the points by their x- coordinate p 1 p 2... p n/2... p n/ p n

November 4, Divide and Conquer (3) Phase 2: Recursively compute closest pairs and minimum distances, d l, d r in P l = {p 1, p 2,..., p n/2 } P r = {p n/2+1,..., p n } Find the closest pair and closest distance in central strip of width 2 d, where d = min(d l, d r ) in other words...

November 4, Divide and Conquer (4) Find the closest (, ) pair in a strip of width 2d, knowing that no (, ) or (, ) pair is closer than d

November 4, Combining Two Solutions For each point p in the strip, check distances d(p, q), where p and q are of different colors and: There are no more than four such points!

November 4, Running Time Sorting by the y-coordinate at each conquering step yields the following recurrence

November 4, Improved Algorithm The idea: Sort all the points by x and y coordinate once Before recursive calls, partition the sorted lists into two sorted sublists for the left and right halves When combining, run through the y-sorted list once and select all points that are in a 2d strip around l.

November 4, Running Time Phase 1: Sort by x and y coordinate: O(n log n) Phase 2: Partition: O(n) Recur: 2T(n/2) Combine: O(n) T(n) = 2 T(n/2) + n = O(n log n) Total Time: O(n log n)

November 4, Next Lecture Introduction to complexity classes Tractable/intractable problems NP-Completeness