ORourkeCH4 - Computer Science

advertisement
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
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

2D faces
polyhedra
disjoint or have vertex in common or have vertex/edge/vertex in common
Local topology is “proper”


1D edges
Components intersect “properly.” Each face pair:


vertices
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)
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 polyhedron1 is 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.
- What is wrong with this definition?
- Find an example of an object that is a
polyhedron1 but is not a polyhedron.
polyhedra and
polyhedra1?
not polyhedra
and not
polyhedra1?
Polyhedra: Regular Polytopes
source: O’Rourke, Computational Geometry in C
Convex polyhedra are polytopes
 Regular polyhedra are polytopes that have:

 regular

p
3
4
3
5
3
v
3
3
4
3
5
faces, = faces, = solid (dihedral) angles
There are exactly 5 regular polytopes
(p-2)(v-2)
1
2
2
3
3
Name
Tetrahedron
Cube
Octahedron
Dodecahedron
Icosahedron
Description
3 triangles at each vertex
3 squares at each vertex
4 triangles at each vertex
3 pentagons at each vertex
5 triangles at each vertex
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)
V-E+F=2
Proof has 3 parts:
1) Convert polyhedron surface to planar graph
2) Tree theorem
3) Proof by induction
Polyhedra: Euler’s Formula
sources: O’Rourke, Computational Geometry in C
for genus 0 (no holes)
V-E+F=2
•
•
Euler’s formula implies V, E, F are related.
Relationship is LINEAR!
•
•
If V = n, then E  O (n) F  O (n)
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)
Polyhedral Boundary
Representations
v7
e1+
f0
e0-
v1
v2
e1f1
e
v3
f0 e
e0+
e4,0
v0
winged edge
- focus is on edge
- edge orientation is arbitrary
source: O’Rourke, Computational Geometry in C
* see also deBerg et al. for DCEL description
v1
e’s f
1
twin
v6
e0,1
v0
v5
v4
twin edge
[DCEL: doubly connected edge list*]
- 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
Polyhedral Boundary
Representations: Quad-Edge
e7,1
v2 e1,0 v1
e2,0
v3
f0 e0,0
e3,0
v4
v7
e7,1
e4,0
e6,1
e1,1 f1
v0 e
0,1
v6
e5,1
v5
twin edge
[DCEL: doubly connected edge list]
source: O’Rourke, Computational Geometry in C
e6,1
v6
v1
e1,0
v2
v7
f1
e5,1
e0,0 e1,1
e2,0
f0
v3
v5
v0
e3,0
v4
e4,0
e0,1
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
Algorithms: 2D Gift Wrapping
source: O’Rourke, Computational Geometry in C

Use one extreme edge as an
anchor for finding the next
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: 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”
B
A
Idea is extended to 3D in Chapter 4.
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
Algorithms: 2D QuickHull
source: O’Rourke, Computational Geometry in C


Concentrate on points close to
hull boundary
Named for similarity to
Quicksort
a
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)
b
O(n2)
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)

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.
p
 Construct new hull using cone
Q
 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-1 do
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
ReadVertices
MakeNullVertex
DoubleTriangle
Print
ConstructHull
AddOne
Collinear MakeFace
MakeConeFace
VolumeSign
Cleanup
MakeCcw CleanEdges
CleanFaces
MakeNullEdge
MakeNullFace
CleanVertices
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

Complementary
sets of
information:


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 p i:

If point sees a face, it must have been able to see one or both faces adjacent to e on H i-1
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.



points not
yet inserted
facets of
current 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 preexisting 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.
*Not the same as motion planning configuration space!
Conflict graph G
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)
in:
2 d 8
complexity is
(n
d / 2 
)
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
P  T C
frequent problem in graphics
What is the largest number of vertices P
can have for any triangle?
C
T
Download