convex hulls in 3d - start page at  · 2018. 12. 10. · computing a convex hull in 3d •...

8
D7013E Computational Geometry - Håkan Jonsson 1 D7013E Lecture 11 Convex Hulls in Higher Dimensions 3D Voronoi diagrams Incremental Algorithm D7013E Computational Geometry - Håkan Jonsson 2 Convex Hulls in 3D Collision detection: D7013E Computational Geometry - Håkan Jonsson 3 Definitions The smallest volume polyhedral that contains a set of points in 3D. – Facets – Edges – Vertices Generalizes to higher dimensions. D7013E Computational Geometry - Håkan Jonsson 4 Size Theorem 11.1 + Corollary 11.2: A convex hull of n points in 3D has at most n vertices (of course), 3n-6 edges, and 2n-4 facets. It is ”planar”. Euler’s formula.

Upload: others

Post on 09-Sep-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Convex Hulls in 3D - Start page at  · 2018. 12. 10. · Computing a Convex Hull in 3D • Incremental Algorithm – Add points one at a time and maintain a current convex hull. –

D7013E Computational Geometry - Håkan Jonsson 1

D7013ELecture 11

Convex Hulls inHigher Dimensions

3DVoronoi diagrams Incremental

Algorithm

D7013E Computational Geometry - Håkan Jonsson 2

Convex Hulls in 3D

•  Collision detection:

D7013E Computational Geometry - Håkan Jonsson 3

Definitions

•  The smallest volume polyhedral that contains a set of points in 3D. –  Facets –  Edges –  Vertices

•  Generalizes to higher dimensions.

D7013E Computational Geometry - Håkan Jonsson 4

Size

•  Theorem 11.1 + Corollary 11.2: –  A convex hull of n points in 3D has at most

•  n vertices (of course), •  3n-6 edges, and •  2n-4 facets.

–  It is ”planar”. –  Euler’s formula.

Page 2: Convex Hulls in 3D - Start page at  · 2018. 12. 10. · Computing a Convex Hull in 3D • Incremental Algorithm – Add points one at a time and maintain a current convex hull. –

Computing a Convex Hull in 3D •  Incremental Algorithm

–  Add points one at a time and maintain a current convex hull.

–  Use DCEL:s to represent the convex hull.

•  Start with four (4) input points that form a pyramid.

–  Should these and all other points lie in the same plane, compute a 2D convex hull as in Chapter 1!

–  O(n log n) time. •  Then

–  add new facets for each point considered that lie outside the current hull.

•  Delete old facets that end up inside.

D7013E Computational Geometry - Håkan Jonsson 5 D7013E Computational Geometry - Håkan Jonsson 6

Horizon

D7013E Computational Geometry - Håkan Jonsson 7

Adding One Point Finding a horizon •  The horizon can be

found by traversing the current convex hull. –  Each edge of the

horizon bounds two faces of which just one is visible from pr.

•  Visible: •  If a face is visible to pr

they are in conflict. –  The face has to go when

we consider pr.

D7013E Computational Geometry - Håkan Jonsson 8

Page 3: Convex Hulls in 3D - Start page at  · 2018. 12. 10. · Computing a Convex Hull in 3D • Incremental Algorithm – Add points one at a time and maintain a current convex hull. –

Deleting/Adding Facets •  Remove visible faces.

–  Easy since, by construction, each facet is oriented counterclockwise when seen from the outside of the convex hull.

•  Insert new triangular facets for each edge in the horizon unless the new face would be coplanar with an existing face ”behind” the horizon, in which case the two are merged.

D7013E Computational Geometry - Håkan Jonsson 9 D7013E Computational Geometry - Håkan Jonsson 10

•  Constructing the initial pyramid takes O(1) time. •  Processing each of the remaining n-4 points

means: –  Finding the horizon, –  removing visible faces, thereby “opening it up”, and –  adding new triangles to “close” the convex hull again.

•  Since each of these steps can be performed in O(n) time, the total time becomes O(n2). –  Is this the best we can do…?

Worst-Case Analysis

D7013E Computational Geometry - Håkan Jonsson 11

•  We get an algorithm expected to be faster by using two clever tricks:

•  1) Randomization! Permute the input. –  As we have done before. –  Lowers the expected time to O(n log n).

•  2) Use a conflict graph to add points and find which faces to remove fast.

How to Find the Visible Facets Conflict Graphs •  Bipartite.

–  A node per point not yet considered.

–  A node per facet in the current convex hull.

•  Arcs between points and facets that are in conflict (“visible”).

•  We maintain the conflict graph during the computation.

–  After a point has been considered, we remove its node.

•  Pconflict(f) is the list of points in conflict with f.

•  Fconflict(pt) is the list of faces in conflict with pt.

D7013E Computational Geometry - Håkan Jonsson 12

Points left to insert.

Page 4: Convex Hulls in 3D - Start page at  · 2018. 12. 10. · Computing a Convex Hull in 3D • Incremental Algorithm – Add points one at a time and maintain a current convex hull. –

Using the Conflict Graph

•  The facets visible to a point are its neighbors in the graph.

•  Likewise: The points visible from a facet are its neighbors in the graph.

•  The conflict sets of points and facets can be extracted in time linear in their sizes.

D7013E Computational Geometry - Håkan Jonsson 13 D7013E Computational Geometry - Håkan Jonsson 14

Adding a point pt

•  Using the conflict graph, we get all visible facets and the horizon.

–  Fconflict(pt) •  Remove all visible facets, but keep those next to the

horizon in a separate data structure for a while. –  Update the conflict graph accordingly. –  For each face f that is deleted, and for each p in Pconflict(f),

delete f from Fconflict(p). •  If Fconflict(p) becomes empty, p is inside the hull and will

never be considered again. –  Delete the node of f.

•  When adding a new point – and new facets – to the convex hull , we add new nodes to the conflict graph as well.

–  The crucial point is how to construct their conflict lists. •  Note: The conflicts of facets not visible from pt are not

effected.

Constructing conflict lists Consider adding a new face f. •  f is coplanar with f1 (”behind” the

horizon) ConflictList(f) = ConflictList(f1). �(since a point p is seen from f1 if and only if it is also visible from f.)

•  f is not coplanar with f1 –  ConflictList(f) = �

points of ConflictList(f1) and ConflictList(f2) visible from f.

�(There could be points visible from f2 and f, but not f1, and vice versa.)

D7013E Computational Geometry - Håkan Jonsson 15 D7013E Computational Geometry - Håkan Jonsson 16

f

New Faces lie Next to the Horizon

Page 5: Convex Hulls in 3D - Start page at  · 2018. 12. 10. · Computing a Convex Hull in 3D • Incremental Algorithm – Add points one at a time and maintain a current convex hull. –

D7013E Computational Geometry - Håkan Jonsson 17

Expected number of facets •  Lemma 11.3:

–  The expected number of facets created by our algorithm is at most 6n-20.

•  Backward analysis: –  Remove pr from CH(Pr). –  The number of facets

removed is the same as those created by pr.

–  The number of edges incident to pr in CH(Pr) is the degree of pr:

deg(pr, CH(Pr))

D7013E Computational Geometry - Håkan Jonsson 18

Expected number of facets •  (Lemma 11.1) A convex polytope of r vertices has at most 3r-6 edges.

–  ⇒ The sum of degrees of vertices of the polytope is 6r-12. •  Then the expected degree of a vertex pr is bounded by (6r-12)/r. •  A more careful analysis [page 250]:

–  The initial pyramid has at most degree 12 and pr is chosen from a subset of the original set of points.

D7013E Computational Geometry - Håkan Jonsson 19

Chapter 11CONVEX HULLS

11.3* The Analysis

As usual when we analyse a randomized incremental algorithm, we first try tobound the expected structural change. For the convex hull algorithm this meanswe want to bound the total number of facets created by the algorithm.

Lemma 11.3 The expected number of facets created by CONVEXHULL is atmost 6n−20.

Proof. The algorithm starts with a tetrahedron, which has four facets. In everystage r of the algorithm where pr lies outside CH(Pr−1), new triangular facetsconnecting pr to its horizon on CH(Pr−1) are created. What is the expectednumber of new facets? As in previous occasions where we analyzed randomizedalgorithms, we use backwards analysis. We look at CH(Pr) and imagine remov-ing vertex pr; the number of facets that disappear due to the removal of pr fromCH(Pr) is the same as the number of facets that were created due to the insertionof pr into CH(Pr−1). The disappearing facets are exactly the ones incident to pr,and their number equals the number of edges incident to pr in CH(Pr). We callthis number the degree of pr in CH(Pr), and we denote it by deg(pr,CH(Pr)).We now want to bound the expected value of deg(pr,CH(Pr)).

By Theorem 11.1 a convex polytope with r vertices has at most 3r−6 edges.This means that the sum of the degrees of the vertices of CH(Pr), which is aconvex polytope with r or less vertices, is at most 6r−12. Hence, the averagedegree is bounded by 6− 12/r. Since we treat the vertices in random order,it seems that the expected degree of pr is bounded by 6− 12/r. We have tobe a little bit careful, though: the first four points are already fixed when wegenerate the random permutation, so pr is a random element of {p5, . . . , pr},not of Pr. Because p1, . . . , p4 have total degree at least 12, the expected value ofdeg(pr,CH(Pr)) is bounded as follows:

E[deg(pr,CH(Pr))] =1

r−4

r

∑i=5

deg(pi,CH(Pr))

! 1r−4

! " r

∑i=1

deg(pi,CH(Pr))#−12

$

! 6r−12−12r−4

= 6.

The expected number of facets created by CONVEXHULL is the number offacets we start with (four) plus the expected total number of facets createdduring the additions of p5, . . . , pn to the hull. Hence, the expected number ofcreated facets is

4+n

∑r=5

E[deg(pr,CH(Pr))] ! 4+6(n−4) = 6n−20.

Now that we have bounded the total amount of structural change we canbound the expected running time of the algorithm.250

Expected number of facets

•  Since we started with a pyramid with 4 facets, we get the total number as the following sum:

D7013E Computational Geometry - Håkan Jonsson 20

Chapter 11CONVEX HULLS

11.3* The Analysis

As usual when we analyse a randomized incremental algorithm, we first try tobound the expected structural change. For the convex hull algorithm this meanswe want to bound the total number of facets created by the algorithm.

Lemma 11.3 The expected number of facets created by CONVEXHULL is atmost 6n−20.

Proof. The algorithm starts with a tetrahedron, which has four facets. In everystage r of the algorithm where pr lies outside CH(Pr−1), new triangular facetsconnecting pr to its horizon on CH(Pr−1) are created. What is the expectednumber of new facets? As in previous occasions where we analyzed randomizedalgorithms, we use backwards analysis. We look at CH(Pr) and imagine remov-ing vertex pr; the number of facets that disappear due to the removal of pr fromCH(Pr) is the same as the number of facets that were created due to the insertionof pr into CH(Pr−1). The disappearing facets are exactly the ones incident to pr,and their number equals the number of edges incident to pr in CH(Pr). We callthis number the degree of pr in CH(Pr), and we denote it by deg(pr,CH(Pr)).We now want to bound the expected value of deg(pr,CH(Pr)).

By Theorem 11.1 a convex polytope with r vertices has at most 3r−6 edges.This means that the sum of the degrees of the vertices of CH(Pr), which is aconvex polytope with r or less vertices, is at most 6r−12. Hence, the averagedegree is bounded by 6− 12/r. Since we treat the vertices in random order,it seems that the expected degree of pr is bounded by 6− 12/r. We have tobe a little bit careful, though: the first four points are already fixed when wegenerate the random permutation, so pr is a random element of {p5, . . . , pr},not of Pr. Because p1, . . . , p4 have total degree at least 12, the expected value ofdeg(pr,CH(Pr)) is bounded as follows:

E[deg(pr,CH(Pr))] =1

r−4

r

∑i=5

deg(pi,CH(Pr))

! 1r−4

! " r

∑i=1

deg(pi,CH(Pr))#−12

$

! 6r−12−12r−4

= 6.

The expected number of facets created by CONVEXHULL is the number offacets we start with (four) plus the expected total number of facets createdduring the additions of p5, . . . , pn to the hull. Hence, the expected number ofcreated facets is

4+n

∑r=5

E[deg(pr,CH(Pr))] ! 4+6(n−4) = 6n−20.

Now that we have bounded the total amount of structural change we canbound the expected running time of the algorithm.250

Page 6: Convex Hulls in 3D - Start page at  · 2018. 12. 10. · Computing a Convex Hull in 3D • Incremental Algorithm – Add points one at a time and maintain a current convex hull. –

Total time complexity

•  Initialization takes O(n log n). –  If we end up having to compute a 2D convex hull.

•  Creating and deleting facets takes O(n) time since this is the expected number of facets created.

•  To deleting pr and facets in Fconflict(pr) from the conflict graph along with incident arcs also takes O(n) time.

•  Our only headache is the time it takes to find new conflicts.

D7013E Computational Geometry - Håkan Jonsson 21

Total time complexity •  For each edge e on the horizon we use

O(|P(e)|) time, where � P(e) =Pconflict(f1) ∪ Pconflict(f2).

•  The total time is O(Σe|P(e)|), where e is an edge of a horizon during the computation.

•  Lemma 11.6: –  The expected value of Σe|P(e)|, where the

summation is over all horizon edges that appear at some stage of the algorithm, is O(n log n).

–  (Exactly 96n log n.) •  Lemma 11.7:

–  The convex hull of n points in R3 can be computed in O(n log n) time.

D7013E Computational Geometry - Håkan Jonsson 22

23 / 41

Convex Hulls in Dual Space

•  In Chapter 8 we learned about geometric duality. •  The upper (lower) convex hull of a set of points is

“essentially” the lower (upper) envelope of a set of lines.

24 / 41

Why “essentially”?

•  It may seem that convex hulls and intersections of half planes are dual concepts…

•  … and that an algorithm to compute the intersection of half-planes can be given as a convex hull algorithm in the dual plane.

•  However, the convex hull of points is always well-defined while the intersection of half-planes could be empty – does not exist.

•  Only as long as the intersection exists, the dual does.

Page 7: Convex Hulls in 3D - Start page at  · 2018. 12. 10. · Computing a Convex Hull in 3D • Incremental Algorithm – Add points one at a time and maintain a current convex hull. –

Convex Hulls in 3D and Voronoi diagrams/Delaunay Triangulations in 2D •  Ok, so convex hulls

dualizes to intersections of half-planes.

•  From Chapter 7 we know that cells in Voronoi diagrams are intersections of half-planes.

D7013E Computational Geometry - Håkan Jonsson 25 D7013E Computational Geometry - Håkan Jonsson 26

D7013E Computational Geometry - Håkan Jonsson 27 D7013E Computational Geometry - Håkan Jonsson 28

Conclusion

•  The Delaunay triangulation/Voronoi diagram of a set of n points (xi, yi) in the plan can be computed by computing the convex hull in 3D of the points (xi, yi, xi

2+yi2).

–  Project the lower hull of the triangulation onto the xy-plane.

–  (The dual is the Voronoi diagram.) •  Moreover, the dual of the upper hull projected

down onto the xy-plane is the furthest-point Voronoi diagram. –  (Read also the handout you got.)

Page 8: Convex Hulls in 3D - Start page at  · 2018. 12. 10. · Computing a Convex Hull in 3D • Incremental Algorithm – Add points one at a time and maintain a current convex hull. –

D7013E Computational Geometry - Håkan Jonsson 29

Conclusion

•  (Lemma 11.4) –  Given a set of n points in 3D, CONVEXHULL

computes a convex hull in O(n log n) expected time. •  Comment:

–  There is also a deterministic algorithm by Preparata and Hong that runs in O(n log n) time, but that one is more complicated.