You are on page 1of 3

Volume 7, number 1 INFORMATION PROCESSING LETTERS q January 197g

A REEVALUATION OF AN EFFICIENT AI.GORITHM FOR DETERMINING


THE CONVEX HULL OF A FINITE PLANAR SET

Kenneth R. ANDERSON
Dept. Earth and PlanetarySciences, Massadwei~s Institute of Technology, Chnbridie, MA 02139, USA

Received 3 Janwuy 1977; revised version received 20 Ob&ober 1977

Convex hull algorithm, structure programming

I Introduction

Graham [l] proposed an algorithm for determining


the convex hull of a finite set of points in the plane
which takes no more than N log2 (N)l + CN “opera-
tions”, where N is the number of points in the set.
Jarvis [2] pointed out that Cin Graham’s algorithm
is actually quite large and developed an algorithm
which takes at most A@¶ + 1) simpler operations,
where Mis the number of points on the hull. This
paper presents a reevaluation of Graham’s algorithm
which shows it to be much more efficient than it
appears from his description. The basic conclusion is m

that although angles are obviously useful for describ- Fig. 1.


ing an algorithm, sines and cosines are usually a more
“natural” representation computationally.
between the x axis and a ray drawn between the
points i and m. At the same time, remove from S any
2. Convex hull algorithm points at the same location as m. If there is more than
one point on any ray, i.e. 8i =cOi+r, remove the point
The following notation is adopted: S is a set of closer to m.
points. Each point, i, in S has x and y coordinates xi 8i is used to define two functions, clock(i) and
and yj respectively. Points will be deleted from S as cclock(i). clock(i) returns the next point of S clock-
the algorithm progresses until only the extreme points wise from i. cclock(i) returns the next point in S
of the hull remain. counter-clockwise from i.
The ordered points remaining in S (taken cyclical
Step 1. Find the point, m, in S which is the bottom- ly) can be considered the vertices of a polygon as
most point. If there is more than one such point, shown Ly the dotted outline in Fig. 1. This polygon
choose the leftmost. Thus all points in S are either is not necessarily convex. A polygon can be made
above or .to the right of m. convex by removing its concave vertices. (A vc rtex
is concave if its interior angle > 7r.)The object og
Step 2. Order the points, except m, by the angle 8i, Step 4 below is to successively remove such vertices

53
V&ms3, number 1 INFORMATION PROCESSING LETTERS January 1970

until only the vertices of the convex huh remain as method that will produce an equivalent ordering.
&owl; by the solid outline in Fig. Il. Jarvis [2] pointed out that rather than evaluating
the arctangent to determine the angle, the points may
Step 3. Let i = m, j = cclock(~), and k = cclock(j). be ordered properly by using only their tangents.
However, care must be taken to avoid dividing by
Step 4, Do the following whae k is not equal to mr. zero. An alternative approach is to order by -sign(cos
(0)) cos*(O)which can be evaluated in 2 multiplica-
If point j is not an concave vertex, it is possibly an tions, 1 division and 2 subtractiaxrsusing:
extreme point of the hull. Let i = j, j = k, arrd k =
cclock(J:). -sign(x - x,)& - x,)*
-sign(cos (0)) cos2(t9)= -s
Othcrsie, point j cannot be an extreme pdnt of (x - x,,)* + (y - JQ* ’ (l)
the hull. Remove j from S. Let j = i and i = clock(i).
This is to check if any point tentatively retained in S Division by zero can be eliminated since any point
as a possible extreme point can now be removed .
coincident with m need not be considered further.
Tangents need not be used since Step 1 guarantees
from S.
At the completion of Step 4, S will contain the that n>8 20.
extreme points of the hull. k will be set equal to Graham’s concavity test was originally written in
every point in S, except m and cclock(m), at least terms of the angles (k j m) and (:ij m). The order im-
once during Step 4, and every point not in the hull posed on the points in Step 2 reduces this to deter-
will cause another point to be reexamined. Thus Step mining if j is on the same side 01’the line (j k) as m is.
4 will be done at most (Iv - 2) + (IV- M’)times. This can be done in 2 multipiica tions and 4 subtrac-
tions as:

if C-X]
- XI)@R- Yt) > @i - Y&Q - Xi) 9 (2)
3. Discussion and &inement
then j is on the other side of the line.
It is useful to think of an algorithm, whether Determining which of two pr#nts on the same ray,
expressed in English or in a programming language, j or k is farthest from m can be {Determined
by:
as 2 description of 2 process [3]. For example, even iryk >yj Or & =yj andxk >Xf), (3)
though Step 2 says essentially to “draw 2 ray*‘, we
realize that this is only 2 convenient geometrical &en k is farther from m.
description of what is to be done. The ray would Here use was made of the fat t that all points in S
never be drawn in practice on a computer. Although are either above or to the right of m
it is obvious that one can avoid drawing rays, it is not Thus a careful analysis of Griham’s algorithm
so obvious that one can avoid computing angles. When shows that it is much less difficult to compute than
implementing or describing an algorithm, it is impor- is first apparent. Excluding the ordering process which j
tant to distinguish between those parts which are takes O(N log2 (N)) operations, be rest of the algo-
incidental and those which are necessary. With this rithm can be performed in at most 6 multiplications,
in mind, let us consider wtlat refinements can be made 1 division, and 10 subtractions F$erpoint.
to the algorithm described above and compare it to A comment on the presen tati on of algorithms is
ti e original Graham algorithm. We will find that his in order. Following the guide lines of structured pro-
description actually hides its computational simplicity. gramming, the description of an algorithm should be
Graham initially searches for a point inside the thought of as the first step in thy top-down design
hull t make his new origin. He does this by finding of a structured program which will become the im-
3 points that are not coiint:ar and using the center of plementation of the algorithm. I~Sthe first step, it
gravity of thestl points 2s the origin. Choosing inste;id should be a clear presentation of‘the basic method.
2 point on the hull, such 2s m in Step 1, is a distinct Graham presents a clean, easily undsrstood descrip
advantage in the computation of Steps 2 and 4. tion of his method, but does not provide any hint as
Rather than ixdering by angle, one may use any to how it might be implemented efficiently. After

54
Volume 7, number 1 INFORMATDN ?k,::SS?NC LETTERS JanuaIy 1978

the initial presentation, each step should be refined B.K.P. Hcrrn in his course “Makingmachines see alld
as necess8ry to expand on complex substeps, show feel”. I wolrld fike to thank Peter Neilson, Jack Sax,
which parts of the algorithm interact strongly, which and Bob Walton for critically previewingthe manu-
parts are absolutely necessary, and which parts can script. Computational facilities were provided by the
be implemented efficiently with special techniques. Uncoln Laboratory, Applied SeismologyCroup,
This approach of presenting an algorithm as a set of M.I.T.6
successiverefinements is followed by this paper and
that of Jarvis [2].
When this paper was submitted for publication, a
reviewerpointed out that Preparata and Hong [4] References
showed that for two and three dimensions the com-
plexity of the hull problem is O(N log&V)). Graham R.L. Graham, An efficient algorithm for deterniiing
showed that at least for two dimensions this com- the convex hull of a fmite p&&r set, information Pk
plexity can be decomposed into two parts, one for cessing Lett. 1(1972) 132-133.
ordering which is O(N log8(/V))and the other for R.A.J&s, On the identification of the convex hull of
actually determining the hull which is O(N). a ftite set of points in the plane, Information Processing
Lett. 2 (1973) 18-21.
P.J. Hayes, Computer programming as a cognitive para-
Adcnowkdgements digm, Nature 254 (1975) 563-566.
F.P. Preparata and S.J. Hong, Convex hulls of ftite sets
That the evaluation of trigonometric’function can of points Qwo and three dimensions, C.A.C.M. 20 (2)
sometimes be avoided w8s first pointed out to me by (1977) 87-93.

You might also like