260 likes | 503 Views
UMass Lowell Computer Science 91.504 Advanced Algorithms Computational Geometry Prof. Karen Daniels Spring, 2010. O’Rourke Chapter 4: 3D Convex Hulls Thursday, 2/18/10. Chapter 4 3D Convex Hulls. Polyhedra Algorithms Implementation Polyhedral Boundary Representations
E N D
UMass Lowell Computer Science 91.504Advanced AlgorithmsComputational GeometryProf. Karen DanielsSpring, 2010 O’Rourke Chapter 4: 3D Convex Hulls Thursday, 2/18/10
Chapter 43D Convex Hulls Polyhedra Algorithms Implementation Polyhedral Boundary Representations Randomized Incremental Algorithm Higher Dimensions
Polyhedra: What are they? source: O’Rourke, Computational Geometry in C • Polyhedron generalizes 2D polygon to 3D • Consists of flat polygonal faces • Boundary/surface contains • 0D vertices 1D edges 2D faces • Components intersect “properly.” Each face pair: • disjoint or have vertex in common or have vertex/edge/vertex in common • Local topology is “proper” • at every point neighborhood is homeomorphic to disk • Global topology is “proper” • connected, closed, bounded • may have holes (by default no holes in our work) polyhedra not polyhedra! for more examples, see http://www.ScienceU.com/geometry/facts/solids/handson.html
Polyhedra: A Flawed Definition source: O’Rourke, Computational Geometry in C • Definition of Polyhedron1 • A polyhedron1is a region of space bounded by a finite set of polygons such that: • every polygon shares at least one edge with some other polygon • every edge is shared by exactly two polygons. polyhedra and polyhedra1? not polyhedra and not polyhedra1? - What is wrong with this definition? - Find an example of an object that is a polyhedron1 but is not a polyhedron.
Polyhedra: Regular Polytopes source: O’Rourke, Computational Geometry in C • Convex polyhedra are polytopes • Regular polyhedra are polytopes that have: • regular faces, = faces, = solid (dihedral) angles • There are exactly 5 regular polytopes dodecahedron icosahedron Excellent math references by H.S.M. Coxeter: - Introduction to Geometry (2nd edition), Wiley &Sons, 1969 - Regular Polytopes, Dover Publications, 1973
Polyhedra: Euler’s Formula sources: O’Rourke, Computational Geometry in C & Figure from de Berg et al. Ch 11. for genus 0 (no holes) Proof has 3 parts: 1) Convert polyhedron surface to planar graph 2) Tree theorem 3) Proof by induction V - E + F = 2
Polyhedra: Euler’s Formula sources: O’Rourke, Computational Geometry in C for genus 0 (no holes) • Euler’s formula implies V, E, F are related. • Relationship is LINEAR! • If V = n, then • Proof Sketch: • Assume polytope is simplicial: all faces triangles • Each face has 3 edges (E = 3F) • But double-counted shared edges, so E = 3F/2 implying F = 2E/3 • Substitute F = 2E/3 into Euler’s formula • V – 2 = E/3 implies E = 3V – 6 < 3V = 3n in O(n) • F = 2E/3 = 2V – 4 < 2V = 2n in O(n) V - E + F = 2
Polyhedral Boundary Representations v7 v2 v1 e1- v1 e’s twin e1+ f1 f1 v3 e v6 e f0 e0,1 f0 e0+ v5 e4,0 v0 v0 e0- v4 twin edge [DCEL: doubly connected edge list*] winged edge • represent edge as 2 halves • lists: vertex, face, edge/twin • more storage space • facilitates face traversal • can represent holes with face inner/outer edge pointer • focus is on edge • edge orientation is arbitrary source: O’Rourke, Computational Geometry in C * see also deBerg et al. for DCEL description
v7 e7,1 e0,1 v2 e1,0 v1 e6,1 e2,0 e3,0 f1 e5,1 e1,1 v3 v6 e0,0 e6,1 f0 e5,1 e3,0 e1,0 v5 v0 e0,1 e7,1 e4,0 v4 e2,0 e4,0 twin edge [DCEL: doubly connected edge list] Polyhedral Boundary Representations: Quad-Edge v7 v6 v1 f1 v2 e1,1 e0,0 f0 v5 v3 v0 v4 unbounded face • general: subdivision of oriented 2D manifold • edge record is part of: • endpoint 1 list • endpoint 2 list • face A list • face B list source: O’Rourke, Computational Geometry in C
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 source: O’Rourke, Computational Geometry in C • Use one extreme edge as an anchor for finding the next
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
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 is extended to 3D in Chapter 4. B A Algorithm: 2D 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)
Algorithms:3D Divide and Conquer O(n log n) time ! CxHull Animations: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html
Algorithms:3D Divide and Conquer • Hard work is in MERGE of A with B: O(n) • Add single “band” of faces with topology of cylinder without caps • Each face uses at least 1 edge from A or B • # faces <= # edges so O(n) faces • Each face added in O(1) amortized time: • Lemma: When plane p is rotated about line through ab, first point c to be hit is a vertex adjacent to either a or b. • Point c can be found in O(1) amortized time using aggregate analysis. • Finding it might require examining W(n) neighbors, but monotonicity of counterclockwise search helps. • Each edge is “charged”/examined at most twice (once from each endpoint). • Discarding Hidden Faces: • Wrapping discovers “shadow boundary” edges, but don’t necessarily form simple cycle (see example on p. 113 Fig. 4.7). • Hidden faces do form a connected cap: use e.g. DFS from shadow boundary. source: O’Rourke, Computational Geometry in C
a b Algorithm: 2D 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 source: O’Rourke, Computational Geometry in C • Concentrate on points close to hull boundary • Named for similarity to Quicksort
Algorithms: 3D QuickHull CxHull Animations: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html
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 is extended to 3D in Chapter 4. Algorithm: 2D 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)
p Q Algorithms: 3D Incremental source: O’Rourke, Computational Geometry in C • Add points, one at a time • Update hull Q for each new point p • Case 1: p is in existing hull Q • Must be on positive side of every plane determined by a face of Q. • Left-of test uses volume of tetrahedron (board work) • # faces in O(n) due to Euler, so test takes only O(n) time. • Discard p if it is inside existing hull. • Case 2: p is not in existing hull Q • Compute cone tangent to Q whose apex is p. • Cone consists of triangular tangent faces. • Base of each is an edge of Q. • Construct new hull using cone • Discard faces that are not visible.
Algorithms: 3D Incremental source: O’Rourke, Computational Geometry in C Algorithm: 3D INCREMENTAL ALGORITHM Let H3 ConvexHull{ p0 , p1 , p2, p3 } = tetrahedron for i 4 to n - 1 do for each face f of Hi-1 do compute signed volume of tetrahedron* determined by f and pi mark f visible iff signed volume < 0 if no faces are visible then Discard pi(it is inside Hi-1) else for each border edge e of Hi-1do Construct cone face determined by e and pi for each visible face f do Delete f Update Hi *Use determinant of a matrix. O(n2) Randomized incremental has expected O(nlgn) time.
Algorithms: 3D Incremental source: O’Rourke, Computational Geometry in C Calling Diagram for O’Rourke’s C Implementation of 3D Incremental Algorithm Main Print ReadVertices ConstructHull DoubleTriangle AddOne Cleanup MakeConeFace MakeNullVertex Collinear MakeFace VolumeSign MakeCcw CleanEdges CleanFaces CleanVertices MakeNullEdge MakeNullFace
Algorithms: 3D Incremental O(n2) time CxHull Animations: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html
Algorithms: 3D Randomized Incremental source: O’Rourke, Computational Geometry in C • Clarkson, Shor (1989) • O(nlgn) expected time • Variant of 3D incremental algorithm • Avoid brute-force visible face test • Maintain CONFLICT GRAPH • For each face of Hi-1record which not-yet-added points can see it • For each not-yet-added point, record which faces it can see (those it is “in conflict” with) • Key observation allowing fast adding of face = CH(e,pi), where e is a polytope edge on border between faces visible and invisible from pi: • If point sees a face, it must have been able to see one or both faces adjacent to e on Hi-1 Complementary sets of information:
Algorithms: 3D Randomized Incremental • More detail is found in de Berg et al. Ch 11: Section 11.2-11.3 • Bipartite conflict graph • When point and face cannot coexist in the convex hull. • Once point p in Pconflict( f ) is added to convex hull, facet f must be removed; they conflict. • Initialize in linear time for convex hull of first tetrahedron. • Conflict list of a new facet f: test points in conflict lists of two facets f1 and f2 incident to “horizon” (“shadow”) edge e in pre-existing convex hull. • Need to bound cardinality of conflict lists to analyze this…see subtle analysis of Section 11.3, which uses elegant notion of configuration space* framework for a generic randomized incremental algorithm from Section 9.5. facets of current hull points not yet inserted Conflict graph G *Not the same as motion planning configuration space!
Algorithms: 3D Randomized Incremental • Pseudocode from de Berg et al. Ch 11: Conflict graph G
Combinatorial Size of Convex Hull Convex Hull boundary is intersection of hyperplanes, so worst-case combinatorial size (number of features)(not necessarily running time) complexity is in: Qhull: http://www.qhull.org
3D Visibility source: O’Rourke, Computational Geometry in C • To build our 3D visibility intuition (homework): • T = planar triangle in 3D • C = closed region bounded by a 3D cube frequent problem in graphics C T What is the largest number of vertices P can have for any triangle?