1 / 43

UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002. Tuesday, 11/5/02 Computational Geometry Chapter 33. Relevant Sections of Chapter 33.

Download Presentation

UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. UMass Lowell Computer Science 91.503Analysis of AlgorithmsProf. Karen DanielsFall, 2002 Tuesday, 11/5/02 Computational Geometry Chapter 33

  2. Relevant Sections of Chapter 33 You’re responsible for material in this chapter that we discuss in lecture. (Note that this includes all sections.) Ch33 Computational Geometry

  3. Overview • Computational Geometry Introduction • Line Segment Intersection • Convex Hull Algorithms • Nearest Neighbors/Closest Points

  4. Manufacturing Computational Geometry Computer Graphics Visualization & Bioinformatics Design Analyze Core Geometric Algorithms Application-Based Algorithms Apply Telecommunications

  5. Typical Problems • maintaining line arrangements • polygon partitioning • nearest neighbor search • kd-trees • bin packing • Voronoi diagram • simplifying polygons • shape similarity • convex hull SOURCE: Steve Skiena’s Algorithm Design Manual (for problem descriptions, see graphics gallery at http://www.cs.sunysb.edu/~algorith)

  6. Convex Hull Voronoi Diagram New Point Delaunay Triangulation Common Computational Geometry Structures source: O’Rourke, Computational Geometry in C

  7. Sample Tools of the Trade Algorithm Design Patterns/Techniques: binary search divide-and-conquer duality randomizationsweep-line derandomizationparallelism Algorithm Analysis Techniques: asymptotic analysis, amortized analysis Data Structures: winged-edge, quad-edge, range tree, kd-tree Theoretical Computer Scienceprinciples: NP-completeness, hardness MATH Sets Proofs Geometry Summations Linear Algebra Probability Growth of Functions Recurrences Graph Theory Combinatorics

  8. Geometry Theoretical Computer Science Applied Math Computational Geometry Efficient Geometric Algorithms Design Analyze Applied Computer Science Apply Computational Geometryin Context

  9. Line Segment Intersections(2D) Intersection of 2 Line Segments Intersection of > 2Line Segments

  10. p2 p2 p3 p2 p4 p1 p2 p1 p0 p0 (2) (3) Cross-Product-Based Geometric Primitives Some fundamental geometric questions: source: 91.503 textbook Cormen et al. (1)

  11. p2 p1 p0 (1) Cross-Product-Based Geometric Primitives: (1) 33.1 Advantage: less sensitive to accumulated round-off error source: 91.503 textbook Cormen et al.

  12. p2 p1 p0 (2) Cross-Product-Based Geometric Primitives: (2) 33.2 source: 91.503 textbook Cormen et al.

  13. p3 p2 p4 p1 (3) Intersection of 2 Line Segments Step 1: Bounding Box Test p3 and p4 on opposite sides of p1p2 33.3 Step 2: Does each segment straddle the line containing the other? source: 91.503 textbook Cormen et al.

  14. Lab c Lcd b d a Segment-Segment Intersection • Finding the actual intersection point • Approach: parametric vs. slope/intercept • parametric generalizes to more complex intersections • Parameterize each segment Lab c Lcd C=d-c b q(t)=c+tC d A=b-a a p(s)=a+sA Intersection: values of s, t such that p(s) =q(t) : a+sA=c+tC source: O’Rourke, Computational Geometry in C

  15. Demo Segment/Segment Intersection http:/cs.smith.edu/~orourke/books/CompGeom/CompGeom.html

  16. Intersection of >2 Line Segments Sweep-Line Algorithmic Paradigm: 33.4 source: 91.503 textbook Cormen et al.

  17. Intersection of >2 Line Segments Sweep-Line Algorithmic Paradigm: source: 91.503 textbook Cormen et al.

  18. Intersection of >2 Line Segments Time to detectif any 2 segments intersect: O(n lg n) Note that it exits as soon as one intersection is detected. 33.5 source: 91.503 textbook Cormen et al. source: 91.503 textbook Cormen et al.

  19. Intersection of Segments • Goal: “Output-size sensitive” line segment intersection algorithm that actually computes all intersection points • Bentley-Ottmann plane sweep: O((n+k)logn) time • k = number of intersection points in output • Intuition: sweep horizontal line downwards • just before intersection, 2 segments are adjacent in sweep-line intersection structure • check for intersection only segments that adjacent • event types: • top endpoint of a segment • bottom endpoint of a segment • intersection between 2 segments Improved to O(nlogn+k) [Chazelle/Edelsbrunner] source: O’Rourke, Computational Geometry in C

  20. Convex Hull Algorithms Definitions Gift Wrapping Graham Scan QuickHull Incremental Divide-and-Conquer Lower Bound in W(nlgn)

  21. nonconvex polygon convex hull of a point set Convexity & Convex Hulls source: O’Rourke, Computational Geometry in C • A convex combination of points x1, ..., xk is a sum of the form a1x1+...+ akxk where • Convex hull of a set of points is the set of all convex combinations of points in the set. source: 91.503 textbook Cormen et al.

  22. 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) then pL is nonextreme Algorithm: EXTREME EDGES 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(n3) Naive Algorithms for Extreme Points O(n4) source: O’Rourke, Computational Geometry in C

  23. q Algorithm: GIFT WRAPPING i0 index of the lowest point i i0 repeat for each j = i Compute counterclockwise angle q from previous hull edge k index of point with smallest q Output (pi , pk) as a hull edge i k until i = i0 O(n2) Algorithms: 2D Gift Wrapping • Use one extreme edge as an anchor for finding the next source: O’Rourke, Computational Geometry in C

  24. Gift Wrapping 33.9 source: 91.503 textbook Cormen et al.

  25. 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

  26. a b 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) B points strictly right of (c,b) return QuickHull(a,c,A) + (c) + QuickHull(c,b,B) O(n2) Algorithms: 2D QuickHull • Concentrate on points close to hull boundary • Named for similarity to Quicksort finds one of upper or lower hull source: O’Rourke, Computational Geometry in C

  27. Algorithms: 3D QuickHull CxHull Animations: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html

  28. Algorithms: Qhull (>= 2D ) http://www.geom.umn.edu/software/qhull/

  29. Algorithm: GRAHAM SCAN, Version B 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) q O(nlgn) Graham’s Algorithm source: O’Rourke, Computational Geometry in C • Points sorted angularly provide “star-shaped” starting point • Prevent “dents” as you go via convexity testing “multipop”

  30. Graham Scan source: 91.503 textbook Cormen et al.

  31. Graham Scan 33.7 source: 91.503 textbook Cormen et al.

  32. Graham Scan 33.7 source: 91.503 textbook Cormen et al.

  33. Graham Scan source: 91.503 textbook Cormen et al.

  34. Graham Scan source: 91.503 textbook Cormen et al.

  35. Algorithms: 2D Incremental source: O’Rourke, Computational Geometry in C • Add points, one at a time • update hull for each new point • Key step becomes adding a single point to an existing hull. • Idea can be extended to 3D. Algorithm: INCREMENTAL ALGORITHM Let H2 ConvexHull{p0 , p1 , p2 } for k 3 to n - 1 do Hk ConvexHull{ Hk-1 U pk } O(n2) can be improved to O(nlgn)

  36. Algorithms: 3D Incremental O(n2) time CxHull Animations: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html

  37. Algorithms:2D Divide-and-Conquer source: O’Rourke, Computational Geometry in C • Divide-and-Conquer in a geometric setting • O(n) merge step is the challenge • Find upper and lower tangents • Lower tangent: find rightmost pt of A & leftmost pt of B; then “walk it downwards” • Idea can be extended to 3D. B A Algorithm: 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 Compute ConvexHull(A) and ConvexHull(B) recursively Merge ConvexHull(A) and ConvexHull(B) O(nlgn)

  38. Algorithms:3D Divide and Conquer O(n log n) time ! CxHull Animations: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html

  39. Lower Bound of O(nlgn) source: O’Rourke, Computational Geometry in C • Worst-case time to find convex hull of n points in algebraic decision tree model is in W(nlgn) • Proof uses sorting reduction: • Given unsorted list of n numbers: (x1,x2 ,…, xn) • Form unsorted set of points: (xi, xi2) for each xi • Convex hull of points produces sorted list! • Parabola: every point is on convex hull • Reduction is O(n) (which is o(nlgn)) • Finding convex hull of n points is therefore at least as hard as sorting n points, so worst-case time is in W(nlgn) Parabola for sorting 2,1,3

  40. Nearest Neighbor/Closest Pair of Points

  41. Closest Pair Goal: Given n (2D) points in a set Q, find the closest 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: partition with vertical line L into PL, PR • Conquer: recursively find closest pair in PL, PR • dL, dR are closest-pair distances • d = min(dL, dR ) • Combine: closest-pair is either d or pair straddles partition line L • Check for pair straddling partition line L • both points must be within d of L • create array Y’ = Y with only points in 2d strip • for each point p in Y’ • find (<= 7) points in Y’ within d of p source: 91.503 textbook Cormen et al.

  42. Closest Pair Correctness 33.11 source: 91.503 textbook Cormen et al.

  43. Closest Pair Running Time: Key Point: Presort points, then at each step form sorted subset of sorted array in linear time Like opposite of MERGE step in MERGESORT… source: 91.503 textbook Cormen et al.

More Related