CG Lecture01 CH 6spp
CG Lecture01 CH 6spp
1
Orientation and point classification Possible problems
x1 y1 1 (x1,y1) • Degenerate cases, e.g., 3 collinear
1 points, may harm the correctness of
Area = x2 y2 1
2 + the algorithm. Segments AB, BC and A
x3 y3 1 AC will all be included in the
(x2,y2)
(x3,y3) convex hull. B
make some simplifying assumptions, e.g.: 1. Find the lowest point p1 and its hull edge e p
p4 8
p13
p1
• No three collinear points; 2. For each remaining point pi (i > 2) do p5
p7
p10
• No two points with the same x or y coordinate; • Compute the CCW angle αi from the p6
p2 p2
previous hull edge
• Other configurations: no three points on a circle, …
• Let pj be the point with the smallest αi p1
• Later, we consider the general case: • Make (p1 pi) the new hull edge
• Behavior of algorithm to degenerate cases? Rotate counterclockwise a line through p1
until it touches one of the other points
• Will the correctness be preserved?
• Will the running time remain the same? Time complexity: O(n2)
• Modify/extend algorithm to handle degeneracies In fact, the complexity is O(nh),
9 where n is the input size and h is the hull size. 10
Leo Joskowicz, Spring 2005 Leo Joskowicz, Spring 2005
2
Graham’s scan: complexity analysis Quick hull algorithm a
Algorithm:
• Sorting – O(n log n) • Find four extreme points of P: highest a, lowestc
b, leftmost c, rightmost d. d
• Di = number of points popped on processing pi, • Discard all points in the quadrilateral interior
n n
• Find the hulls of the four triangular regions
time = ∑ ( Di + 1) = n + ∑ Di exterior to the quadrilateral. b
i =1 i =1
• To process triangular regions, find the extreme
• Each point is pushed on the stack only once. point in linear time. Two new exterior regions
• Once a point is popped – it cannot be popped again. A, B will be formed, each processed separately.
• Recurse until no points are left in the exterior:
• Hence the convex hull is the union of the exteriors.
n
∑D ≤ n
i =1
i
Time Complexity:
extreme point c
|B|= β
T(n) = O(n)+T(α)+T(β) where α+β=n–1 |A|= α
a
13 = T(n–1) + O(n) = O(n2) worst case! 14
Leo Joskowicz, Spring 2005 Leo Joskowicz, Spring 2005 b
3
Convex hulls in 3D Convex hull in 3D: properties
z
Theorem: A convex polyhedron with |V| = n vertices
hast at most |E| = 3n–6 edges and |F| = 2n–4 faces.
Proof: from Euler’s formula for planar graphs:
|V| – |E| + |F| = 2
y
Every face has at least 3 edges (triangle)
Every edge is incident to at least 2 faces
Output: Convex hull
x Input: Æ 3|F| ≤ 2|E| Æ |E| ≤ 3n–6 and |F| ≤ 2n–4
• The complexity of the convex hull is O(n).
Points in 3D
• The equality holds when all faces are triangles.
• When no three points are on a line and no four on a
Representation: plane, the faces of the convex hull are all triangles.
Planar subdivision
Leo Joskowicz, Spring 2005
19
Leo Joskowicz, Spring 2005
20
4
Merging two disjoint convex polyhedra Merging two disjoint convex polyhedra
Idea:
Algorithm sketch
1. Identify the merge boundaries of A and B.
1. Find the lowest new edge of the hull formed by one
2. Create new triangular faces with two vertices from the
merge boundary of A and one vertex from the merge vertex a of A and one vertex b of B.
boundary of B (and vice-versa). 2. “Pivot” a plane Π around edge ab to find the first p.
3. Delete hidden faces of A and B. 3. Form a triangular face (abp) and repeat with the new
Remarks: pivot edge formed by p and its opposite (either a or b)
• The “chain” of hidden faces starts and ends at the
merge boundary edges. 4. Repeat step 3 until the wrapping is done.
• The “band” of new faces has the topology of a 5. Delete the hidden faces by following the faces around
cylinder with no caps (it wraps around). A and B whose edges are on the merge boundary.
25 26
Leo Joskowicz, Spring 2005 Leo Joskowicz, Spring 2005
27 28
Leo Joskowicz, Spring 2005 Leo Joskowicz, Spring 2005
5
Divide and Conquer in 3D (end) Incremental convex hull in 3D
Idea: incrementally add a point to a convex polyhedra P
• The number of candidate vertices in each loop iteration
decreases monotonically. Each edge is examined at Two cases:
most twice Æ operation takes O(n). 1. The new point is inside P Æ do nothing
• Divide-and conquer recurrence equation: 2. The new point is outside of P Æ fix P!
⎛n⎞ Membership
T ( n ) = 2T ⎜ ⎟ + O ( n )
⎝2⎠ test is done in
• Theorem: the convex hull of a set of points in space O(n) time.
can be computed in optimal O(n log n) time and O(n)
space. What needs to
Æ Same complexity as 2D problem! be done to add
31
a point? 32
Leo Joskowicz, Spring 2005 Leo Joskowicz, Spring 2005
33 34
Leo Joskowicz, Spring 2005 Leo Joskowicz, Spring 2005
6
Complexity and degeneracies Improvement (1)
• Overall complexity is O(n2). Can we do better? • Look-ahead computation to make it cheaper to find
visible facets.
• Degeneracy: if points can be coplanar, coplanar
• Maintain for each facet f of the current convex hull
triangles will be created. This can be fixed by deleting
CH(Pi) a conflict set:
the shared diagonal, thereby creating a larger face.
Pconflict(f) ⊆ {pi+1,…pn}
containing the points that f can see.
• For each point pj, j>i, maintain the set of facets of CH(Pi)
visible from pj, called Fconflict(pj)
• Point pj is in conflict with a face f because once pj is
added, the face must be deleted from the convex hull.
37 38
Leo Joskowicz, Spring 2005 Leo Joskowicz, Spring 2005
Improvement (2)
• We obtain a bipartite graph,
called the conflict graph G.
• Update the conflict graph
when adding pi:
• Discard neighbors of pi
• Add nodes to G for the newly
created facets and discard pi
• Find conflict list of new facets.
All others remain unaffected!
• Algorithm sketch: add
points p1,…pn sequentially,
using the conflict graph G to Complexity: O(n log n)
determine visible faces.
Leo Joskowicz, Spring 2005
expected randomized 39 Leo Joskowicz, Spring 2005
40