On computing approximate convex hulls

On computing approximate convex hulls

Information Processing Letters 16 (1983) 121-126 North-Holland Publishing Company ON COMPUTING 15 April 1983 APPROXIMATE CONVEX HULLS * Eljas SOI...

557KB Sizes 19 Downloads 176 Views

Information Processing Letters 16 (1983) 121-126 North-Holland Publishing Company

ON COMPUTING

15 April 1983

APPROXIMATE

CONVEX HULLS *

Eljas SOISALON-SOININEN Department

of Computer

Science, University of Helsinki,

SF-00250

Helsinki

25, Finland

Communicated by K. Mehlhorn Received 28 July 1982 Revised 7 December 1982

Keywords:

Convex

hulls, approximation

algorithms

1. Introduction The determination of the convex hull of a finite set of points is important in several problems arising in such areas as computer graphics, design automation and operation research. Computing the convex hull may also be needed as a preliminary step in some other geometrical problems. A typical example of this is the determination of the smallest ellipsoid containing all given points it is enough to consider the convex hull [4]. Several algorithms have been presented for computing the convex hull of n planar points in O(n log n) worst case time [3,5,6]. The O(n log n) worst case time bound has also been achieved in three dimensions [5]. On the other hand, it has been showed that !J(n log n) is the lower bound for planar convex hull computation [6,7]. The expected complexity of computing convex hulls has been considered by Bentley and Shamos [2], who showed that the hull of n points in two and three dimensions can be computed in linear time for a large class of probability distributions. Recently, still another approach has been taken for convex hull computation: Bentley, Faust and Preparata [I] presented a linear time algorithm for

* This work was supported by the Academy of Finland and by the Alexander von Humboldt Foundation while the author was visiting the University of Karlsruhe, Karlsruhe, Fed. Rep. Germany.

0020-0190/83/$03.00

0 1983 North-Holland

computing an approximate convex hull in two-dimensional space. That is, given a points in the plane, a polygon with vertices in this point set is determined in time O(n) such that this polygon is arbitrarily close to the true convex hull of the point set. This planar approximation algorithm is further generalized in [l] to computing hulls of point sets in higher dimensions but a similar efficiency is not obtained. The approximation method of [l] is rather sensitive to the uneven distribution of points in the given point set. That is, to obtain the required accuracy extra work may be needed also in those parts of the point set where a much less accurate approach would lead to the correct selection of hull points. In this note we modify the approximation scheme of [I] in such a way that we obtain a criterion which depends on the required accuracy and which selects edges of the computed approximate hull such that ‘behind’ these edges no points can lie. This makes it then possible to improve the accuracy without considering selected areas, and through repeated processing even arrive at the true convex hull by efficient approximation technique.

2. The planar approximation algorithm using strips In this section we describe the basic algorithm by Bentley, Faust and Preparata [l] for computing 121

Volume

16. Number

INFORMATION

3

1

l

a)

PROCESSING

l

l l

l

l

l

0

l

0 l

l

0

l

0

l

l

l

l

‘b)

15

April 1983

step of the algorithm the points with the minimum and maximum x-values are determined. Then the area between these points is divided into k equally spaced strips. The strips are parallel to the y-axis. The next step is to determine for each strip the points with the maximum and the minimum yvalue in this strip. These points plus the points with extreme x-values (if there is more than one point with an extreme x-value, then the highest and the lowest of these are taken into account) form the set S, the convex hull of which is finally constructed. This convex hull is used as an approximate hull for the original point set. Observe that in the example of Fig. 1 two points lie outside the approximate convex hull. The above scheme is easily programmed as is done in [ 11, and the program requires O(n + k) time, where n is the number of original points and k the number of strips. The key issue here is that the points of S are accessed in the order sorted by the x-values and thus the convex hull of S can be constructed in O(k) time [6]. It should be observed that the approximate convex hull indeed is a subset of the true hull, and thus any point inside the approximate hull is also inside the true hull. It is also easily shown (see [ 11) that if w is the width of a single strip, then any point in the original point set not inside the approximate hull is within distance w of the hull. Thus if the distance between the minimum and maximum x-values is unity, then any point that is not inside the approximate hull is within distance l/k of the hull.

1 1 El

El

El

l

l

l

.

I3

El

l

6

l

cl

\

l

l

Fig. 1. An approximation algorithm for convex hulls in the plane. (a) Place points in bin; (b) Find extremes in bins; (c) Build hull of extremes.

an approximate convex hull of a planar point set. The idea in the algorithm is simply to select a sample of the given point set and to compute the convex hull of the selected sample. To guarantee the required accuracy, the selection of points must be done evenly, and to guarantee efficiency the selection process should imply a regular structure for the sample. The process is illustrated in Fig. 1. As the first 122

LETTERS

3. A modification

of the planar algorithm

In this section we modify the approximation scheme of [l] such that strips are drawn in two directions. That is, we will have strips parallel to the y-axis as well as strips parallel to the x-axis. If we have k equally spaced strips in both directions, we loose some of the accuracy compared to 2k strips in one direction (1/(2k) versus fi/(2k)) but we will be able to analyze the approximation in more detail. If a point is almost &/(2k) units outside the approximate hull, then the two hull vertices ‘between’ which this point lies must be

Volume 16, Number 3 1

INFORMATION 3

2

c

.

a)

L

I

6

5 l

l l

l

3

l

.

l l

2

0

l

l l

0 1

l

l

l--T-tT m

bl

Fig. 2. (a) Place points in orthogonal bins. (b) Find extremes in bins. Extremes in y-values as well as the points with the maximum and the minimum x-values (not taken into account in determining the extremes) are denoted by squares, and circles are used in the horizontal case. (c) Build hull of extremes.

close to each other. In fact, we can show that if for two consecutive hull vertices (x,, y,) and (x,, yz) the conditions

hold,

then no point

outside

the approximate

hull

PROCESSING LETTERS

15 April 1983

lies in the rectangle having (x,, y,) and (x2, yz) as opposite corner points. Our modified approximation scheme is illustrated in Fig. 2. The first step of our algorithm finds the minimum and the maximum values in the x-dimension as well as in the y-dimension. Then we divide the area between the points with extreme x-values into k, equally spaced strips, and the area between the points with extreme y-values into k, equally spaced strips (see Fig. 2(a)). Next we behave exactly as in the algorithm of [l] and form the set S. This set, now denoted by S,, contains the points with maximum and minimum y-values in each strip parallel to the y-axis and the corresponding extreme points, that is, at most 2k, + 4 points. Next we construct the set S, with at most 2k, + 4 points in the exactly analogous way but now applied to the strips parallel to the x-axis (see Fig. 2(b)). Finally, we compute the convex hull of S, U S, and use it as an approximation of the convex hull of the whole point set. Up to computing the sets S, and S, we thus only use the algorithm of [ 11. S, will be implemented by two vectors YMAX[O : k, + l] and YMIN(O: k, + 11, where the points with maximum and minimum y-values are stored in cells YMAX[ 11,. . , YMAX[k,] and YMIN[ 11,. . . , YMIN[k,], respectively. The points with extreme x-values are stored in YMAX[O], YMIN[O], YMAX[k, + l] and YMIN[k, + 11. If there is only one point with the minimum x-value, then both YMAX[O] and YMIN[O] contain this point. Otherwise YMAX[O] contains the one with the maximum y-value and YMIN[O] with the minimum y-value. The contents of YMAX[k, + l] and YMIN[k, + l] are obtained similarly but now using the points with the maximum x-value. The set S, will be implemented by two vectors XMAX[O : k, + l] and XMIN[O : k, + l] in the analogous way. The points in vector YMAX as well as in vector YMIN are in the ascending order by the x-values. Thus the convex hull computation of S, can be done efficiently in O(k,) time (see [l]). Similarly, the points in vectors XMAX and XMIN are in the ascending order by the y-values, and the convex hull of S, can be constructed in O(k,) time. Our problem is now to design an algorithm to construct the convex hull of S, u S, in O(k, + k2) 123

Volume

16, Number

3

INFORMATION

PROCESSING

time. This can be done in the following way. First we determine the index i such that XMAX[i] = YMAX[k, + 11. Then those points of XMAX[k* + ll,..., XMAX[i], which will be vertices of the convex hull of S, U S, lie sorted by the x-values in the ascending order. That is, if, for j > i, XMAX~~] is a vertex of the hull (XMAX[kz + l] certainly is), then XMAX~ - l] definitely cannot be a vertex of the hull if the x-value of XMAX~ - l] is smaller than the x-value of XMAXL~].This means that we can screen out those points which cannot affect the convex hull computation in such a way that we are left with points sorted by the x-values. In other words, we only consider those points XMAX~~], k, + 1 > j > i, such that the x-value of all XMAX~~‘],j’ > j, is no greater than the x-value of XMAXLj].

We also determine the index i such that XMrN[i] = YMAX[O], and then screen out those points of XMIN[i], . . . , XMIN[k* + l] which violate the ascending order by the x-values of the points. Altogether we are left with a set of points in the ascending order by the x-values such that the set contains all those points of the vectors XMAX and XMIN which may contribute to the convex hull computation of S, U S, above the points YMAX[O]and YMAX[k, + 11. This point set can then be merged with the points in the vector YMAX resulting in a vector MAX[O: I+ 11, &< k, + k,, where MAX[O]= YMAX[O] and MAX[l+ 1] = YMAX[k, + 11. In the exactly analogous way we construct a set of points in the ascending order by the x-values such that the set contains all those points of the vectors XMIN and XMAX which may contribute to the convex hull computation of S, U S, below the points YMIN[O] and YMIN[k, + 11. This point set can be merged with the points in the vector YMIN resulting in a vector MIN[O: P+ 11, 16 k, + k,, where MIN[O] = YMIN[O] and MIN[& + l] = YMIN[k, + I]. Both the vectors MAX and MIN are constructed in O(k, + k,) time and contain points sorted by the x-values. Thus the convex hull of S, U S, can be determined by the technique of [l] in O(k, + k2) time. This means that all computation time required is O(n + k, + k,), where O(n) is needed for constructing S, and S,, or O(n + k), if we denote k = max{k,, k,}. 124

LETTERS

15 April 1983

4. Analysis of the orthogonal strip approximation scheme In this section we investigate how accurate approximations the algorithm of the previous section actually produces. Specifically, we are able to analyze the approximation as regards the possible location of those areas of the approximate hull which are different from the true hull. First of all it is clear that the produced approximation is conservative in the sense that every point in the approximate convex hull is also within the true hull. (Note that the variations of the basic approximation scheme of Bentley, Faust and Preparata given in [l] and producing non-conservative approximations are easily defined in our orthogonal strip scheme, too.) We thus have to answer the question how far a point outside the approximate hull but within the true hull can lie from the approximate hull. Assume that the distance between the maximum and minimum x-values in the given point set is D, units, and k, strips parallel to the y-axis have been used. Similarly assume that the distance between the maximum and minimum y-values is D, units and k, strips parallel to the x-axis have been used. We have the following theorem. Theorem 1. Any point p in the given point set that is not inside the approximate convex hull is within distance D,D,//~ of the hull. In particular, if max(D,, D,} is unity and max(k,, k,} is denoted by k, then this distance is < fi/(2k). Proof. Let p = (x, y) be a point in the point set which lies outside the approximate convex hull, and let qymax = (xymax, Y,,,,) and qymln = (xymln, yymin) be the points with the maximum and the minimum y-value in the strip which is parallel to the y-axis and in which p lies. Then yy min < y < if qxmin=(~xmin, y,,i,) and Y,,,X. Similarly q xmax = (x xmax, YXmax) are the points with the minimum and the maximum x-value in the strip which is parallel to the x-axis and in which p lies, then x,,,,~” -C x < x,,,,.

Volume

16. Number

INFORMATION

3

PROCESSING

15 April 1983

LElTERS

lies outside the hull, and XI = x 2

and

y’= y,,

if triangle

lies -outside the hull. Triangle Fig. 3. Intersection are extreme points

of two strips. The vertices of the polygon in the strips.

Q

Y2>7 (x',Y’>)

Ux I, Y,>> (x2,

is called the error triangle of ((x,, y,), (x2, y2)). Now, because p = (x, y) is outside the approximate hull, it must lie outside the polygon Q with vertices qymax, qymin, qxmax and qXmrn. Further, because p lies in the intersection I of the strips with extremes qymax, qymin and q,,,,, q xmin, the greatest possible distance between p and Q occurs when two vertices of Q are opposite corner points of I (see Fig. 3). Because the strips are D,/k, and D,/k, units wide, it is a simple task to calculate that p is within distance D,D,/im

of the line joining

these

two vertices of Q. Because Q must be included in the approximate hull, we thus obtain the first statement of the theorem. The second statement 0 immediately follows from the first. We next depending outside the given edge description approximate

show that under a certain condition on the width of the strips no point approximate hull can lie close to a of the hull. We first give a general of the areas where points outside the hull can lie.

Theorem 2. If p is a point outside the approximate hull, then it must lie in a triangle of the form

(b

I,

Yl>? (x2,Yz),

(x’, Y'>L

where ((x,, y,), (x,, y2)) is an edge of the approximate hull and for (x’, y’) the following condition holds: x)=x,

and

y’=y2,

Proof. A point p outside the error triangles simply contradicts the construction method of the approximate hull, which is based on the determination of extremes in the strips. Namely, p should in any case be an extreme point, if it lies outside the error triangles. 0 Now some of the error out in the following way.

triangles

can be ruled

Theorem 3. Let (q,, q2) be an edge of the approximate convex hull. Zf q, and q2 are not in the same strip in either direction, then no point outside the approximate hull can lie in the error triangle of (S,? 92). (For illustration,

see Fig. 4.)

Proof. It is easily seen that points lying in the error triangle of (q,, q2) would contradict the fact that (q,, q2) is an edge of the approximate hull. In any case, because q, and q2 are lying in different strips in both directions, these points must include an extreme in some strip. This extreme point would mean that (q,, q2) cannot be an edge of this approximate hull. q Because the strips parallel to the y-axis (the x-axis) are D/k, (D2/k2) units wide, we obtain the following corollary. Corollary 4. Let (q,, q2) be an edge of the approximate convex hull, where q, = (x,, y,) and q2 = (x,9 Y2>.Zf

if triangle

D, lx,

-x21>k

1

and

IY,-y21>k,

D2 2

125

Volume

16, Number

3

INFORMATION

PROCESSING

c

Fig. 4. Part of an approximate hull. In the shaded area no point of the given point set can lie: by Theorem 2 not outside the error triangle of (q,, qa) and by Theorem 3 not in the error triangle of (q,, q2) because q, and q2 are not in the same strip in either direction. Note that above (p,, pz) there is a point outside the approximate hull. This is possible because p, and pa are in the same strip in one direction.

then no point outside the approximate the error triangle of (q,, q2).

hull can lie in

The advantage of our approximation method is that we may start with a rather robust approximation and then make it more accurate only in those areas which possibly can contain new constributions to the hull. Our method using orthogonal strips actually divides the area in question into rectangles of equal size and form. Only those rectangles which are cut by the approximate hull can contain points that lie outside the approximate hull (these rectangles are easily determined while constructing the approximate hull). If a rectangle cut by the approximate hull is divided into two parts by an edge of the hull the error triangle of which cannot contain any point (by Theorem 3), then this rectangle obviously need not be considered. For more accuracy all other rectangles cut by the approximate hull are treated by dividing them into orthogonal strips and computing the new extremes (only for those old extremes that are present in the rectangle in question). The new approximate hull is then computed

126

LETTERS

15 April 1983

using the new extremes and the vertices of the old approximate hull. We can also determine the true hull such that as an intermediate result an approximate hull is computed. In the same way as above we select the rectangles which can contain new contributions to the hull and then compute the convex hull of the set containing (i) all points in the selected rectangles, and (ii) all vertices of the approximate hull. The extension of our 2-space approximation method into d-space should be straightforward. In 2-space we divided the area in question into rectangles using strips such that extremes are determined in orthogonal bins. In d-space we divide the area into d-dimensional hyper-rectangles and determine the extremes in d directions. Then we only compute the convex hull of these extremes. It should be noted that there is no straightforward way to make use of the regular structure of these extreme points - in contrast to the two-dimensional case - in order to simplify the computation of the convex hull (cf. [I]).

References [1] J.L. Bentley, M.G. Faust and F.P. Preparata, Approximation algorithms for convex hulls, Comm. ACM 25( 1) (1982) 64-68. [2] J.L. Bentley and M.I. Shamos, Divide-and-conquer for linear expected time, Inform. Process. Lett. 7(2) (1978) 87-91. [3] R.L. Graham, An efficient algorithm for determining the convex hull of a finite planar set, Inform. Process. Lett. 1 (1972) 132-133. [4] M.J. Post. A minimum spanning ellipse algorithm, Conf. Record 22nd Symp. on Foundations of Computer Science (1981) pp. 115-122. [5] F.P. Preparata and S.J. Hong, Convex hulls of finite sets of points in two and three dimensions. Comm. ACM 20(2) (1977) 87-93. [6] M.I. Shamos, Computational geometry. Ph.D. Thesis, Yale University, New Haven, Connecticut, 1978. [7] A.C. Yao, A lower bound to finding convex hulls, J. ACM 28(4) (198 I) 780-787.