Algorithms and Data Structures lecture C(hex) Computational geometry: planar rectangular range query, planar convex hull Szymon Grabowski sgrabow@kis.p.lodz.pl.

Slides:



Advertisements
Similar presentations
Computational Geometry - Part II Mohammed Nadeem Ahmed Raghavendra Kyatham.
Advertisements

 Distance Problems: › Post Office Problem › Nearest Neighbors and Closest Pair › Largest Empty and Smallest Enclosing Circle  Sub graphs of Delaunay.
algorithms and data structures
Brute-Force Triangulation
Computing Convex Hulls CLRS 33.3
Convex Hull obstacle start end Convex Hull Convex Hull
CS16: Introduction to Data Structures & Algorithms
C o m p u t i n g C O N V E X H U L L S by Kok Lim Low 10 Nov 1998 COMP Presentation.
UNC Chapel Hill M. C. Lin Polygon Triangulation Chapter 3 of the Textbook Driving Applications –Guarding an Art Gallery –3D Morphing.
Geometric Algorithms João Comba. Example: Convex Hull convex Non-convex.
The Divide-and-Conquer Strategy
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
Convex Hulls May Shmuel Wimer Bar Ilan Univ., Eng. Faculty Technion, EE Faculty.
By Groysman Maxim. Let S be a set of sites in the plane. Each point in the plane is influenced by each point of S. We would like to decompose the plane.
Convex Sets & Concave Sets A planar region R is called convex if and only if for any pair of points p, q in R, the line segment pq lies completely in R.
1 Convex Hull in Two Dimensions Jyun-Ming Chen Refs: deBerg et al. (Chap. 1) O’Rourke (Chap. 3)
Computational Geometry
Lecture 3: Reduce to known problem Convex Hull (section 33.3 of CLRS). Suppose we have a bunch of points in the plane, given by their x and y coordinates.
Informal Definition : Let S is set of nails sticking out from a board. the convex hull can be visualized as the shape formed by a tight rubber band that.
1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem.
Algorithms and Data Structures Lecture 13. Agenda: Plane Geometry: algorithms on polygons - Verification if point belongs to a polygon - Convex hull.
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]
Query Processing in Databases Dr. M. Gavrilova.  Introduction  I/O algorithms for large databases  Complex geometric operations in graphical querying.
Lecture 12 : Special Case of Hidden-Line-Elimination Computational Geometry Prof. Dr. Th. Ottmann 1 Special Cases of the Hidden Line Elimination Problem.
1 What is Computational Geometry Ref: Godfried T. Toussaint.
Brute-Force Triangulation
Advanced Algorithm Design and Analysis (Lecture 9) SW5 fall 2004 Simonas Šaltenis E1-215b
October 8, 2013Computer Vision Lecture 11: The Hough Transform 1 Fitting Curve Models to Edges Most contours can be well described by combining several.
Computational Geometry Convex Hulls Robust Geometric Primitives Degeneracy and Stability Nick Pilkington.
9/7/06CS 6463: AT Computational Geometry1 CS 6463: AT Computational Geometry Fall 2006 Triangulations and Guarding Art Galleries Carola Wenk.
Convex Hull. What is the Convex Hull? Imagine a set of points on a board with a nail hammered into each point. Now stretch a rubber band over all the.
C o m p u t i n g C O N V E X H U L L S. Presentation Outline 2D Convex Hulls –Definitions and Properties –Approaches: Brute Force Gift Wrapping QuickHull.
Center for Graphics and Geometric Computing, Technion 1 Computational Geometry Chapter 8 Arrangements and Duality.
Fundamental Data Structures and Algorithms Klaus Sutner April 27, 2004 Computational Geometry.
Fundamental Data Structures and Algorithms Margaret Reid-Miller 27 April 2004 Computational Geometry.
1 11. Polygons Polygons 2D polygons ( 다각형 ) –Polygon sides are all straight lines lying in the same plane 3D polyhedra ( 다면체 )  chap. 12 –Polyhedra.
Computational Geometry 2D Convex Hulls
A planar region R is called convex if and only if for any pair of points p, q in R, the line segment pq lies completely in R. Otherwise, it is called concave.
COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.
Lecture 15 Computational Geometry Geometry sweeping Geometric preliminaries Some basics geometry algorithms.
CS6234 Advanced Algorithms - Convex hull. Terminologies – ◦ Convex hull of a set Q of points is the smallest convex polygon P for which each point in.
9/8/10CS 6463: AT Computational Geometry1 CS 6463: AT Computational Geometry Fall 2010 Triangulations and Guarding Art Galleries Carola Wenk.
Convex hulls in 3D Maciej Kot. Finding convex hull Given a set of points, find a convex hull that contains all of them and is minimal.
Convex Hulls Guo Qi, Chen Zhenghai, Wang Guanhua, Shen Shiqi, Himeshi De Silva.
Polygon Triangulation
Algorithms and Data Structures lecture C(hex) Computational geometry: planar rectangular range query, planar convex hull Szymon Grabowski
CMPS 3130/6130 Computational Geometry Spring 2017
3. Polygon Triangulation
Introduction to Spatial Computing CSE 555
Introduction to Polygons
Convex Hull.
Query Processing in Databases Dr. M. Gavrilova
Algorithm design techniques Dr. M. Gavrilova
Fitting Curve Models to Edges
Convex Hull obstacle start end 11/21/2018 4:05 AM Convex Hull
Computational Geometry Capter:1-2.1
Geometry.
Convex Sets & Concave Sets
Convex Hull 1/1/ :28 AM Convex Hull obstacle start end.
CHAPTER 33 Computational Geometry
CMPS 3130/6130: Computational Geometry Spring 2017
Computational Geometry
Convex Hull obstacle start end 4/30/2019 5:21 PM Convex Hull
Introduction to Algorithms
Computational Geometry Algorithms
Geometry.
Algorithms and Data Structures Lecture XIV
Convex Hull - most ubiquitous structure in computational geometry
Presentation transcript:

Algorithms and Data Structures lecture C(hex) Computational geometry: planar rectangular range query, planar convex hull Szymon Grabowski sgrabow@kis.p.lodz.pl http://szgrabowski.kis.p.lodz.plAlg15/ Łódź, 2015

Computational geometry Hard to define the field precisely. Geometric problems considered, in 2D, 3D and even in higher (arbitrarily high) dimensions. Historically, CG developed as a generalization of sorting and searching problems from 1-dim. (numerical) keys into multidimensional objects. Hot research area since the late 1970s (very influential Shamos’s PhD...). Already the 2-dimensional space is interesting enough...

Recommended literature Dave Mount, CMSC 754 Computational Geometry, Fall 2002, lecture notes. http://www.cs.umd.edu/~mount/754/Lects/754lects.pdf Franco P. Preparata, Michael Ian Shamos, Geometria obliczeniowa. Wprowadzenie, Helion 2003, pp. 392 (in Polish). (Original title: Computational Geometry. An Introduction. Springer-Verlag, New York, 1985.) Joseph O'Rourke, Computational geometry in C, Cambridge University Press, 2nd edition, 1998. Mark de Berg, Marc van Krefeld, Mark Overmars, Otfried Schwarzkopf, Computational Geometry: Algorithms and Applications. Springer-Verlag, 2nd edition, 2000, pp. 367. Godfried T. Toussaint‘s web page: http://cgm.cs.mcgill.ca/~godfried/ And Cormen et al. as usual.

CG objects Mostly straight or flat objects. Lines, line segments, polygons, planes and polyhedra. Also simple curved objects like circles. Representation of a polygon (for example) is the set of its vertices in a “walking order” (e.g., counter-clockwise).

Typical CG problems NN queries: Find the nearest neighbor of a point q from the given dataset S. Range queries: Find all the points in S located within the radius r from a given point q. Shortest path: Given a set of obstacles (e.g., in the plane), find the shortest obstacle-avoiding path from a given point s to a given point t. http://www.cs.umd.edu/~mount/754/Lects/754lects.pdf

Typical CG problems, cont’d Convex hull. Triangulations (or other partitioning problems): Divide a complex object into a set of disjoint objects (e.g, any simple polygon into triangles). Simple concave polygon Complex polyon From: http://en.wikipedia.org/wiki/Polygon#Naming_polygons

Typical CG problems, cont’d Convex hull in 3D (and in d dim.). http://www.comp.nus.edu.sg/~tants/gHull_files/gHull_Jan2012.pdf

Typical CG problems, cont’d [ http://www. ams. sunysb Point-in-polygon test: Is point q inside simple polygon P? Naïve test: O(n). Smart (CG): O(log n) (after O(n) polygon preprocessing, ie. makes sense amortized over many tests...). q P n-gon

Typical CG problems, cont’d [ http://www. ams. sunysb Segment intersection: Given n line segments in the plane, determine: Does some pair intersect? (DETECT) Compute all points of intersection (REPORT) Naïve solution: O(n2). Smart (CG): O(n log n) detect, O(k + n log n) report (reporting is output-sensitive).

Typical CG problems, cont’d Art gallery problems (Klee, 1973): For a given simple polygon of n vertices, locate the minimum number of guards in a way to have every point of the polygon visible. 12 vertices. (a) 3 guards required. (b) 4 guards required. From: [O'Rourke, Computational geometry in C]

Typical CG problems, cont’d [ http://cgm. cs. mcgill Isothetic computational geometry (or rectilinear CG): Input data are such as line segments and polygons in which all the edges are either vertical or horizontal. Applications: VLSI design, image processing. Problem could be: given a set of isothetic (also called: orthogonal) rectangles in the plane, compute the boundary of the union of the rectangles (VERY IMPORTANT IN VLSI DESIGN). ...or the other way around: given an isothetic contour, break it into a union of a minimum number of rectangles.

The cross product of vectors A and B is the dashed area.

Cross product of vectors, cont’d p1 x p2 is positive iff p1 is clockwise from p2 with respect to the origin (0,0). p1 x p2 can be zero – when?

Determining whether consecutive segments turn left or right p2 p2 p1 p0 p1 p0 p0 p1 p2 – turn right or left? Simply calculate the cross product ( p2 – p0 ) x ( p1 – p0 ). If the product sign is positive, it means a right turn at p1 (picture above, right). Negative – left turn (pic. above, left). Zero – collinear points.

(Planar) convex hull problem Given a set Q of n points in 2 dimensions, find the minimal convex polygon CH(Q) containing all the points from Q. Minimal since CH(Q) is a subset of any convex set containing all points of Q. More precisely, the problem is to list the h vertices of CH(Q) ordered along its boundary. h is an output parameter (can’t be guessed beforehand).

Convex hull example Elastic band analogy: the band contracts to form the “hull” of the convex http://en.wikipedia.org/wiki/Image:ConvexHull.png

Convex hull applications [J Convex hull applications [J. O'Rourke, Computational geometry in C, 2nd edition, 1998] 1. Collision avoidance. If a convex hull of a robot avoids collision with an obstacle, then so does the robot. Easier to plan trajectories. Faster collision detection in computer games.  2. Smallest (bounding) box. The smallest area rectangle that encloses a polygon has at least one side touching with the convex hull of the polygon, so computing the CH of the polygon is the first step. 3. Shape analysis. Shapes may be classified (for the purpose of matching) by some special structures that depend on the computation of their convex hulls. 4. A building block for many more complex CG algorithms (e.g., finding the diameter of a set of points).

Overall worst-case time: O(n3). Pretty bad. A naïve algorithm There are n(n–1) / 2 = O(n2) pairs of points in Q, each of them corresponds to a unique line. For each line l (defined by some points p1, p2) we check in O(n) worst-case time if all the other points of Q lie on one side of l or not. If so, we say that (p1, p2) define a supporting line and this line segment will belong to CH(Q) (i.e., the points p1 and p2 will be somewhere on the output list, and they’ll be next to each other). We have at most n such pairs, joining them can be done, e.g., via sorting, i.e. in O(n log n) time. Overall worst-case time: O(n3). Pretty bad.

An illustration to the naïve algorithm line l won’t belong to CH(Q) here l is OK http://www.cis.upenn.edu/~suvenkat/677/lec1notes.ps

Quickhull algorithm (Preparata & Shamos, 1985) This and following slides: from http://www.bilmuh.gyte.edu.tr/BIL521/Lecture%20Notes/ LN_4_divide&conquer.ppt

Quickhull, step-by-step (1/7) Find extreme points above, below, left and right. Define a quadrilateral connecting extreme points, discard internal points.

Quickhull, step-by-step (2/7) 3. Process 4 triangles recursively.

Quickhull, step-by-step (3/7) For each triangle, find vertex with greatest distance from the triangle baseline. Define another triangle and discard internal triangles.

Quickhull, step-by-step (4/7) 6. Process two triangles recursively.

Quickhull, step-by-step (5/7)

Quickhull, step-by-step (6/7)

Quickhull, step-by-step (7/7)

Quickhull, time complexities Worst case: obviously O(n2) (why?). Best case: O(n), also obvious. Average case? This is harder. Assuming uniform point distribution in a unit square, the avg time is O(n log n). Quickhull was dubbed after quicksort. As with QS, the algorithm picks a “pivot” element, splits the data based on the pivot, and is recursively applied to each of the split sets. Also, as with quicksort, the pivot element is not guaranteed to split the data into equally sized sets, Worst case, closer look: O(nh), where h is the # of the CH(Q) boundary points.

Quickhull, final words [ http://www. cs. umd Why practical? The intuition is that in many applications most of the points lie in the interior of the hull. For example, if the points are uniformly distributed in a unit square, then it can be shown that the expected number of points on the convex hull is O(log n). There are better algorithms, but QH can be used as a preliminary step (filter) before some other algorithm (in a hope to combine good worst case and practical speed).

Jarvis march (1973) The Jarvis march uses a (very intuitive) technique called gift wrapping. We can say it simulates wrapping a piece of paper around the set Q. We attach the end of the paper to the lowest point in Q, which will be denoted as p0. Note that p0 must belong to CH(Q). Each next point (until reaching the highest point of Q) must be not lower than its predecessor. Formally, p1 is the point which has the least polar angle with respect to p0. Continue in the same way, i.e., look for p2 with respect to p1, etc. Finally you’ll obtain the right chain of CH(Q). Left chain – analogously.

Jarvis march, example ([Cormen])

Jarvis march complexity Finding p0: O(n) time. Finding p1: for each of n–1 remaining points its polar angle must be calculated and compared to the current min polar angle: O(1) time per each, i.e., O(n) in total. The convex hull of Q has h points, hence the overall complexity of the Jarvis march is O(nh) (worst, average and best case). For the worst case of h = O(n), we have O(n2).  Still, quite often h is small, so the Jarvis algorithm is practical (and very simple, isn’t it?).

The Graham scan (1972) [O’Rourke’98] reports: Perhaps the honor of the first paper published in the field of computational geometry should be accorded to Graham’s algorithm for finding the hull of points in two dimensions in O(n log n) time (Graham, 1972). In the late 1960s an application at Bell Laboratories required the hull of n  10,000 points, and they found the O(n2) algorithm in use too slow. Graham developed his simple algorithm in response to this need. Graham’s algorithm involves a stack. The stack S keeps candidate points. Each point of Q is pushed once onto the stack. At the end, S contains only the vertices of CH(Q), in counter-clockwise order of their appearance on the boundary. We’ll assume |Q|  3.

Graham scan pseudocode From [Cormen], chapter 35.3

Graham scan example (from [Cormen]) After steps 1–6. p0 is the lowest point. The other points are sorted appropriately.

Graham scan example (b) p2 rejected, as the ordered triple p1, p2, p3 didn’t form a left turn

Graham scan example (c) p3 seems okay. Put onto the stack...

Graham scan example (d) p4 kicked out

Graham scan example (e) p10 some-where above p5 seem okay (so far...) Now we skip over the boring steps (f) and (g)...

Graham scan example (h) p10 some-where above p7 and p8 got what they deserved

Graham scan example (i) heavy hand of justice expels p5, finally

Graham scan example (l) The rest is silence. After finding the last point, connect it with p0.

Graham scan complexity Beware: we’ll use n symbol below for the number of points from Q, as opposed to the Cormen et al. pseudocode where m is used. Step 1: O(n) time. Step 2: O(n log n) time (sorting). Steps 3–6: O(1) time. Steps 7–10: ??? The external loop runs n–2 times. The # of passes over the internal loop varies: may be as large as O(n). Does it mean the total complexity is O(n2) ??!

Graham scan complexity, cont’d Note that the time complexity of the steps 7–10 corresponds to the # of pop() calls in line 9. You cannot pop more items from a stack than you have pushed. And each point of Q is put onto the stack S only once. Hence the steps 7–10 need only O(n) time. In total we obtain O(n log n) worst-case time complexity (the sort is the bottleneck).