503_lecture8_S11

503_lecture8_S11 - UMass Lowell Computer Science 91.503 91...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: UMass Lowell Computer Science 91.503 91 503 Graduate Algorithms Prof. Karen D i l P f K Daniels Spring, 2011 Computational Geometry Overview from Cormen, et al. Cormen, Chapter 33 (with additional material from other sources) 1 Overview Computational Geometry Introduction C i lG I d i Line Segment Intersection Convex Hull Algorithms Nearest Neighbors/Closest Points 2 Introduction What is Computational Geometry? 3 Applied Computational Geometry Research Assoc. Prof Assoc Prof. Karen Daniels & Collaborators Design Clustering for Data Mining Analyze Covering for Geometric Modeling feasibility, estimation, optimization problems for covering, clustering, packing, layout, geometric modeling Packing for Manufacturing Apply Meshing for Geometric Modeling Courtesy of Cadence Design Systems Topological Invariant Estimation for 4 Geometric Modeling Typical Problems bin packing Voronoi diagram simplifying polygons shape similarity convex hull maintaining line g arrangements polygon partitioning nearest neighbor search kdkd-trees 5 SOURCE: SOURCE: Steve Skiena's Algorithm Design Manual (for problem descriptions, see graphics gallery at http://www.cs.sunysb.edu/~algorith) ) Common Computational Geometry Structures Convex Hull Voronoi Diagram New Point Delaunay Triangulation 6 source: O'Rourke, Computational Geometry in C Sample Tools of the Trade Algorithm D i P tt Al ith Design Patterns/Techniques: /T h i binary search divide-and-conquer duality divide-andrandomization sweep-line sweepincremental derandomization parallelism Algorithm Analysis Techniques: asymptotic analysis, amortized analysis Data Structures: wingedwinged-edge, quad-edge, range tree, kd-tree quadkd- Theoretical Computer Science principles: Th i lC S i i i l NPNP-completeness, hardness MATH Sets Summations Probability Growth of Functions Combinatorics Proofs Geometry Linear Algebra Recurrences Graph Theory 7 Computational Geometry in Context Geometry Design D i Applied pp Math Analyze A l Theoretical Computer Science Computational Geometry Efficient Geometric Algorithms Apply Applied Computer Science 8 Line Segment Intersections i i (2D) Intersection of 2 Line Segments Intersection of > 2Line Segments 9 Cross-Product-Based Geometric Primitives Some fundamental geometric questions: source: 91 503 t tb k C 91.503 textbook Cormen et al. t l p2 p3 p3 p2 p4 p1 p1 p0 p1 p2 (1) (2) (3) 10 Cross-Product-Based Geometric Primitives: (1) p2 33.1 p1 p0 x1 p1 p2 = det y 1 x2 = x1 y2 - x2 y1 y2 (1) Advantage: Advantage: less sensitive to accumulated round-off error round- 11 source: 91.503 textbook Cormen et al. Cross-Product-Based Geometric Primitives: (2) p2 p1 33.2 p0 (2) 12 source: 91.503 textbook Cormen et al. Intersection of 2 Line Segments Step 1: p 1: Bounding Box Test p3 p4 p1 p2 p3 and p4 on opposite sides of p1p2 (3) Step 2: Does each 2: segment straddle the line containing the other? 33.3 13 source: 91.503 textbook Cormen et al. Segment-Segment Intersection Finding the actual intersection point g p Approach: parametric vs. slope/intercept parametric generalizes to more complex intersections e.g. segment/triangle Parameterize each segment P i h c b a d Lab Lcd c C=dC=d-c Lab b q(t)=c+tC d Lcd A=bA=b-a a p(s)=a+sA Intersection: values of s, t such that p(s) =q(t) : a+sA=c+tC a+sA= 2 equations in unknowns s, t : 1 for x, 1 for y 14 source: O'Rourke, Computational Geometry in C Intersection of >2 Line Segments SweepSweep-Line Algorithmic Paradigm: 33.4 15 source: 91.503 textbook Cormen et al. Intersection of >2 Line Segments SweepSweep-Line Algorithmic Paradigm: 16 source: 91.503 textbook Cormen et al. Intersection of >2 Line Segments Time to detect if any 2 segments intersect:O(n lg n) Balanced BST stores segments in order of intersection with sweep line. Associated operations take O(lgn) time. Note that it exits as soon as one intersection is detected. 33.5 17 source: 91.503 textbook Cormen et al. source: 91.503 textbook Cormen et al. Intersection of Segments Goal: "OutputGoal: "Output-size sensitive" line segment intersection algorithm p g g that computes all intersection points BentleyBentley-Ottmann plane sweep: O((n+k)log(n+k))= O((n+k)logn) time O((n+k)log(n+k))= O((n+k)logn) k = number of intersection points in output Intuition: sweep vertical line rightwards just before intersection, 2 segments are adjacent in sweep-line intersection structure sweepcheck for intersection only adjacent segments y j g insert intersection event into sweep-line structure sweepevent types: top endpoint of a segment bottom endpoint of a segment intersection between 2 segments swap order Improved to O(nlogn+k) [Chazelle/Edelsbrunner] 18 source: O'Rourke, Computational Geometry in C Convex Hull Algorithms g Definitions Gift Wrapping Graham Scan QuickHull Incremental Divide- d Divide and-Conquer Di id -and-C Lower Bound in (nlgn) 19 Convexity & Convex Hulls source: O'Rourke, Computational Geometry in C A convex combination of points x1, ..., xk is a sum of the form 1x1+...+ kxk where i 0 i and 1 + L + k = 1 Convex hull of a set of points is the set of all convex combinations of points in the set. i t i th t nonconvex polygon source: 91.503 textbook Cormen et al. convex hull of a point set 20 Naive Algorithms for Extreme Points Algorithm: Algorithm: INTERIOR POINTS for each i do for each j = i do for each k = j = i do for each L = k = j = i do if pL in triangle(pi, pj, pk) g (p then pL is nonextreme Algorithm: EXTREME EDGES Algorithm: g for each i do for each j = i do for each k = j = i do if pk is not left or on (pi, pj) then (pi , pj) is not extreme O(n4) 21 source: O'Rourke, Computational Geometry in C O(n3) Algorithms: 2D Gift Wrapping Use one extreme edge as an anchor for finding the next g Algorithm: Algorithm: GIFT WRAPPING index of the lowest point i0 i i0 repeat for each j = i Compute counterclockwise angle from previous hull edge k index of point with smallest Output (pi , pk) as a hull edge i k 22 2) until i = i0 O(n source: O'Rourke, Computational Geometry in C Gift Wrapping source: 91.503 textbook Cormen et al. 33.9 Output Sensitivity: O(n2) run-time is actually O(nh) Sensitivity: runwhere h is the number of vertices of the convex hull. 23 Algorithms: 3D Gift Wrapping O(n2) time [output sensitive: O(nF) for F faces on hull] CxHull Animations: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html Animations: 24 Algorithms: 2D QuickHull Concentrate on points close to hull boundary Named f similarity to N d for i il it t Quicksort a b A c finds one of upper or lower hull Algorithm: Algorithm: QUICK HULL function QuickHull(a,b,S) if S = 0 return() else c index of point with max distance from ab A points strictly right of (a c) (a,c) B points strictly right of (c,b) return QuickHull(a,c,A) + (c) + QuickHull(c,b,B) O(n2) 25 source: O'Rourke, Computational Geometry in C Algorithms: 3D QuickHull CxHull Animations: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html Animations: 26 Graham's Algorithm source: O'Rourke, Computational Geometry in C Points sorted angularly provide "star"star-shaped" starting point Prevent "dents" as you go via dents convexity testing p0 Algorithm: Algorithm: GRAHAM SCAN Find rightmost lowest point; label it p0. Sort all other points angularly about p0. In case of tie, delete point(s) closer to p0. Stack S (p1, p0) = (pt, pt-1); t indexes top i 2 while i < n do if pi is strictly left of pt-1pt then Push(pi, S) and set i i +1 else Pop(S) "multipop" O(nlgn) 27 Graham Scan 28 source: 91.503 textbook Cormen et al. Graham Scan 33.7 29 source: 91.503 textbook Cormen et al. Graham Scan 33.7 30 source: 91.503 textbook Cormen et al. Graham Scan pi must be in shaded region, region preserving convexity. pj cannot be on CH(Q CH(Q) 31 source: 91.503 textbook Cormen et al. Graham Scan 32 source: 91.503 textbook Cormen et al. Algorithms: 2D Incremental source: O'Rourke, Computational Geometry in C Add points, one at a time i i update hull for each new point Key step becomes adding a single point to an existing hull. Find 2 tangents g Results of 2 consecutive LEFT tests differ Idea can be extended to 3D. Algorithm: Algorithm: INCREMENTAL ALGORITHM ConvexHull{p0 , p1 , p2 } {p Let H2 for k 3 to n - 1 do ConvexHull{ Hk-1 U pk } Hk O(n2) 33 can be improved to O(nlgn) Algorithms: 3D Incremental O(n2) time CxHull Animations: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html Animations: 34 source: O'Rourke, Computational Geometry in C Algorithms: 2D Divide and Conquer Divide-and-Conquer B Divide-andDivide-and-Conquer in a geometric q g setting O(n) merge step is the challenge Find Fi d upper and l d lower tangents t t Lower tangent: find rightmost pt of A & leftmost pt of B; then "walk it downwards" A Idea Id can be extended to 3D. b t d d t 3D Algorithm: DIVIDE-andAlgorithm: DIVIDE-and-CONQUER Sort points by x coordinate Divide points into 2 sets A and B: A contains left n/2 points B contains right n/2 points t i i ht /2 i t Compute ConvexHull(A) and ConvexHull(B) recursively Merge ConvexHull(A) and ConvexHull(B) O(nlgn) 35 Algorithms: 3D Divide and Conquer O(n log n) time ! CxHull Animations: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html Animations: 36 Combinatorial Size of Convex Hull Convex Hull boundary is intersection of hyperplanes, hyperplanes, so worstworst-case combinatorial size complexity (number of features, not necessarily running time) is in: ( n (n 2d 8 Qhull: http://www.qhull.org/ d / 2 ) 37 Lower Bound of O(nlgn) source: O'Rourke, Computational Geometry in C WorstWorst-case time to find convex hull of n points in algebraic decision tree model is in (nlgn) nlgn) Proof uses sorting reduction: Given unsorted list of n numbers: (x1,x2 ,..., xn) Form unsorted set of points: (xi, xi2) f each xi F t d t f i t ( for h Convex hull of points produces sorted list! list! Parabola: every p y point is on convex hull Reduction is O(n) (which is in o(nlgn)) o(nlgn)) Finding convex hull of n points is therefore at least as hard as sorting n points, so worst-case points worsttime is in (nlgn) nlgn) Parabola for sorting 2,1,3 38 CONVEX LAYERS DEMO Courtesy of David Wolfendale in 91.504, Spring 2010 y , p g For practical motivation behind this problem, please see the following link: http://www.montefiore.ulg.ac.be/~briquet/algo3-chullhttp://www.montefiore.ulg.ac.be/~briquet/algo3-chull-20070206.pdf (e.g. detection of outliers) 39 Nearest Neighbor/ Closest Pair of Points Cl tP i fP i t 40 Closest Pair Goal: Goal: Given n (2D) points in a set Q, find the closest p ( )p , pair under the Euclidean metric in O(n lgn) time. Divide-and-Conquer Strategy: -X = points sorted by increasing x -Y = points sorted by increasing y Divide: -Divide: partition with vertical line L into PL, PR -Conquer: recursively find closest pair in PL, PR L, R are closest-pair distances = min( L, R ) -Combine: closest-pair is either or pair straddles partition line L C bi l t i i ith i t ddl titi li Check for pair straddling partition line L both points must be within of L create array Y' = Y with only points in 2 strip Y for each point p in Y' find (<= 7) points in Y' within of p 41 source: 91.503 textbook Cormen et al. Closest Pair Correctness 33.11 42 source: 91.503 textbook Cormen et al. Closest Pair Running Time: T (n) = 2T (n / 2) + O(n) g O(1) if n > 3 = O(n lg n) if n 3 Key Point: Presort points, then at each step form Point: sorted subset of sorted array in linear time Like opposite of MERGE step in MERGE-SORT... MERGE-SORT... L 43 R source: 91.503 textbook Cormen et al. Additional Computational Geometry Resources Computational Geometry in C, 2nd edition by Joseph O'Rourke Cambridge University Press 1998 Computational Geometry: Algorithms & Applications, 3rd edition by deBerg et al. al. Springer 2008 See also 91.504 Course Web Site (and its additional resources): http://www.cs.uml.edu/~kdaniels/courses/ALG_504.html 44 ...
View Full Document

This note was uploaded on 02/13/2012 for the course CS 91.503 taught by Professor Staff during the Spring '11 term at UMass Lowell.

Ask a homework question - tutors are online