160 likes | 277 Views
Convex Hulls. Computational Geometry, WS 2006/07 Lecture 2 Prof. Dr. Thomas Ottmann. Algorithmen & Datenstrukturen, Institut für Informatik Fakultät für Angewandte Wissenschaften Albert-Ludwigs-Universität Freiburg. Overview. Computing the convex hull The Naïve approach Graham Scan
E N D
Convex Hulls Computational Geometry, WS 2006/07 Lecture 2 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät für Angewandte Wissenschaften Albert-Ludwigs-Universität Freiburg
Overview • Computing the convex hull • The Naïve approach • Graham Scan • Lower bound • Design, analysis, implementation Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann
p p pq pq q q Convex Hulls • Subset of S of the plane is convex, if for all pairs p,q in Sthe line segment pq is completely contained in S. • The Convex HullCH(S) is the smallest convex set, which contains S. Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann
Convex Hull of a Set of Points in the Plane • The convex hull of a set P of points is the unique convex polygon whose vertices are points of P and which contains all points from P. Rubber band experiment Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann
Polygons • A polygon P is a closed, connected sequence of line segments. • A polygon is simple, if it does not intersect itself. • A simple polygon is convex, if the enclosed area is convex. Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann
q p Computing the Convex Hull • Right rule: The line segment pq is part of the CH(P) iff all points of P-{p,q} lie to the right of the line through p and q. Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann
E= • for all (p, q) from PxP with p q • valid = true • for all r in P with r p and rq • if r lies to the left of the directed line from p to q • valid = false • if valid then for E = E { pq } • Construct CH(P) as a list of nodes fromE • Run time: O(n³) Naïve Procedure Input: A set Pof points in the plane Output: Convex Hull CH(P) Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann
Degenerate Cases 1. Linear dependency: more points are on a line. Solution: extended definition by cases. 2. Rounding errors due computer arithmetic (floats). Solution: symbolic computation, interval arithmetic. Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann
Incremental approach: Given: Upper hull for p1,...,pi-1 Compute: Upper hull for p1,...,pi An Incremental Algorithm Upper Hull Partitioning of the problem: Lower Hull z X s X X Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann
Computation of UH (Graham Scan) Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann
Fast Computation of the Convex Hull Input/output:see " naive procedure " Sort Paccording to x-Coordinates LU={p1, p2 } fori = 3 to n LU = LU { pi } while LU contains more than 2 points and the last 3 points in LU do not make a right turn do delete the middle of last 3 points LL={pn, pn-1 } fori = n-2 to 1 LL = LL { pi } whileLL contains more than 2 points and the last 3 points in LL do not make a right turn do delete the middle of last 3 points delete first and last point in LL CH(P) = LU LL Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann
Runtime Theorem: The fast algorithm for computing the convex hull (Graham Scan) can be carried out in time O(n log n). Proof: (for UH only) Sorting n points in lexicographic order takes time O(n log n). Execution of the for-loop takes time O(n). Total number of deletions carried out in all executions of the while loop takes time O(n). Total runtime for computing UH is O(n log n) Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann
pi+1 V pi Correctness • Proof: for Upper Hull by induction: • {p1, p2 } is a correct UH for a set of 2 points. • Assume: { p1,...,pi } is a correct UH for i points and consider pi+1 By induction a too high point may lie only in the slab V. This, however, contradicts the lexicographical order of points! Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann
x1 x2 ... xn Lower Bound Reduction of the sorting problem to the computation of the convex hull. 1.x1, ... ,xn (x1, x1²), ... ,(xn,,xn²)O(n) 2. Construct the convex hull for these points 3. Output the points in (counter-)clockwise order Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann
1. Design the algorithm and ignore all special cases. 2. Handle all special cases and degeneracies. 3. Implementation: Computing geometrical objects: best possibleDecisions (e.g. comparison operations): suppose exact (correct) results Support: Libraries:LEDA, CGAL Visualizations:VEGA Design, Analysis & Implementation Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann