BF 02712873
BF 02712873
Geometry
~) 1996Springer-VerlagNewYorkInc.
T. M. Chan
Department of Computer Science, University of British Columbia,
Vancouver, British Columbia, Canada V6T 1Z4
Abstract. We present simple output-sensitive algorithms that construct the convex hull
of a set of n points in two or three dimensions in worst-case optimal O (n log h) time and
O(n) space, where h denotes the number of vertices of the convex hull.
1. Introduction
* This research was supported by a Killam Predoctoral Fellowship and an NSERC Postgraduate
Scholarship.
362 T.M. Chan
algorithms, with complexity measured as a function of both n and the "output size" h,
are said to be output-sensitive.
In this note, we point out a simple output-sensitive convex hull algorithm in E 2 and its
extension in E 3, both running in optimal O(n log h) time. Previous optimal (determin-
istic) methods, including the algorithm by Kirkpatrick and Seidel and its improvement
by Chan et al., all rely on the existence of a linear-time procedure for finding medians.
In Chazelle and Matougek's three-dimensional algorithm, even more complex tools for
derandomization, such as e-approximations, are used. Our algorithms avoid median-
finding and derandomization altogether; Dobkin-Kirkpatrick hierarchies [9], [10] are
the only data structures used in the three-dimensional case. Our idea is to speed up
Jarvis's march and the gift-wrapping method by using a very simple grouping trick.
Let P C E 2 be a set of n _> 3 points. For simplicity, we assume that the points of P are
in general position, i.e., no three points are collinear; see Section 4 for how to deal with
degenerate point sets.
Recall that Jarvis's march [19], [23], [25] computes the h vertices of the convex hull
one at a time, in counterclockwise (ccw) order, by a sequence of h wrapping steps: if
Pk-1 and Pk are the previous two vertices computed, then the next vertex Pk+~ is set to
be the point p E P that maximizes the angle Zp~-lpkP with p 7~ Pk. One wrapping
step can obviously be done in O (n) time by scanning all n points; with an appropriate
initialization the method constructs the entire convex hull in O (nh) time.
We observe that a wrapping step can be done faster if we preprocess the points. Choose
a parameter m between 1 and n and partition P into In/m] groups each of size at most m.
Compute the convex hull of each group in O(m log m) time by, say, Graham's scan [15].
This gives us In~m] possibly overlapping convex polygons each with at most m vertices,
after a preprocessing time of O ((n/m) (m log m)) = O (n log m). Now, a wrapping step
can be done by scanning all In~m] polygons and computing tangents or supporting lines
of the polygons through the current vertex Pk, as shown in Fig. 1. Since tangent finding
takes logarithmic time for a convex polygon by binary or Fibonacci search [5], [25] (the
dual problem is to intersect a convex polygon with a ray), the time required for a wrapping
step is then O ((n/m) log m). As h wrapping steps are needed to compute the hull, the total
time of the algorithm becomes O (n log m d- h ((n/m) log m)) = O (n (1 + h/m) log m).
The following is a pseudocode of the algorithm just described. The procedure always
runs within O(n(1 q- H/m)log m) time and successfully returns the list of vertices of
cony(P) in ccw order when H >_ h.
6. f o r k = l . . . . . H d o
7. for i = 1 . . . . . In~m] do
8. compute the point qi E Pi that maximizes Z p k - i Pkqi ( qi ~ Pk )
by performing a binary search on the vertices of conv(Pi)
9. Pk+l ~-- the point q from {ql . . . . . qFn/mq} that maximizes Zpk-1Pkq
10. if Pk+l = Pl then return the list (Pl . . . . . Pk)
11. return incomplete
1. f o r t = 1,2 . . . . do
2. L ~ Hull2D(P, m, H), where m = H = min{22' , n}
3. if L ~ incomplete then return L
The procedure stops with the list of hull vertices as soon as the value of H in the for-loop
reaches or exceeds h. The number of iterations in the loop is [log log hi (using base-2
logarithms), and the tth iteration takes O(n log H) = O(n2 I) time. Therefore, the total
running time of the algorithm is O rxT~Fl~176
~z_~t=l n2 t) = O(n2 Fl~176 = O(nlogh).
The storage requirement is clearly linear.
364 T.M. Chan
Let P C E 3 be a set of n > 4 points. Again we assume general position, i.e., no four
points are coplanar (see Section 4). It suffices to construct the 2h - 4 facets (triangular
faces) of the convex hull; with the aid of a dictionary, we can easily produce the set
of h vertices and 3h - 6 edges together with their adjacency and order information in
additional O(h log h) time.
The higher-dimensional analogue of Jarvis's march is Chand and Kapur's gift-wrapping
method [3], [25], [26], which computes the hull facets one at a time as follows: from a
given facet f , we generate its three adjacent facets 3~ by performing a wrapping step
about each of the three edges ej of f (j = 1, 2, 3). Here, a wrapping step about ej is to
compute a point pj E P that maximizes the angle between f and conv(ej U {pj}) with
pj ~ ej. Since such a step can be done in O(n) time, we can find the facets adjacent
to f in O(n) time. Assuming an initial facet f0 is given (which can be found in two
wrapping steps), a breadth-first or depth-first search can then generate all facets of the
convex hull. Using a dictionary to detect duplication, we can ensure that each facet is
processed once. This implies that the algorithm performs 3(2h - 4) wrapping steps and
thus runs in O(nh) time.
We can use the same grouping idea from the previous section to improve the time
complexity to optimal O (n log h) while maintaining linear space. The calls to Graham's
scan (line 3 of Hull2D(P, m, H)) are now replaced by calls to Preparata and Hong's three-
dimensional convex hull algorithm [24], which has the same complexity. To make line 8
work in E 3, we need to calculate tangents or supporting planes of convex polyhedra
through a given line (or, in dual space, intersect convex polyhedra with a ray). If we
use the hierarchical representation of Dobkin and Kirkpatrick [9], [10] to store these
polyhedra (which requires only linear-time preprocessing), then the tangents can be
computed in logarithmic time each, as before. The analysis is thus identical to that of
the two-dimensional algorithm. The pseudocode is as follows:
4. Refinements
In this section we suggest ideas on possible improvements that may speed up our algo-
rithms in practice; we also discuss how degenerate cases can be handled.
Idea 1. First, points found to be in the interior of conv (P,.) in line 3 of Hull2D(P, m, H )
or Hull3D(P, m, H) can be eliminated from further consideration. This may potentially
save work during future iterations of the algorithm, although it does not affect the worst-
case complexity.
Idea 3. With Idea 2, the dominant cost of algorithm Hull2D(P, m, H) lies in the pre-
processing, i.e., the computation of the convex hulls of the groups in line 3. To reduce this
cost, we may consider reusing hulls computed from the previous iteration and merging
them as the group size is increased. Suppose m' is the previous group size. Since the
convex hull of two convex polygons can be computed in linear time (the dual problem
is to intersect two convex polygons), we can compute the convex hull of [m/m'7 con-
vex m'-gons in O (m log (m / m')) time by the standard "mergehulr' divide-and-conquer
algorithm [25]. Thus, the In~m7 hulls in line 3 can be constructed in O(n log(m/m'))
366 T.M. Chan
rather than O(n log m) time. The same can be said for the three-dimensional case, but
merging two convex polyhedra, though possible in linear time [4], is more complicated.
Idea 5. E. Welzl has observed that the binary search in line 8 of Algorithm Hull2D(P, m,
H) can be replaced by a simpler linear search without changing the time complexity of
the algorithm. The following monotonicity property provides the justification: during the
course of the algorithm, the variable qi in line 8 can only advance in the ccw direction
along conv(Pi) for each fixed i. As a result, the h-vertex convex hull of p convex poly-
gons with a total ofn vertices can be computed in O(n + hp) time by gift-wrapping; the
two-polygon (p = 2) version of the algorithm is in fact the dual of an intersection algo-
rithm by O'Rourke et al. [22] (see also [23] and [25]). The total cost of Hull2D(P, m, H)
can then be reduced to O(n log m + H(n/m)) time, which is a log m factor saving in the
second term. Although the overall constant factor is unaffected by the saving if Idea 2 is
employed (as the first term is the dominant one), the linear search is easier to implement.
There does not seem to be an analogous simplification in three dimensions.
5. Extensions
Acknowledgments
I wish to thank Jack Snoeyink for his great support and encouragement as well as for his
many valuable suggestions.
References
and clipped Voronoi diagrams in three. Proc. 6th ACM-SIAM Symp. on Discrete Algorithms, pp. 282-291,
1995.
3. D. R. Chand and S. S. Kapur. An algorithm for convex polytopes. J. Assoc. Comput. Mach., 17:78-86,
1970.
4. B. Chazelle. An optimal algorithm for intersecting three-dimensional convex polyhedra. S1AMJ. Comput.,
21:671~596, 1992.
5. B. Chazelle and D. P. Dobkin. Intersection of convex objects in two and three dimensions. J. Assoc. Comput.
Mach., 34:1-27, 1987.
6. B. Chazelle, H. Edelsbrunner, M. Grigni, L. Guibas, J. Hershberger, M. Sharir, and J. Snoeyink. Ray
shooting in polygons using geodesic triangulations. Proc. 18th lnternat. Colloq. on Automata, Languages,
and Programming, pp. 661-673, Lecture Notes in Computer Science, vol. 510. Springer-Verlag, Berlin,
1991.
7. B. Chazelle and J. Matou~ek. Derandomizing an output-sensitive convex hull algorithm in three dimensions.
Comput. Geom. Theory Appl., 5:27-32, 1995.
8. K. L. Clarkson and P. W. Shor. Applications of random sampling in computational geometry, H. Discrete
Comput. Geom., 4:387-421, 1989.
9. D. P. Dobkin and D. G. Kirkpatrick. Fast detection of polyhedral intersection. Theoret. Comput. Sci.,
27:241-253, 1983.
10. D. P. Dobkin and D. G. Kirkpatrick. Determining the separation of preprocessed polyhedra: a unified
approach. Proc. 17th lnternat. Colloq. on Automata, Languages, and Programming, pp. 440--413, Lecture
Notes in Computer Science, vol. 443. Springer-Verlag, Berlin, 1990.
11. H. Edelsbrunner. Algorithms in Combinatorial Geometry. Springer-Verlag, Berlin, 1987.
12. H. Edelsbrunner and E. P. Miicke. Simulation of simplicity: A technique to cope with degenerate cases in
geometric algorithms. ACM Trans. Graphics, 9:66-104, 1990.
13. H. Edelsbrunner and W. Shi. An O (n log2 h) time algorithm for the three-dimensional convex hull problem.
SlAM J. Comput., 20:259-277, 1991.
14. I. Emiris and J. Canny. An efficient approach to removing geometric degeneracies. Proc. 8th ACM Symp.
on Computational Geometry, pp. 74-82, 1992.
15. R.L. Graham. An efficient algorithm for determining the convex hull of a finite planar set. Inform. Process.
Lett., 1:132-133, 1972.
16. S. Hart and M. Sharir. Nonlinearity of Davenport-Schinzel sequences and of generalized path compression
schemes. Combinatorica, 6:151 - 177, 1986.
17. J. Hershberger. Finding the upper envelope of n line segments in O (n log n) time. Inform. Process. Lett.,
33:169-174, 1989.
18. J. Hershberger and S. Suri. A pedestrian approach to ray shooting: shoot a ray, take a walk. Proc. 4th
A CM-SIAM Syrup. on Discrete Algorithms, pp. 54-63, 1993.
19. R. A. Jarvis. On the identification of the convex hull of a finite set of points in the plane. Inform. Process.
Lett., 2:18-21, 1973.
20. D.G. Kirkpalxick and R. Seidel. The ultimate planar convex hull algorithm? SlAM J. Comput., 15:287-299,
1986.
21. K. Mulmuley. Computational Geometry: An Introduction Through Randomized Algorithms. Prentice-Hall,
Englewood Cliffs, NJ, 1994.
22. J. O'Rourke, C.-B. Chien, T. Olson, and D. Naddor. A new linear algorithm for intersecting convex
polygons. Comput. Graph. Image Process., 19:384-391, 1982.
23. J. O'Rourke. Computational Geometry in C. Cambridge University Press, Cambridge, 1994.
24. E P. Preparata and S. J. Hong. Convex hulls of finite sets of points in two and three dimensions. Commun.
ACM, 20:87-93, 1977.
25. E P. Preparata and M. I. Shamos. Computational Geometry: An Introduction. Springer-Verlag, New York,
1985.
26. G. F. Swart. Finding the convex hull facet by facet. J. Algorithms, 6:17-48, 1985.
Received April 27, 1995, and in revisedform September 14, 1995, and November 30, 1995.