A Simpler Linear-Time Algorithm for Intersecting Two Convex
Transcription
A Simpler Linear-Time Algorithm for Intersecting Two Convex
A Simpler Linear-Time Algorithm for Intersecting Two Convex Polyhedra in Three Dimensions Timothy M. Chan∗1 1 Cheriton School of Computer Science, University of Waterloo [email protected] Abstract Chazelle [FOCS’89] gave a linear-time algorithm to compute the intersection of two convex polyhedra in three dimensions. We present a simpler algorithm to do the same. 1998 ACM Subject Classification F.2.2 Nonnumerical Algorithms and Problems Keywords and phrases convex polyhedra, intersection, Dobkin–Kirkpatrick hierarchy Digital Object Identifier 10.4230/LIPIcs.xxx.yyy.p 1 Introduction This note concerns the following problem: given two convex polyhedra of size O(n) in 3-d, compute their intersection. Equivalently, the dual problem is to compute the convex hull of the two convex polyhedra, i.e., merge two convex hulls. This is one of the most basic computational problems about convex polyhedra. Algorithms for the problem have been used as subroutines to solve many other problems in computational geometry (see [2] for just one example). In the 70s, Preparata and Hong [13] observed that two linearly separated convex hulls in 3-d can be merged in linear time. (Earlier Shamos and Hoey [14] observed the same for the special case of two linearly separated Delaunay triangulations in 2-d, and later Kirkpatrick [9] showed how to merge two arbitrary Delaunay triangulations in 2-d in linear time.) The general problem was eventually settled a decade later when Chazelle [4] announced a linear-time algorithm for intersecting/merging two arbitrary convex polyhedra in 3-d. Chazelle’s algorithm, like many of his other works, is a tour de force. It started with a standard construction of the Dobkin–Kirkpatrick (DK) hierarchies [6, 7] of the input polyhedra in both primal and dual space, but incorporated pages of intricate ideas and details. To give a flavor of the overall plan, we only mention that the running time satisfies a recurrence of the form T (n) = 4 T (δn) + O(n), which indeed solves to T (n) = O(n) for a sufficiently small constant δ > 0. A thesis by Martin [11] described a simplification of Chazelle’s algorithm that avoided switching back and forth with duality, but needed to navigate simultaneously in the DK hierarchies of the insides and outsides of the polyhedra. The details were still lengthy, and the recurrence was “improved” to T (n) = 2 T (δn) + O(n). Chazelle’s work dated back to a time when the unifying techniques of randomized geometric divide-and-conquer [5, 12] were just starting to flourish. This prompts the question of whether more modern concepts like sampling, conflict lists, etc. might give a simpler ∗ Part of this work was done during the author’s visit to the Hong Kong University of Science and Technology. © Timothy M. Chan; licensed under Creative Commons License CC-BY Conference title on which this volume is based on. Editors: Billy Editor and Bill Editors; pp. 1–6 Leibniz International Proceedings in Informatics Schloss Dagstuhl – Leibniz-Zentrum für Informatik, Dagstuhl Publishing, Germany 2 A Simpler Linear-Time Algorithm for Intersecting Convex Polyhedra explanation for why the problem can be solved in linear time. After all, at a gut level, this textbook problem shouldn’t be that hard to solve (although one could say the same for the problem of triangulating a simple polygon [3, 1]!). In this note, we show that there is indeed a simpler linear-time algorithm for intersecting two convex polyhedra. Our solution ends up not requiring random sampling, but falls back to the DK hierarchy. We only need to navigate in the hierarchies of the outsides, and we don’t need to switch between primal and dual space. Furthermore, we get a more usual recurrence T (n) = T (δn) + O(n)—in other words, a more conventional way of using DK hierarchies turns out to work after all! There are concrete advantages to having the better recurrence when considering other computational models; for example, the algorithm is more efficiently parallelizable. However, we believe the simplicity of the solution is what is the most valuable aspect of the work. 2 Preliminaries We begin by computing a point o in the intersection of the two convex polyhedra; this can be done in linear time by 3-d linear programming [8] (known randomized algorithms are particularly simple), or in polylogarithmic time using DK hierarchies [6, 7]. By translation, we may make o the origin. It suffices to compute the part of the intersection in {z > 0}. By a projective transformation (x, y, z) 7→ (x/z, y/z, −1/z), we can move o to (0, 0, −∞) and thus assume that both input polyhedra are unbounded from below, i.e., they are (the regions underneath) lower envelopes of planes. We assume that the planes are in general position, by standard perturbation techniques. Given a set H of planes, let P(H) denote the region underneath its lower envelope. We say that H is nonredundant if all planes of H participate in the boundary of P(H). Given P = P(H), let T (P ) denote a triangulation of P . More precisely, we triangulate each face of P , and for each triangle v1 v2 v3 we take the region underneath v1 v2 v3 (a prism unbounded from below) as a cell of T (P ). For any region ∆, the conflict list H|∆ is the subset of all planes of H intersecting ∆. A standard approach to computing the lower envelope of H is to pick a random sample H 0 of H, construct the lower envelope of the conflict list H|∆ inside ∆ for each cell ∆ ∈ T (P(H 0 )), and then glue the results together. Although we will not use randomization, we will adapt similar ideas. Given P(H1 ) and P(H2 ) for two nonredundant sets H1 and H2 of planes, our problem is to compute P = P(H1 ) ∩ P(H2 ) (i.e., P = P(H1 ∪ H2 )). In order to allow for a recursive algorithm, we need to strengthen the output requirement and require further information to be reported for each vertex v of P . Our key idea is this. Since v is in the intersection, we know that v is on or below P(Hj ) for each j ∈ {1, 2}. Thus, there exist three vertices w1 , w2 , w3 of P(Hj ) that “witness” this fact, i.e., that have v below1 4w1 w2 w3 . We will require the algorithm to output one such triple for each v and j. It is important that we do not insist w1 w2 w3 be a face of (a triangulated) P(Hj ). Otherwise, one can show that finding such witnesses may require Ω(n log n) comparisons in the worst case! Witnesses will make the generation of conflict lists easy; on the other hand, extra work will be required to find witnesses. To summarize, we will solve the following stronger prolem: 1 Throughout the paper, “below” means “below or is incident to” unless preceded by “strictly”. T. M. Chan Problem: Given P(H1 ) and P(H2 ) for two nonredundant sets H1 and H2 of n planes, compute P = P(H1 ) ∩ P(H2 ), and for each vertex v of P and each j ∈ {1, 2}, report some vertices w1 , w2 , w3 of P(Hj ), called the j-witnesses of v, such that v is below 4w1 w2 w3 . 3 The Algorithm We are now ready to give the algorithm outline to solve the problem: Intersect(P(H1 ), P(H2 )): 0. if H1 and H2 have size below a constant then return answer directly 1. for j ∈ {1, 2}: 2. choose an independent set of faces of P(Hj ) 3. let Ij be the planes defining these faces, and let Hj0 = Hj \ Ij 4. obtain P(Hj0 ) from P(Hj ) 0 5. P = Intersect(P(H10 ), P(H20 )) // now compute the intersection P of P(H1 ) and P(H2 ) for each ∆ ∈ T (P 0 ): for j ∈ {1, 2}: find the conflict list Hj |∆ by searching in the candidate list Cj,∆ := { h ∈ Hj : h lies below a j-witness of a vertex of ∆ } 9. compute the intersection of P(H1 |∆ ) and P(H2 |∆ ) inside ∆ 10. glue all the polyhedra from line 9 to get P 6. 7. 8. // now compute new witnesses for P 11. for each ∆ ∈ T (P 0 ): 12. for j ∈ {1, 2}: 13. for each vertex v of P inside ∆: 14. find j-witnesses of v by searching in the candidate witness list Wj,∆ := { vertices w of P(Hj ): w is a j-witness of a vertex of ∆ or w is on a plane in Ij ∩ Cj,∆ } 15. return P with all its witnesses We explain the algorithm in more detail. In line 2, independence means that the chosen faces do not share any edges. By applying a standard linear-time greedy algorithm to a planar graph in the dual, we can always choose an independent set of at least αn faces each with at most c vertices, for some constants α and c; for example, see Kirkpatrick’s well known paper [10], which has α = 1/24 and c = 11. Line 4 takes linear time, since the difference of two polyhedra P(Hj ) and P(Hj0 ) consists of disjoint constant-size pockets, as we are removing an independent set of constant-size faces; each pocket can be constructed from the lower envelope of O(1) planes. (The hierarchy of polyhedra produced from the recursion is commonly referred to as the Dobkin–Kirkpatrick hierarchy [6, 7].) Line 5 contains the main recursive call, where the number of planes in either input set drops to at most (1 − α)n. In line 8, we use witnesses for P 0 to help generate conflict lists. Any plane h in the conflict list Hj |∆ must lie below one u of the three vertices of ∆. Since u (a vertex of P 0 ) lies below 4w10 w20 w30 for its j-witnesses w10 , w20 , w30 , it follows that h lies below some wi0 and must indeed be in the candidate list Cj,∆ . There are at most nine j-witnesses for the three vertices of ∆. Each j-witness wi0 (a vertex of P(Hj0 )) has at most O(1) planes of Hj below it: namely, its three defining planes, 3 4 A Simpler Linear-Time Algorithm for Intersecting Convex Polyhedra and at most one plane from Ij strictly below it (which we can easily identify after initializing some pointers). Thus, the candidate list Cj,∆ has constant size, and so each conflict list Hj |∆ can be generated in constant time. Line 9 takes constant time even by a brute-force algorithm. Line 10 then takes linear total time. We show, with a slightly subtle proof, that in line 14, we can indeed always find j-witnesses from the candidate witness list Wj,∆ : I Lemma 1. For a vertex v of P inside ∆, there exist w1 , w2 , w3 ∈ Wj,∆ such that v lies below 4w1 w2 w3 . Proof. Let W 0 be the at most nine j-witnesses of the three vertices of ∆. Then v lies below the upper hull of W 0 and is thus below the upper hull of some three points w10 , w20 , w30 ∈ W 0 (which are vertices of P(Hj0 )). Let Γ be the region underneath 4w10 w20 w30 . Since v is in P(Hj ) ∩ Γ, there exist three vertices u1 , u2 , u3 of P(Hj ) ∩ Γ such that v is below 4u1 u2 u3 . (Note that each ui may not necessarily be a vertex of P(Hj ) as it could lie on the boundary of Γ.) For each i ∈ {1, 2, 3}, we claim that ui is below the upper hull of Wj,∆ : Case 1: ui is a vertex of Γ, i.e., ui ∈ {w10 , w20 , w30 }. Then ui is a vertex of P(Hj0 ). Since ui is in P(Hj ), it follows that ui is a vertex of P(Hj ). Thus, ui is in Wj,∆ by definition of Wj,∆ , and the claim is trivially true. Case 2: ui is not a vertex of Γ. Then ui must be defined by at least one plane h ∈ Hj that intersects the interior of Γ. This plane h is strictly below at least one of w10 , w20 , w30 and so must be a member of Ij and also a member of Cj,∆ . Now, ui lies in the face of P(Hj ) defined by h; all the vertices of this face are in Wj,∆ by definition of Wj,∆ , and the claim is again true. Since v is below 4u1 u2 u3 , it follows that v is below the upper hull of Wj,∆ and is thus below 4w1 w2 w3 for some three vertices w1 , w2 , w3 ∈ Wj,∆ . J The candidate witness list Wj,∆ has constant size, since there are at most nine j-witnesses for the three vertices of ∆, each plane in Ij contains at most c vertices, and there are O(1) planes in Cj,∆ . So, line 13 can be done in constant time by brute force. The entire loop in lines 11–14 then takes linear total time. The overall running time of the algorithm satisfies the recurrence T (n) = T ((1 − α)n) + O(n), which solves to T (n) = O(n). 4 Remarks An alternative, slightly slower algorithm. There is a more “standard” algorithm based on ∗ sampling, without using witnesses, that gives almost linear n2O(log n) expected time. For the readers who are familiar with randomization techniques [5, 12] and enjoy comparisons of different approaches, we briefly sketch the alternative: First consider a multiset version of Hj where the multiplicity wj (h) (the weight) of each plane h ∈ Hj is the size of the face of P(Hj ) defined by h. The multiset still has O(n) size. We draw a random sample Hj0 of the multiset of size r = O(n/ log n). We construct P(H10 ), P(H20 ), and their intersection P 0 by an O(r log r)-time algorithm, which takes O(n) time. For each vertex v of P(Hj0 ), we can construct its conflict list Hj |v (the list of all planes of Hj below v) as follows: first find an initial plane of Hj below v by a point location query in the xy-projection of P(Hj ); then find all planes of Hj below v by a graph search over the T. M. Chan faces of P(Hj ). This works because the planes below v correspond to the faces visible to v, which are connected in the boundary of P(Hj ) (assuming that Hj is nonredundant). We can preprocess in linear time for point location in O(log n) time [10], so the O(r) point location queries cost O(n) total time. The graph search takes time proportional to the weight of Hj |v . The total time over all v is O(r · n/r) = O(n) in expectation, by Clarkson and Shor’s analysis [5]. Next, for each vertex v of P 0 , we can compute its conflict list Hj |v as follows: first find a cell ∆ ∈ T (P(Hj0 )) containing v by a point location query in the xy-projection of T (P(Hj0 )); then search in the conflict lists of the three vertices of ∆ (which are vertices of P(Hj0 )) found in the preceding paragraph. The O(r) point location queries again cost O(n) total time. So, this step again takes O(n) expected total time. For each cell ∆ ∈ T (P 0 ), we can now generate the conflict list Hj |∆ from the conflict lists of the three vertices of ∆ (which are vertices of P 0 ) found in the preceding paragraph. We then recursively compute the intersection of P(H1 |∆ ) and P(H2 |∆ ) inside ∆, and glue the polyhedra together. By Clarkson and Shor’s analysis [5], the total expected running time satisfies the recurrence P T (n) = i T (ni ) + O(n) where maxi ni = O((n/r) log n) = O(log2 n) with high probability P and i ni has expected value O(r · n/r) = O(n). With O(log∗ n) iterations, this yields an ∗ expected time bound of n2O(log n) . An open problem. An interesting question is whether we can similarly merge lower envelopes of pseudo-planes in 3-d in linear time, under an appropriate definition of pseudo-planes where three pseudo-planes may intersect in at most one point. This would have applications to merging two additively weighted Voronoi diagrams in 2-d, for instance. Our concept of j-witnesses unfortunately doesn’t seem immediately generalizable, although the alternative ∗ n2O(log n) -time randomized algorithm can be adapted at least for the case of 2-d additively weighted Voronoi diagrams. Acknowledgement. The author thanks Stefan Langerman for discussion on these problems. References 1 2 3 4 5 6 7 Nancy M. Amato, Michael T. Goodrich, and Edgar A. Ramos. A randomized algorithm for triangulating a simple polygon in linear time. Discrete and Computational Geometry, 26(2):245–265, 2001. Timothy M. Chan. Deterministic algorithms for 2-d convex programming and 3-d online linear programming. Journal of Algorithms, 27(1):147–166, 1998. Bernard Chazelle. Triangulating a simple polygon in linear time. Discrete and Computational Geometry, 6:485–524, 1991. Bernard Chazelle. An optimal algorithm for intersecting three-dimensional convex polyhedra. SIAM Journal on Computing, 21(4):671–696, 1992. Kenneth L. Clarkson and Peter W. Shor. Application of random sampling in computational geometry, II. Discrete and Computational Geometry, 4:387–421, 1989. David P. Dobkin and David G. Kirkpatrick. A linear algorithm for determining the separation of convex polyhedra. Journal of Algorithms, 6(3):381–392, 1985. David P. Dobkin and David G. Kirkpatrick. Determining the separation of preprocessed polyhedra—A unified approach. In Proceedings of the 17th International Colloquium on Automata, Languages and Programming, pages 400–413, 1990. 5 6 A Simpler Linear-Time Algorithm for Intersecting Convex Polyhedra 8 9 10 11 12 13 14 Martin Dyer, Nimrod Megiddo, and Emo Welzl. Linear programming. In Jacob E. Goodman and Joseph O’Rourke, editors, Handbook of Discrete and Computational Geometry, chapter 45. CRC Press, second edition, 2004. David G. Kirkpatrick. Efficient computation of continuous skeletons. In Proceedings of the 20th Annual Symposium on Foundations of Computer Science, pages 18–27, 1979. David G. Kirkpatrick. Optimal search in planar subdivisions. SIAM Journal on Computing, 12(1):28–35, 1983. Andrew K. Martin. A simple primal algorithm for intersecting 3-polyhedra in linear time. Master’s thesis, Department of Computer Science, University of British Columbia, 1991. https://circle.ubc.ca/handle/2429/30114 or http://www.cs.ubc.ca/cgi-bin/tr/1991/TR-9116. Ketan Mulmuley. Computational Geometry: An Introduction Through Randomized Algorithms. Prentice Hall, Englewood Cliffs, NJ, 1993. Franco P. Preparata and S. J. Hong. Convex hulls of finite sets of points in two and three dimensions. Communications of the ACM, 20(2):87–93, 1977. Michael Ian Shamos and Dan Hoey. Closest-point problems. In Proceedings of the 16th Annual Symposium on Foundations of Computer Science, pages 151–162, 1975.