An Optimal Algorithm for Finding the Kernel of a... K(P)

advertisement
An Optimal Algorithm for Finding the Kernel of a Polygon
D. T. LEE AND F. P. PREPARATA
Umverstty of llhnots at Urbana-Champatgn, Urbana, llhnots
ABSTRACT The kernel K(P) of a simple polygon P wah n verUces is the locus of the points internal to P from
which all verUcesof P are wslble Equwalently, K(P) is the mtersectmn of appropriate half-planes determined by
the polygon's edges Although it is known that to find the intersection of n generic half-planes requires time
O(n log n), we show that one can exploit the ordering of the half-planes corresponding to the sequence of the
polygon's edges to obtain a kernel finding algorithm which runs m time O(n) and is therefore optimal
KEYWORDSANDPHRASES computatmnal complexay, optimal algorithms, simple polygon, kernel of polygon
CR CATEGORIES 4 49, 5 25, 5 32
1. Introduction
T h e kernel K(P) o f a simple polygon P is the locus o f the points internal to P which can be
j o i n e d to every vertex o f P by a segment totally contained in P. Equivalently, if one
considers the b o u n d a r y o f P as a counterclockwise directed cycle, the kernel o f P is the
intersection o f all the half-planes lying to the left o f the polygon's edges.
Shamos and H o e y [1] have presented an algorithm for finding the kernel o f an n-edge
polygon in time O(n log n). T h e i r algorithm is based on the fact that the intersection o f n
generic half-planes can be found in time O(n log n); they also show that fl(n log n) is a
lower b o u n d to the time for finding the intersection o f n half-planes. H o w e v e r , this lower
b o u n d does not apply to the p r o b l e m o f finding the kernel, since in the latter case the halfplanes are ordered according to the sequence of the edges o f P, nor does their algorithm
take advantage o f this order. In this note we shall show that, indeed, this ordering can be
exploited to yield an algorithm which runs in time linear in the n u m b e r o f the edges.
Obviously, since each edge must be examined, the time o f our algorithm is o p t i m a l within
a multiplicative constant.
T h e m o d e l o f c o m p u t a t i o n used for the above results, which we shall also adopt in this
paper, is a random-access m a c h i n e ( R A M ) w a h r e a l - n u m b e r arithmetic, i.e. with the
capability o f performing comparisons o f real numbers and rational operations on real
numbers.
T h e input polygon P is represented by a sequence o f vertices Vo, vl . . . . . vn-l, with n _> 4,
in which each v, has real-valued x- and y-coordinates (x,, y,), and (v,-1, v,) (see F o o t n o t e
1), for i = 1, 2 . . . . . n, is the edge o f the polygon connecting vertices v,_~ and v,. F o r ease o f
reference we shall describe P by a circular list o f vertices and intervening edges as
voe~v~e2 ... en-lvn-leovo, where e, = (v,_~, v,). W e also Impose a direction u p o n each edge
Permission to copy without fee all or part of this material is granted provided that the copies are not made or
distributed for direct commercial advantage, the ACM copyright notice and the tale of the pubhcatlon and its
date appear, and noUce is gwen that copying is by permission of the Assooatlon for Computing Machinery To
copy otherwise, or to republish, requires a fee and/or specific permission
This work was supported by the National Science Foundation under Grant MCS 76-17321 and by the Joint
Services Electronics Program under Contract DAAB-07-72-C-0259
Authors' present addresses D T Lee, Department of Electncal Engineering and Computer Science, Northwestern
Umverslty, Evanston, IL 60201, F.P Preparata, Coordinated Science Laboratory, UmversRy of llhnots at
Urbana-Champalgn, Urbana, IL 61801
All radices are taken modulo n
© 1979 ACM 0004-5411/79/0700-0415 $00 75
Journal of the Association for Computmg Machinery, Vol 26, No 3, July 1979, pp 415.-421
416
D. T. LEE AND F. P. PREPARATA
vi
fi
jJ
t I
/
~
vn-I
/
Kx
FIG !
Illustrationof the definitionof F, and L,
F]G 2
Illustrationof polygon Kj
such that the interior of the polygon hes to the left oi~ the edge, or, eqmvalently, the
boundary of P is directed counterclockwise. A vertex v, is called reflex ff v,+~ hes to the
right of the line containing e, and directed like e,, that is, if the interior angle at v, is larger
than 180°; a vertex is called convex otherwise. We also assume that the intenor angle at a
convex vertex v, be strictly smaller than 180°, since the elimination of straight-angle
vemces does not change P and can be done by a preliminary scan of the boundary of P in
time O(n). It is obvious that the kernel of P, being the intersection of half-planes, is a
convex polygon K(P) and is bounded by at most n edges. Thus if the kernel is nonempty,
the output will also be represented by the sequence of vemces and edges of the polygon
K(P).
2. The Algorithm
The algorithm we shall outline scans in order the vertices of P and construct a sequence of
convex polygons KI, K2. . . . . Kn-1. Each of these polygons may or may not be bounded. We
shall later show (Lemma 1) that K, is the common intersection of the half-planes lying to
the left of the &rected edges e0, e~, ... , e,. This result has the obvious consequences that
K , - i = K(P) and that K1 D K2 D ... _D K,; the latter implies that there is some r > 1 such
that K, is u n b o u n d e d or bounded depending upon whether t < r or i _> r, respectively.
Notationally, if points w, and w,+~ belong to the line containing the edge % of P, then
w,esw,+x denotes the segment between w, and w,+~ with the same direction as e , . When a
polygon K, is unbounded, two of its edges are half-hnes; so, A e w denotes a half-line
terminating at point w and directed like edge e, while weA denotes the complementary
half-line.
During the processing, the boundary of K is maintained as a doubly hnked hst of
vertices and intervening edges. This list will be either linear or circular, depending upon
whether K, is u n b o u n d e d or bounded, respectively. In the first case, the first and last item
of the list will be called the list head and list tail, respectively.
Among the vertices of Ks we distmgmsh two vertices F, and L,, defined as follows.
Consider the two lines of support 2 of K, through vertex v, of P. Letf~ and l, be the two halflines of these hnes which contain the points of support, named so that the clockwise angle
from f, to l, in the plane wedge containing K, is no greater than ,r (Figure l). Vertex F, is
the point common to f, and K, which is farthest from v,; L, is slmdarly defined. These two
vertices play a crucial role in the construction of K,+i from K,.
If P has no reflex vertex, then P is convex and trivially K(P) = P. Thus let vo be a reflex
vertex of P. We can now describe the kernel algorithm.
Inmal Step We set K~ equal to the intersectionof the half-planeslying to the left of edges e0 and e~, i e K1 *Ae;voeoA (Figure 2) F1 ~ point at infinityof Aelv0, L1 ~ point at Infinityof VoeoA
2Recall that l is a line of support of a polygonP if l has at least one point In commonwith P and the interiorof
P entirelylies on one side of l
Download