Professional Documents
Culture Documents
A Linear Algorithm For Incremental Digital Display of Circular Arcs
A Linear Algorithm For Incremental Digital Display of Circular Arcs
Introduction
Copyright © 1977, Association for Computing Machinery, Inc. will be used. The extension to complete the full circle
General permission to republish, but not for profit, all or part will then be described as will the modifications required
of this material is granted provided that A C M ' s copyright notice to accomodate an arbitrary arc of the general circle
is given and that reference is made to the publication, to its date
of issue, and to the fact that reprinting privileges were granted given by
by permission of the Association for Computing Machinery. ( x - - a) 2 + ( y - - b) 2 = r 2
Author's address: IBM System Communications Division,
1000 Westchester Avenue, White Plains, NY 10604. with starting point (x~, y,) and terminating point
* Editor when the paper w a s being processed; J. Foley is now
editor of this department. (xt, yt) specified on circumference.
6 = 2 { [ ( X + 1)2 + ( Y - - l) 2 ] - R 2} + 2 Y - - 1.
where a [ b is b modulo a.
Alternatively, movement can be coded as a 2-tuple
of delta abscissa and ordinate (Ax, Ay) increments 1,
this case the above steps yield 8 > 0 and 6' < 0 so a 0, or --1. With initial conditions of M10 = (1, 0),
proper m2 move is forced by either calculation. M20 = (1, --1), and M30 = (0, --1), one can observe
that at each quadrant crossing the clockwise movement
By noting the expansions code reinitialization is
(X+ 1)2 = X ~ + 2 X + 1, ( Y - - 1)2 = y 2 _ 2 y + 1,
Mlj+x ~ M3j, M2i+l ~-- (M212b, --M2[1]j),
the difference A~ and the coordinates of the display M3~.+1 *-- (M312]s, - M 3 [ l b ) .
point P~ are observed to have the following recurrence To adapt the above basic algorithm ~ for arbitrary
relations: circular arcs having noninteger radii and center points,
(i) For m: movement (i.e. A~ < 0 and ~ _< 0), initialization must be considered in more detail. The
Xi+: = X i JU 1,
general circle will be (x -- a) 2 + (y -- b) 2 = r 2 with a
Yi+: Y~ ,
=
starting point ( x , , ys) and terminating point (x~, yt)
Ai+: -- Ai + 2X~+: + 1. given on the circumference. Direction of rotation will
be clockwise (D = 1) or counterclockwise (D = -- 1).
(ii) For m2 movement (i.e. A~ < 0 and 6 > 0, or As the path to be calculated must consist of integer
/x~ >_ 0 and 6' < 0), mesh points, it is necessary to determine the mesh
Xi+l = Xi + 1, points closest to the starting and terminating points.
Y~+I = Y ~ - - I, Any point (x, y) on the circumference lies within a unit
Ai+I = A i "-1- 2 X i + l - - 2Yi+: + 2. square having mesh point corners of
(ii) For m3 movement (i.e. A~ > 0 and 6' > 0), c: {(txj, lyJ) (txJ, [yl) ([xl, tyJ) ([xl,ryl)}
Xi+l = Xi , where [xJ is the greatest integer equal to or less than x
Yi+1 = Y i - 1, and [x] is the least integer equal to or greater than x.
Ai+: = /x i - 2 Y I + : + 1. If x a n d / o r y are integers, the unit square degenerates
to a single point or a unit length line and the four
If the circle is started at one of the four intersections member set C will contain only one or two unique
of the true circle with the coordinate axes, there is no elements. The closest mesh point (X', Y') is that point
need to consider any second-order terms in the initial from C which minimizes the difference:
conditions. If the circle starts at the point (X0 = 0,
Y0 = R), then [(x' - a) 2 4- (y' - b) 2 -- r=l (x', y') 3 C.
A0 = [ ( X o + 1)2 + ( Y 0 - - 1)2] -- R 2 = 2 - - 2R Translating the closest mesh points to an origin coinci-
dent with the center of the circle then gives closest
and the full first-quadrant clockwise quarter arc will be starting and terminating points of
complete when Yi = 0 or, alternatively, when Y~ < ½.
T o complete the remaining three quarter arcs, the i,~ = X , ' - - a , 1~ = Y ; - - b ,
movement values m l , m2, and m3 are respecified ~t = X/ - - a, 17t = Y/ - - b.
appropriately; the algorithm is reinitialized and is
A flow chart for the basic integer, full circle case [3] which
repeated with the same logic as before until the com- takes advantage of the control format codes for incremental digital
plete circle is drawn. When crossing a quadrant bound- plotting with the IBM 1627is shown in Figure 3.
3. Algorithm
(9
®l D
G i v e n the .arc's starting a n d t e r m i n a t i n g points,
( x , , y,) a n d ( x t , y t ) , on the circle circumference to-
gether with the circle's center p o i n t (a, b) a n d d i r e c t i o n
PLOTTERCONTROLDIGITS o f r o t a t i o n (D), the d i s p l a y mesh p o i n t selection algo-
r i t h m can be s u m m a r i z e d as follows for the general
case:
~ NO
YES~ Notation
X~ is the "constrained circle's" translated abscissa value at the
ith step of normalized clockwise movement in the first quad-
rant.
Y~ is the "constrained circle's" translated ordinate value at the
ith step of normalized clockwise movement in the first quad-
rant.
O.i is the number of quadrants remaining to be traversed.
MI represents relative 0° movement for normalized clockwise,
Y NO
Y~'~ -2
first-quadrant incrementation.
M3 represents relative 270° movement for normalized clockwise,
first-quadrant incrementation.
A~ isthesigned difference {[(Xi+l) 2 + (Yi-1) 2] - R2]}. The sign
of ,5~ indicates whether the point (X~+I, Y~--I) is inside or
outside of the true circle.
a is the signed difference {[(X~+I) ~ q- y~2] _ R ~] + ,a~. The
sign of a indicates which of the two points (X~+I, Y)
or (X~+I, Y~--1) is closest to the true circle.
a' is the signed difference {[X,.+(Yi-1)~J - R 2} --F Ai. The
sign of a' indicates which of the two points (X~, Y~-I) or
(X~+I, Y~- 1) is closest to the true circle.
Initialization
Since all c a l c u l a t i o n s are b a s e d u p o n a s t a n d a r d
1. Determine closest mesh points (X/, Y/) and (Xt', Y,') from
first q u a d r a n t clockwise ease, it is necessary to t r a n s f o r m (x,, y,) and (xt, yt) by finding their respective unit square
a n y o t h e r situation to the n o r m a l i z e d case. T a b l e I corner mesh points from C, and Ct which minimize
gives the t r a n s f o r m a t i o n to o b t a i n ( X s , Y,) a n d
[ [(x'--a)~ + (.v'-b) 2] -- [ ( x - a ) ~ + ( y - b ) 2] [
( X t , Yt) f r o m ( o , ~ ) a n d ( ~ t , l~t). T a b l e I also
gives a q u a d r a n t i n d i c a t o r , q, f r o m which the n u m b e r from C(x', y'): {([xJ, [yJ) (lxl, [y]) (Ix], tyJ) (Ix], [y]) }.
o f q u a d r a n t crossings between the two p o i n t s can be 2. Translate to zero centered circle coordinates:
d e t e r m i n e d t o g e t h e r with the initial m o v e m e n t c o d e s
.~, = Xo' - a, ~:, = Y / -- b, Xt = Xt' -- a, ~:, = Y,' -- b.
a s s o c i a t e d with an a r b i t r a r y point.
T h e n u m b e r o f q u a d r a n t crossings is first c a l c u l a t e d 3. Transform ( ~ , , ~ ) and (Xt, ~t) to normalized, first quadrant,
as f o l l o w s : clockwise coordinates per Table I to determine
X, = X0, Y, = Y0, q,, MI, = M10, M2o = M2o,
Q* = 4 1 ( q, - q,), M3o = M30, andXt, Yt, qt.
then, to consider Q* = 0, the possible a m b i g u i t y is 4. Calculate the number of quadrant crossings from Q* =
resolved b y : 41 (q,-q,) as
(a) Q = Q* - 1 if Q* ~ 0, or if Q* = 0 a n d Q0 = 3, if Q* = 0 a n d X t <_ X, andYt>_ Y°,
either X , >_ X~ a n d Y t < Y , or X t > X , a n d Y t <_ Y , ; Q0 = Q* - 1, otherwise.
T a b l e I. T r a n s f o r m a t i o n T a b l e : N o r m a l i z e to S t a n d a r d C l o c k w i s e First Q u a d r a n t Case.
e ", Appendix
\
\
\ It remains to be shown that minimizing the differ-
\
\
\
ence between the squares of the true and constrained
\
\ radii also minimizes the linear difference between the
two radii. Figure 4 shows the case in which the circle
passes between the points (X + 1, Y) and (X + 1,
Y - - l).
I
l Using the notation in Figure 4, application of the
t
trigonometric law of sines for p and q and the law of
cosines for d 2 and e2 gives
d 2 = w2 + p 2 _ 2 p w c o s ½ (A + B),
x
d2 = w2 + P I Wsin[90+½(A--B)]
sin (90-- A) _2wcos½(A+B) 1
with points most closely spaced in those portions of d2 = w2 + pw[COS A -- 2 eos ½(A + B) cos ½(A -- B) ]
the curve having the greatest curvature. ~b~(~i - - B5
In personal communications [March and April,
d~ w2 cos B
1975], Pitteway has shown the author an alternative = -- pw cos ½(A -- B)'
interpretation which provides additional insight into
the difference between squared and vertical error mini- cos A cos B -]
d ~ = w~ 1 - cS~s~ ~ d = ~ ) J " (1)
mization. The expressions for 8 and 8' can be refactored
as follows:
e2 = (I -- w)2 + q 2 - 2q(1 -- w) cos½(A + B ) ,
8 = 2{(X, + 1) 2 + ( Y , - - ½)2 _ (r 2 _ ¼)},
8' = 2 { ( X , + ½)2 + (y, _ 1)z _ (r 2 _ ¼)}, { sin (90-- B)
e2 = ( l - - w ) 2 + q (1--W) s i n ~ O ~ ( - A ~ B ) ]
which is twice the residue of a circle of radius (fl - ¼)~ N
Therefore References
1. Bresenham, J.E. An incremental algorithm for digital plotting.
if6 < 0 t h e n ( d - e) < 0 h e n c e d < e, (7) Presented at ACM Nat. Conf. (Aug. 1963).
2. Bresenham, J.E. Algorithm for computer control of a digital
if6 ~_ l t h e n ( d - - e) > 0 h e n c e d > e. (8) plotter. IBMSystems J. 4, 1 (1965), 25-30.
3. Bresenham, J.E. A linear, incremental algorithm for digitally
When 6 is integer valued only, one has the simple plotting circles. Tech. Rep. No. TR02.286, IBM General Products
decision rule Div., San Jose, Calif. Jan 27, 1964.
4. Cohen, D. On linear difference curves. Proc. Int. Symp. CG-
ifS_~ 0 t h e n d < e, (9) 70, Vol. I, Brunel U. Uxbridge, England, April 1970.
if6 > 0 t h e n d > e. (10) 5. Cohen, D. Incremental methods for computer graphics. Tech.
Rep. ESD-TR69-193 Harvard U., Cambridge, Mass., April 1969.
6. Danielsen, P.E. Incremental curve generation. IEEE Trans.
In a like manner, (9) and (I0) can be shown to hold Computers C-19, 9 (Sept. 1970), 783-793.
for the 6' situation in which the point (X d- 1, Y -- 1) 7. Denert, E. A method for computing points on a circle using
and line segment d' are exterior to the true circle. only integers. Comptr. Graphicsand Image Processing 2, 1 (Aug.
1973), 83-91.
The circle algorithm thus minimizes both the linear 8. Jordan, B.W., Lennon, W.J., and Holm, B.C. An improved
difference between the true and constrained radii and algorithm for the generation of nonparametric curves. IEEE
the difference between the squares of the true and con- Trans. Computers C-22, 12 (Dec. 1973), 1052-1060.
9. Metzger, R.A. Computer generated graphic segments in a
strained radii when the circle has an integer radius and raster display. Proc. AFIPS 1969 SJCC, AFIPS Press, Montvale,
integer center point. F r o m eqs. (4) and (5) and the sum N.J., pp. 161-172.
of the square roots of eqs. (1) and (2) (i.e. 0 < d d- 10. Pitteway, M.L.V. Algorithm for drawing ellipses or hyper-
bolae with a digital plotter. Comptr. J. 10, 3 (Nov. 1967),
e < 1), it can be shown that if 6 < 0 then d < ½, and 282-289.
if ~ ~_ 1 then e < ½, which agrees with the m a x i m u m 11. Pitteway, M.L.V. Integer circles, etc.--three move extension
radial error found experimentally in [8] and [9]. of Bresenham's algorithm. Comptr. Graphicsand Image Processing
3, 3 (Sept. 1974), 260-261.
When 6 can assume noninteger values in the range 12. Pitteway, M.L.V. Integer circles--some further thoughts.
0 < 6 < I, radial and squared criteria need not coincide Compt. Graphicsand Image Processing3, 3 (Sept. 1974), 262-265.
as one quickly can verify when stepping clockwise
from (1, 5) on the circle x 2 d- y2 = (4.93)2. Should
decision rule (10) be used when 0 < 6 < 1, e will be
selected when in fact d possibly could be the lesser of
the two radial error measures. The difference should be
negligible for larger radii since, for 0 < 6 < 1, one can
observe from equations (1), (2), (4), and (5) that
e < 1/2 d- 1/4r and [ d -- el < 1/2r.
When incrementally displaying the circle (x --