Download presentation
Presentation is loading. Please wait.
1
UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Spring, 2002 Tuesday, 5/7/02 Computational Geometry Chapter 33
2
Relevant Sections of Chapter 35 Ch33 Computational Geometry You’re responsible for material in this chapter that we discuss in lecture. (Note that this includes all sections.)
3
Overview ä Computational Geometry Introduction ä Line Segment Intersection ä Convex Hull Algorithms ä Nearest Neighbors/Closest Points
4
Computational Geometry Telecommunications Visualization & Bioinformatics Manufacturing ComputerGraphics Design Analyze Apply
5
Typical Problems ä bin packing ä Voronoi diagram ä simplifying polygons ä shape similarity ä convex hull ä maintaining line arrangements ä polygon partitioning ä nearest neighbor search ä kd-trees SOURCE: Steve Skiena’s Algorithm Design Manual (for problem descriptions, see graphics gallery at ) (for problem descriptions, see graphics gallery at http://www.cs.sunysb.edu/~algorith)
6
Common Computational Geometry Structures Voronoi Diagram Delaunay Triangulation Convex Hull New Point source: O’Rourke, Computational Geometry in C
7
Sample Tools of the Trade Algorithm Design Patterns/Techniques: binary searchdivide-and-conquerduality randomizationsweep-line derandomizationparallelism Algorithm Analysis Techniques: asymptotic analysis, amortized analysis Data Structures: winged-edge, quad-edge, range tree, kd-tree Theoretical Computer Science principles: NP-completeness, hardness Growth of Functions Summations Recurrences Sets Probability MATH Proofs Geometry Graph Theory Combinatorics Linear Algebra
8
Computational Geometry in Context TheoreticalComputerScience Applied Computer Science AppliedMath Geometry ComputationalGeometryEfficient Geometric Algorithms Design Analyze Apply
9
Line Segment Intersections (2D) Intersection of 2 Line Segments Intersection of > 2Line Segments
10
Cross-Product-Based Geometric Primitives source: 91.503 textbook Cormen et al. p0p0p0p0 p2p2p2p2 p1p1p1p1 (1) p1p1p1p1 p3p3p3p3 p2p2p2p2 (2) p2p2p2p2 p1p1p1p1 p3p3p3p3 p4p4p4p4 (3) Some fundamental geometric questions:
11
Cross-Product-Based Geometric Primitives: (1) source: 91.503 textbook Cormen et al. Advantage: less sensitive to accumulated round-off error p0p0p0p0 p2p2p2p2 p1p1p1p1 (1) 33.1
12
Cross-Product-Based Geometric Primitives: (2) source: 91.503 textbook Cormen et al. p1p1p1p1 p3p3p3p3 p2p2p2p2 (2) 33.2
13
Intersection of 2 Line Segments source: 91.503 textbook Cormen et al. p2p2p2p2 p1p1p1p1 p3p3p3p3 p4p4p4p4 (3) Step 1: Bounding Box Test Step 2: Does each segment straddle the line containing the other? 33.3
14
Segment-Segment Intersection ä Finding the actual intersection point ä Approach: parametric vs. slope/intercept ä parametric generalizes to more complex intersections ä Parameterize each segment a b c d L ab L cd a b c d L ab L cd A=b-a p(s)=a+sA Intersection: values of s, t such that p(s) =q(t) : a+sA=c+tC q(t)=c+tC C=d-c 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 source: 91.503 textbook Cormen et al. Sweep-Line Algorithmic Paradigm: 33.4
17
Intersection of >2 Line Segments source: 91.503 textbook Cormen et al. Sweep-Line Algorithmic Paradigm:
18
Intersection of >2 Line Segments source: 91.503 textbook Cormen et al. O(n lg n) Time to detect if any 2 segments intersect: source: 91.503 textbook Cormen et al. 33.5
19
Intersection of Segments ä Goal: “Output-size sensitive” line segment intersection algorithm that actually computes 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 QuickHullIncrementalDivide-and-Conquer Lower Bound in (nlgn)
21
Convexity & Convex Hulls A convex combination of points x 1,..., x k is a sum of the form 1 x 1 +...+ k x k where ä Convex hull of a set of points is the set of all convex combinations of points in the set. nonconvex polygon convex hull of a point set source: O’Rourke, Computational Geometry in C source: 91.503 textbook Cormen et al.
22
Naive Algorithms for Extreme Points Algorithm: INTERIOR POINTS for each i do for each j = i do for each j = i do for each k = j = i do for each k = j = i do for each L = k = j = i do for each L = k = j = i do if p L in triangle(p i, p j, p k ) then p L is nonextreme O(n 4 ) Algorithm: EXTREME EDGES for each i do for each j = i do for each j = i do for each k = j = i do for each k = j = i do if p k is not left or on (p i, p j ) if p k is not left or on (p i, p j ) then (p i, p j ) is not extreme O(n 3 ) source: O’Rourke, Computational Geometry in C
23
Algorithms: 2D Gift Wrapping ä Use one extreme edge as an anchor for finding the next O(n 2 ) Algorithm: GIFT WRAPPING i 0 index of the lowest point i i 0 repeat for each j = i for each j = i Compute counterclockwise angle from previous hull edge Compute counterclockwise angle from previous hull edge k index of point with smallest k index of point with smallest Output (p i, p k ) as a hull edge Output (p i, p k ) as a hull edge i k i k until i = i 0 source: O’Rourke, Computational Geometry in C
24
Gift Wrapping source: 91.503 textbook Cormen et al. 33.9
25
Algorithms: 3D Gift Wrapping CxHull Animations: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html O(n 2 ) time [output sensitive: O(nF) for F faces on hull]
26
Algorithms: 2D QuickHull ä Concentrate on points close to hull boundary ä Named for similarity to Quicksort a b O(n 2 ) Algorithm: QUICK HULL function QuickHull(a,b,S) if S = 0 return() if S = 0 return() else else c index of point with max distance from ab c index of point with max distance from ab A points strictly right of (a,c) A points strictly right of (a,c) B points strictly right of (c,b) B points strictly right of (c,b) return QuickHull(a,c,A) + (c) + QuickHull(c,b,B) return QuickHull(a,c,A) + (c) + QuickHull(c,b,B) 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
Graham’s Algorithm ä Points sorted angularly provide “star-shaped” starting point ä Prevent “dents” as you go via convexity testing O(nlgn) Algorithm: GRAHAM SCAN, Version B Find rightmost lowest point; label it p 0. Sort all other points angularly about p 0. In case of tie, delete point(s) closer to p 0. In case of tie, delete point(s) closer to p 0. Stack S (p 1, p 0 ) = (p t, p t-1 ); t indexes top i 2 while i < n do if p i is strictly left of p t-1 p t then Push(p i, S) and set i i +1 else Pop(S) source: O’Rourke, Computational Geometry in C
30
Graham Scan source: 91.503 textbook Cormen et al.
31
Graham Scan source: 91.503 textbook Cormen et al. 33.7
32
Graham Scan source: 91.503 textbook Cormen et al. 33.7
33
Graham Scan source: 91.503 textbook Cormen et al.
34
Graham Scan source: 91.503 textbook Cormen et al.
35
Algorithms: 2D Incremental ä Add points, one at a time ä update hull for each new point ä Key step becomes adding a single point to an existing hull. ä Idea is extended to 3D in Chapter 4. O(n 2 ) Algorithm: INCREMENTAL ALGORITHM Let H 2 ConvexHull{p 0, p 1, p 2 } for k 3 to n - 1 do H k ConvexHull{ H k-1 U p k } H k ConvexHull{ H k-1 U p k } can be improved to O(nlgn) source: O’Rourke, Computational Geometry in C
36
Algorithms: 3D Incremental CxHull Animations: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html O(n 2 ) time
37
Algorithms: 2D Divide-and-Conquer ä 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 is extended to 3D in Chapter 4. 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) A B source: O’Rourke, Computational Geometry in C
38
Algorithms: 3D Divide and Conquer CxHull Animations: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html O(n log n) time !
39
Lower Bound of O(nlgn) Worst-case time to find convex hull of n points in algebraic decision tree model is in (nlgn) ä Proof uses sorting reduction: ä Given unsorted list of n numbers: (x 1,x 2,…, x n ) ä Form unsorted set of points: (x i, x i 2 ) for each x i ä 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 (nlgn) Parabola for sorting 2,1,3 source: O’Rourke, Computational Geometry in C
40
Nearest Neighbor/ Closest Pair of Points
41
Closest Pair source: 91.503 textbook Cormen et al. 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 P L, P R - -Conquer: recursively find closest pair in P L, P R - - L, R are closest-pair distances - - min( L, R ) - -Combine: closest-pair is either or pair straddles partition line L - - Check for pair straddling partition line L - - both points must be within of L - - create array Y’ = Y without points in 2 strip - - for each point p in Y’ - - find (<= 7) points in Y’ within of p
42
Closest Pair source: 91.503 textbook Cormen et al. Correctness 33.11
43
Closest Pair source: 91.503 textbook Cormen et al. Running Time: Key Point: Presort points, then at each step form sorted subset of sorted array in linear time
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.