Transcript
Page 1: An Efficient Circle-Drawing Algorithm

333

An Efficient Circle-Drawing Algorithm

Yevgeni P. Kuzmin'

Abstract

An efficient incremental circledrawing algorithm which uses paired update of the decision variable is proposed. The output of the algorithm is identical to the output of Bresenham's algorithm but the total number of arithmetical operations is less. Efficiency of the algorithm is indepen- dent of the output devices. Its other advantages are dis- cussed.

Key words: Incremental algorithm, Circle drawing, Raster graphics.

1. introduction

Efficiency of raster device usage strongly depends on the efficiency of the fundamental algorithms of raster graphics. Without doubt, circle-drawing algorithms belong to this class.

On an integer grid, the circle must be approximated by the sequence of pixels whose centres are 'nearest' to the

This adaption of the Bresenham's algorithm draws the arc of the circle with the center at (0,O) and radius r in the Octant from 180 degrees, and uses procedure sets-8 ( x , y ) to replicate this arc in each of the eight Octant of the circle.

The algorithm of Bresenham needs four (4) arithmet- ical operations per axial step and five ( 5 ) arithmetical operations per diagonal step. It also uses two (2) coordi- nate variables x and y. two (2) algorithm variables u and v and the decision variable e.

Let us transform this algorithm in order to decrease the number of arithmetical operations and variables.

2. Transformation of Algorithm

2.1. New Real Variables

Let us introduce new algorithm variables: v = 2 * ~ and u = 1 + 2 * y .

real circle. Three different metrics have been used for determination of the term 'nearest' and there are several

Then initial values of the variables will be x=-z. , y = O ; v = 2 * u ; u = 1 + 2 * y ; e = l - r ; kinds of algorithms for drawing circles and circular arcs on

integer gridsI4.

The incremental algorithm of Bresenham5 is most widely used. It looks like this:

and the loop may look as follows:

while (x+y < 0 ) i

void o c t a n t - c i r c l e ( r ! int r; i

int x, y, u, v, e;

x = -r; y = 0; e = 1-r; u = 1; v = e-r ;

w h i l e ( v <= 0) (

sets-8 (x, y ) ;

if (e < 0 ) y++; u += 2;

sets-8 ( x , y ) ; if (e >= 0) i

%++; v += 2; e += v;

y++; u += 2; e += u; 1

We have changed loop termination testing and step direction determination. Suppose variables u, v, e are real. Let us divide them by 2. Then initial values will be

x = -r; y = 0; v = x; u = 1 / 2 + y;

t else (

1 v += 4; e += v; x+t:

1 1

and the inner part of the loop will be transformed into the following form:

if (e >= 0 ) {

k y++; u++; e += u;

x++; v++; e += v ;

*Laboratory of Computations Methods Department of Mathematics and Mechanics Moscow State University I I 9899 Moscow USSR

2.2. Exclusion of Variables

It is easy to notice that equations

v - x = O and ~ - y = 1 / 2

North-Holland Cornpurer Graphics Forum 9 (19%)) 333-336

Page 2: An Efficient Circle-Drawing Algorithm

are valid during the execution of the algorithm. Thus it is evident that we can exclude algorithm variable v. Let US try to exclude variable u too.

The result of the execution of the pair of operators e + = u is equivalent to the result of the execution of sequence of such operators;

e += y ' , e +- y ' , e+-;

Thus we can try to repeat the inner part of the loop two times with y instead of u and with supplementary increment of e. We will analyse where we must do this increment.

Let c be so large that steps are axial in the beginning of algorithm execution. We have two series of the values of the decision variable e depending on r being odd or even:

e v e r , : r = 2 * k ; e C = - k + l / 2 ; e i=-:k-2; e 2 = - k + 4 + i / 2 ; e3=-u+8;

e 2 = - k i 4 ; e 3 = - k t 7 + 1 / 2 ; odd: r = 2 * k + ; ; eC=-k; e;=-k-: t l / 2 ;

Results of comparison of e and floor [ e l with zero are equivalent if zero is associated with positive. Then these series can be transformed to the series for floor [ e : :

e v e r . : r = 2 * k ; eC=-k ; e l = - k + 2 ;

odd: r = 2 * k + l ; eO=-k: e l = - k + i ; e2 = - k + 4 ; e 3=-k + 8 ;

e 2 = - k t 4 ; e 3 = - k t 7 ;

or into iterative form:

e ( ; ) = e ( i - : ) + i + s [ i ) ; i = ;,2,3, ' . .

where

1, if ( r+ i ) is odd 0 , i f ( r + i ) i s ever . S ( i ) =

Thus, now all our variables are integer and the algorithm will look as follows:

x = -r' y = 0 ; e = - r / 2 ; if ( r & l 1 g o t o odd;

s e t s 3 ( x , Y ) ; even:

if ( x t y >= 0 ) T e t ' J r n ; if ( e >= 0 ) e t= +rx; e += ++y; e + t ;

s e t s - 8 ( x , y ) ; i f [ x t y >= C ) r e t u r n ; i f ( e >= 0 ) e -= ++x; e += + + y ; goto ever.;

odd :

Here we use paired update of the decision variable in odd and even clusters to correct the error of the approximation.

2.3. Further Modification of the Algorithm

Let us exclude the addition in termination of execution testins. We can do this by displacement of x to the first Octant from 0 degrees in 45 degrees. Then only the com- parison y 2 x will be needed. The initial value of I( will be r and we must also use operator e -= --;< for diago- nal step.

Then, it was found that the increment of the decision variable e is superfluous. Indeed, operator e += i+y may be placed before step direction testing like this:

e A= yt+; if ( e >= 0 ) e -= --x;

We can do this, because the initial value of y is equal to zero. Now, let us change operator e += ycc in the odd cluster to e += t t y and exclude the increment of e in the even cluster.

If : is even. then the value of the decision variable will not change for step direction testing. In case of odd radius, the value of the decision variable will be greater than needed by 1. But we can decrement e in the initiali- sation and the algorithm becomes the following.

x = r; j ; = 3; e = - : / 2 ; i f ( r 6 1 ) [ e--; goto odd; i

s e t s - 8 (x, y ) ; i f ( y >= x ) r e ' c u r n ; e t = v + t ; i f i e ,= 0 ) e -= --y.

sets-8 ( x , y ) ; i f i y >= x ) r e z u r n ; e += ++y; 1: ( e >= 0 ) e -= - -x; q c t o e v e n ;

e v e n :

. I

odd:

The flow-chan of this algorithm is shown in Figure 1.

3. Comparisons and Examples

The output of the proposed algorithm is equivalent to the 'output of the Bresenham circular arc generation algorithm. because values of step determination testing for these two algorithms are the same.

This algorithm needs only two ( 2 ) arithmetical opera- tions per axial step and four (4) arithmetical operations per diagonal step independently of the output devices. Half of these operations are single increments and decrements, which are executed by many processors faster than addi- tions or subtractions. Also we can speed up the execution of the algorithm by using register variables. because we need only three (3) variables.

The bit size of all variables in proposed algorithm is less than in Bresenham's and is equal to the bit size of initial parameter r - the radius of the circle.

Page 3: An Efficient Circle-Drawing Algorithm

335

7 7

6

START +4

3 - 7 odd 4 - 3 even 5 -5 odd

Figure I . Flow-churl of proposed c.irc.lr-tlrun'itzay ulpirithrn

x I y I e I c l u s t e r a I o I -4 I even

I a I 2 I -2 I even I

Figure 2 . Vulues ofthe vuriuhles in the clusters' entries und corresponding pixels

The total number of arithmetical operations of an circle-drawing algorithm may be estimated like this: the number of axial steps A is approximately equal to

4. Conclusion This paper has presented an algorithm for circle-drawing, using output equivalent to the output of the Bresenham cir- cular arc generation algorithm.

Proposed algorithm uses only three (3) variables of reduced size and the number of arithmetical operation per one step of the circle generator is reduced too.

Thus the proposed algorithm is more efficient than Bresenham's and can be widely used in 2D raster graphics

A = ( sq r t ( 2 ) -1) * 4,

the number of diagonal steps D is approximately equal to

D = (l-sqrt(2)/2) *R.

the total number of arithmetical operations for different algorithm is equal to:

BresenhamforCRT 4 * ~ + 5 * o = 3.12*R systems. Bresenham for plotter 3 * A + 3 * D = 2 . 1 2 * R Proposed algorithm 2 * A + 4 * D = 2 = R

To illustrate the circle-generation algorithm we will con- sider a circle with the radius of 8 units and with center at (0,O) (Figure 2). Only the first quadrant is shown.

Author is grateful to Sergej Burtsev of Cybernetics Counsil for constructive discussions and comments.

Page 4: An Efficient Circle-Drawing Algorithm

336

References

J.E. Bresenham, “A linear algorithm for incremental digital display of circular arcs.’‘ Comnirr/zic,ufion.s of

B.K.P. Horn, “Circle generators for display dev- ices,” Computer Gruphics and Imqqe Processing 5.

M.P. McIlroy, “Best approximate circles on integer

ACM20(2), pp. 100-106 (1977).

pp. 280-288 (1986).

pp. 237-263 ( 1983).

Y. Suenaga, T. Kamae, and T. Kobayashi, ”A hight- speed algorithm for the generation of the straight lines and circular arc,” IEEE Tronsocfions c?f Com- puters 28( lo), pp. 728-736 (1979).

J.E. Bresenham, “Algorithm for circular arc genera- tion,” Springer-Varlog, p. 2 13 (1985).


Recommended