0% found this document useful (0 votes)
17 views8 pages

BF 02712873

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views8 pages

BF 02712873

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Discrete Comput Geom 16:361-368 (1996) Discrete& Computational

Geometry
~) 1996Springer-VerlagNewYorkInc.

Optimal Output-Sensitive Convex Hull Algorithms


in Two and Three Dimensions*

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

Given a set P o f n points in the Euclidean plane E 2 or Euclidean space E 3, we consider


the problem of computing the convex hull of P, cony(P), which is defined as the smallest
convex set containing P. The convex hull problem has received considerable attention in
computational geometry [11], [21], [23], [25]. In E 2 an algorithm known as Graham's
scan [15] achieves O(n logn) rtmning time, and in E 3 an algorithm by Preparata and
Hong [24] has the same complexity. These algorithms are optimal in the worst case,
but if h, the number of hull vertices, is small, then it is possible to obtain better time
bounds. For example, in E 2, a simple algorithm called Jarvis's march [ 19] can construct
the convex hull in O(nh) time. This bound was later improved to O(nlogh) by an
algorithm due to Kirkpatrick and Seidel [20], who also provided a matching lower
bound; a simplification of their algorithm has been recently reported by Chan et al.
[2]. In E 3 an O(nh)-time algorithm can be obtained using the gift-wrapping method,
an extension of Jarvis's march originated by Chand and Kapur [3]. A faster but more
involved algorithm in E 3 was discovered by Edelsbrunner and Shi [ 13], having a running
time of O(n log 2 h). Finally, by derandomizing an algorithm of Clarkson and Shor [8],
Chazelle and Matou~ek [7] succeeded in attaining optimal O (n log h) time in E 3. These

* 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.

2. An Output-Sensitive Algorithm in Two Dimensions

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.

Algorithm Hull2D(P, m, H), where P C E 2, 3 _< m _< n, and H > 1


1. partition P into subsets P1 . . . . . Prn/m] each of size at most m
2. fori = 1. . . . . In~m] do
3. compute conv(Pi) by Graham's scan and store its vertices in an array
in ccw order
4. P0 +- ( 0 , - o e )
5. Pl ~- the rightmost point of P
Optimal Output-SensitiveConvexHull Algorithms in Two and Three Dimensions 363

Fig. 1. Wrappinga set of Fnlm7 convexpolygons of size m.

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

By choosing m = H, the complexity of the algorithm is then O (n ( 1 + H / m ) log m) =


O (n log H). Since the value of h is not known in advance, we use a sequence of H ' s to
"guess" its value as shown below (the same strategy is used in Chazelle and Matou~ek's
algorithm):

Algorithm Hull2D(P), where P C E 2

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

3. An Output-Sensitive Algorithm in Three Dimensions

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:

Algorithm Hull3D(P, m, H), where P C E 3, 4 < m < n, and H > 1


1. partition P into subsets P1. . . . . PFn/ml each of size at most m
2. fori = 1. . . . . In~m] do
3. compute conv(P/) by Preparata and Hong's algorithm and store it in
a Dobkin-Kirkpatrick hierarchy
4. F, Q ~ {f0}, where f0 is some initial facet of conv(P)
5. f o r k = 1. . . . . 2 H - 4 d o
6. if Q = ~ then return F
7. pick some f ~ Q and set Q ~ Q - {f}
8. let ej be the edges of f (j = 1, 2, 3)
9. for j = 1, 2, 3 do
10. for i = 1. . . . . In~m] do
11. compute the point qi E Pi that maximizes the angle between f and
conv(ej O {qi }) by searching the hierarchy of conv(Pi)
12. pj +-- the point q from {ql . . . . . qrn/,~l} that maximizes the angle between
f and conv(ej U {q}) (q ~ ej)
Optimal Output-SensitiveConvexHull Algorithmsin Two and Three Dimensions 365

13. j') +- conv(ej O {pj})


14. if j~ ~ F then
15. F +-- F t3 {fj}, Q +-- Q u {j~}
16. return incomplete

We can use a queue or a stack to implement Q and a dictionary to implement F. As


there are only O(h) dictionary operations, they can be carried out in O(h logh) time.
In fact, more clever implementations of the gift-wrapping method via a shelling order
replace the need for dictionaries with just a priority queue.
As before, we choose the group size m = H and guess the value of h with a sequence
of H's:

Algorithm Hull3D(P), where P C E 3


1. f o r t = 1,2 . . . . do
2. L +- HulI3D(P, m, H), where m = H = min{2 z, n}
3. if L ~ incomplete then return L

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 2. In Hu112D(P) and HuI13D(P) we choose the group size m = H so as to


balance the O(n logm) preprocessing cost and the O(H((n/m)logm)) cost for the
O(H) wrapping steps. Alternatively, we can choose m = min{Hlog H, n} (or set
H = m~ log m). This choice of m does not affect the former cost except in the lower-
order terms, but it reduces the latter cost from O(n log H) to O(n) and thus results in a
smaller constant factor overall.

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 4. In Hull2D(P) we use the sequence of group sizes m = 22', t = 1, 2 . . . . .


to guess h. The improvements from Ideas 2 and 3 in fact permit us to choose slower
growing sequences and still retain optimal O(n log h) complexity. For example, one
possible sequence is simply m = 2 t, t = 2, 3 . . . . . which corresponds to doubling the
group size after each iteration. Note that a coarser sequence approximates h less well
while a denser sequence requires more iterations, We may try to optimize the worst-case
constant factor and lower-order terms using sequences with different growth rates. We
suggest the sequence m = 2 t:, t = 2, 3 . . . . .

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.

Degeneracies. In both Algorithms Hull2D(P, m, H) and Hull3D(P, m, H) we have


assumed that the points of P are in general position. One way to cope with degenerate
point sets is to apply general perturbation methods such as [12] and [14]; however, these
methods may cause the output size h to increase, as a point that is not a hull vertex but lies
on the hull boundary may become a vertex after perturbation. Thus, it is better to handle
the degenerate cases directly. For Algorithm Hull2D(P, m, H), this is not difficult to do:
when there is more than one point q that maximizes the angle/Pk-1Pkq in line 9, pick
the point q that is farthest from Pk; use the same rule to break ties in line 8.
For Algorithm Hull3D(P, m, H), we can do the following: In line 8 let ej = ajbj
with aj and bj oriented in ccw order around f . When there is more than one point q
that maximizes the angle between f and conv(ej U {q}) in line 12, pick the point q
that maximizes the angle Zbjajq; and if there is still more than one q that achieves the
maximum, pick the one farthest from aj. Use the same rule to break ties in line 11. For
degenerate point set, it is easier to keep track of edges rather than facets, since facets can
be convex polygons rather than triangles. So, make F and Q sets of edges instead, and
in line 15, add the oriented edges bjaj and a ~ to F and Q. Although we may not have
a complete description of the facet incident to these two edges, we know the equation
of the plane containing the facet; this equation is sufficient to perform wrapping about
these edges.
Optimal Output-SensitiveConvexHull Algorithmsin Two and ThreeDimensions 367

5. Extensions

We have presented new optimal output-sensitive convex hull algorithms in E 2 and E 3.


The algorithms are simpler than previous O (n log h) algorithms, particularly in the three-
dimensional case, and the constant factors behind the big-Oh are likely to be smaller
than those of the previous algorithms (in the worst case).
Besides its simplicity, our approach has the advantage that it is applicable to a variety
of other problems. As an illustration, consider the problem of computing the lower
envelope E,(S) of a set S of n line segments in the plane, which we define as the boundary
of Uses ~ where g denotes the unbounded trapezoid conv(s U {(0, +oo)}) for a given
segment s. (Convex hulls correspond to lower envelopes of lines in the dual.) Let h
be the output size, i.e., the number of edges in the envelope; it is known that h is at
most O(not(n)) [16]. Hershberger [17] has given a worst-case optimal algorithm that
computes lower envelopes in O (n log n) time. We now describe how his algorithm can
be made output-sensitive with our technique.
First, observe that we can trace the h edges in s from left to right by performing
h ray-shooting operations, where a ray-shooting operation is: given a ray p emanating
from a point on or beneath s find the first trapezoid ~ (s e S) that p crosses. As such
an operation can be done in O (n) time, this gives us a naive O (nh) method, like Jarvis's
march. To improve the running time, partition S into [n/m] groups each of at most m
segments and compute the lower envelope of each group by Hershberger's algorithm;
this takes O(n log m) time in total. Using known data structures such as [6] and [18], we
can perform ray shooting under each of these In~m] envelopes in O(log m) time after
0 (ma(m)) preprocessing (the ray-shooting methods can be simplified in our case since
envelopes are monotone). This implies that the h ray-shooting operations on/;(S) can be
done in 0 (h ((n/m)log m)) time. Choosing an appropriate group size m and guessing
the output size h give us an optimal output-sensitive O (n log h) algorithm for computing
the lower envelope.
Other applications of our technique can be found in [ 1], including the output-sensitive
construction of higher-dimensional convex hulls and k-levels. In many cases, our group-
ing idea, combined with appropriate data structures, can be used to obtain optimal
O(n logh) algorithms if the output size h is sufficiently small, i.e., if h = o(n ~) for
a suitable constant o~.

Acknowledgments

I wish to thank Jack Snoeyink for his great support and encouragement as well as for his
many valuable suggestions.

References

1. T. M, Chan. Output-sensitiveresults on convexhulls, extreme points, and related problems. Discrete


Comput.Geom.,this issue, pp. 369-387.
2. T. M. Chan, J. Snoeyink,and C.-K. Yap. Output-sensitiveconstructionof polytopesin four dimensions
368 T.M. Chan

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy