A Fast Bresenham Type Algorithm For Drawing Circles

by John Kennedy Mathematics Department Santa Monica College 1900 Pico Blvd. Santa Monica, CA 90405 [email protected]

Except for this comment explaining that it is blank for some deliberate reason, this page is intentionally blank!

Fast Circle Drawing There is a well-known algorithm for plotting straight lines on a display device or a plotter where the grid over which the line is drawn consists of discrete points or pixels. In working with a lattice of points it is useful to avoid floating point arithmetic. One of the first publications of such a straight-line algorithm was in "*'&, by Jack Bresenham who worked for I.B.M.. The main idea in the algorithm is to analyze and manipulate the linear equation so that only integer arithmetic is used in all the calculations. Integer arithmetic has the advantages of speed and precision; working with floating point values requires more time and memory and such values would need to be rounded to integers anyway. In this paper we consider the more difficult problem of approximating the plot of a circle on a grid of discrete pixels, using only integer arithmetic. Assume B#  C# œ <# represents the real variable equation of a circle which is to be plotted using a grid of discrete pixels where each pixel has integer coordinates. There is no loss of generality here since once the points are determined they may be translated relative to any center that is not the origin (!, !). We will compare errors associated with the B and C coordinates of the points that we are plotting. Although we plot points of the form T (B3 ß C3 ), these points usually do not exactly satisfy the circles' defining equation. Assuming B3 is accurate, the true C-coordinate of T is  <#  B#3 . We plot T (B3 ß C3 ), but U(B3 ß  <#  B#3 ) is the theoretically precise point that is on the circle. The quantity  B#3  C3#   <#

tells how far T is off the true circle. If this quantity is negative it means T lies inside the true circle, and if this quantity is positive it means T is outside the true circle. Of course when this is ! (which may be rare but does happen) T is exactly on the circle. The expression | B#3  C3#  <# | is a more practical measure of the error. The absolute value will be needed when it comes to comparing two such errors, and this new quantity avoids calculating square roots which are an expensive (timewise) computer floating point operation. Thus we define a function which we call the V+.3?=I<<9< which is an error measure for each plotted point. V+.3?=I<<9<(B3 ß C3 ) œ | B#3  C3#  <# | Our plotting strategy is to start with B" œ < and C" œ !. In this case, V+.3?=I<<9<(B" ß C" ) œ | B#"  C"#  <# | œ | <#  !#  <# | œ ! So the first point we plot fits exactly on the true circle.

Fast Circle Drawing

1

We plot our circle in the same order as would be given by the parametric equations B œ cos(>) and C œ sin(>) in which > starts at ! and increases. This means the circle is drawn in a counterclockwise direction, starting on the positive horizontal B-axis. On the starting part of the graph the C-coordinates increase or change more rapidly than the B-coordinates. So at each iteration we decide to always increment C, but we need to test when we should decrement B. C3" œ C3  ", for 3 œ "ß #ß $ß á Depending on the result of our test for when to decrease B, we will have B3" œ B3 if the test fails, or B3" œ B3  " if the test succeeds. Our decision as to when to decrease B is based on the comparison of the two values, V+.3?=I<<9<(B3  "ß C3  ") and V+.3?=I<<9<(B3 ß C3  ") Then we choose either B3  " or B3 as our new B-coordinate depending on which of the two V+.3?=I<<9< values is the smallest. In any event, we need to know how the function V+.3?=I<<9<(B3 ß C3 ) changes for each possible change in its arguments, i.e, when B3 decreases and C3 increases. In other words, we do not need to calculate V+.3?=I<<9< anew for each next point, if we just keep track of how the value changes as the arguments change. If you just plotted the point T (B3 ß C3 ), you would next be considering plotting either T (B3  "ß C3  ") or T (B3 ß C3  ") and you would base your decision of which point to plot after comparing V+.3?=I<<9<(B3  "ß C3  ") and V+.3?=I<<9<(B3 ß C3  "). V+.3?=I<<9<(B3  "ß C3  ") œ l (B3  ")#  (C3  ")#  <# l œ l B#3  #B3  "  C3#  #C3  "  <# l œ l B#3  C3#  <#  Ð"  #B3 )  (#C3  ") l The alternative is to plot T (B3 ß C3  "). The error at this point is given by: V+.3?=I<<9<(B3 ß C3  ") œ l B#3  (C3  ")#  <# l œ l B#3  C3#  #C3  "  <# l œ l B#3  C3#  <#  (#C3  ") l

Fast Circle Drawing

2

Next we analyze and try to simplify the inequality: V+.3?=I<<9<(B3  "ß C3  ")  V+.3?=I<<9<(B3 ß C3  ") This inequality holds if and only if l B#3  C3#  <#  ("  #B3 )  (#C3  ") l  l B3#  C3#  <#  (#C3  ") l if and only if   B#3  C3#  <#  ( #C3  " )   ( "  #B3 ) #   B3#  C3#  <#  ( #C3  " ) # if and only if   B#3  C3#  <#  ( #C3  " )   ( "  #B3 )   B3#  C3#  <#  ( #C3  " )  #

#

if and only if  B#3  C3#  <#  ( #C3  " )   # †  B3#  C3#  <#  ( #C3  " )  † ( "  #B3 )  ( "  #B3 )# #   B#3  C3#  <#  ( #C3  " )  #

if and only if # †  B#3  C3#  <#  ( #C3  " )  † ( "  #B3 )  ( "  #B3 )#  ! if and only if # †  B#3  C3#  <#  ( #C3  " )   ( "  #B3 )  ! In arriving at the last step we assumed the quantity ( "  #B3 ) is negative so when we divide both sides of the inequality with it, the inequality is reversed. If # †  B#3  C3#  <#  ( #C3  " )   ( "  #B3 )  ! then we should decrement B when we plot the next point T (B3" ß C3" ). Having performed the above analysis we can begin to see the usefulness of defining three new quantities.

Fast Circle Drawing

3

\G2+81/ œ ( "  #B3 ) ] G2+81/ œ ( #C3  " ) V+.3?=I<<9< œ B#3  C3#  <# These three quantities may also be calculated recursively (i.e., iteratively). Since when B3 and C3 change, they change by „ ", the quantities \G2+81/ and ] G2+81/ always change by exactly „ #. These two quantities are always odd. \G2+81/ starts counting with the negative number, "  #<, and increases toward !. ] G2+81/ counts odd numbers, starting at " and increases as well. The initial V+.3?=I<<9< value is ! since B" œ < and C" œ !. During the plotting process V+.3?=I<<9< may be positive, or negative, or !. Thus the program's V+.3?=I<<9< variable neither needs nor uses the absolute value that was shown earlier. Now we can give the circle plotting algorithm. Below, G\ , G] , and V refer to the circle's center point coordinates and radius value. procedure PlotCircle(CX, CY, R : longint); begin var X, Y : longint; XChange, YChange : longint; RadiusError : longint; X : œ R; Y := 0; XChange : œ 1  2*R; YChange : œ 1; RadiusError := 0; while ( X   Y ) do begin Plot8CirclePoints(X,Y); {subroutine appears below} inc(Y); inc(RadiusError, YChange); inc(YChange,2); if ( 2*RadiusError + XChange > 0 ) then begin dec(X); inc(RadiusError, XChange); inc(XChange,2) end end end; {procedure PlotCircle}

Fast Circle Drawing

4

Due to the circle's symmetry, we need only calculate points in the first %&° of the circle. Thus in the above code the main while loop terminates when ] first becomes larger than \ . The subroutine called T 69>)G3<-6/T 938>= takes advantage of the symmetry. We only calculate the points in the first %&° , but for each such point we actually plot ( other related points at the same time as indicated in the figure below. The T 69>)G3<-6/T 938>= subroutine would normally be defined inside the above T 69>G3<-6/ procedure. Also note that G\ and G] refer to the circle's center point. The ) numbered regions in the figure below result after dividing each quadrant into two parts. These regions may be called octants, which like quadrants are numbered in a counterclockwise direction, with octant " just above the positive B-axis. procedure Plot8CirclePoints(X,Y : longint); begin PutPixel(CX+X, CY+Y); {point in PutPixel(CX-X, CY+Y); {point in PutPixel(CX-X, CY-Y); {point in PutPixel(CX+X, CY-Y); {point in PutPixel(CX+Y, CY+X); {point in PutPixel(CX-Y, CY+X); {point in PutPixel(CX-Y, CY-X); {point in PutPixel(CX+Y, CY-X) {point in end; {procedure Plot8CirclePoints}

Fast Circle Drawing

5

octant octant octant octant octant octant octant octant

1} 4} 5} 8} 2} 3} 6} 7}

Y+ (-y, x)

(y, x) 2

3

(-x, y) 4

1

(x, y) plotting direction is counterclockwise

X+

X-

5

8

(-x, -y)

(x, -y)

7

6 (-y, -x)

(y, -x)

YFigure 1. The 8 symmetric octants of a circle. Only octant #1 points are calculated.

Fast Circle Drawing

6

REFERENCES: ". Jack Bresenham, Algorithm for Computer Control of a Digital Plotter, IBM Systems Journal, Volume %, Number ", "*'&, pp. #&-$!. #. Jack Bresenham, A Linear Algorithm for Incremental Display of Circular Arcs, Communications of the ACM, Volume #!, Number #, February "*((, pp. "!!-"!'. $. Jerry R. Van Aken, An Efficient Ellipse-Drawing Algorithm, I.E.E.E. Computer Graphics & Applications, September "*)%, pp.#%-$&. %. Michael Abrash, The Good, the Bad, and the Run-sliced, Dr. Dobbs Journal, Number "*%, November "**#, pp."("-"('.

Fast Circle Drawing

7

A Fast Bresenham Type Algorithm For Drawing Circles

once the points are determined they may be translated relative to any center that is not the origin ( , ). ... Thus we define a function which we call the V+.3?=I<<9<.

166KB Sizes 2 Downloads 292 Views

Recommend Documents

A Fast Bresenham Type Algorithm For Drawing Ellipses
We define a function which we call the which is an .... refer to the ellipse's center point coordinates and its horizontal and vertical radial values. So. \V+.3?= œ +.

A Feuerbach Type Theorem on Six Circles
Dec 13, 2001 - (or line) if and only if for appropriate choice of signs, t12t34 ± t13t42 ... From this we obtain t1(A), and similarly t2(B) and t3(C): t1(A) = c · CA1 + ...

A Fast Bit-Vector Algorithm for Approximate String ...
Mar 27, 1998 - algorithms compute a bit representation of the current state-set of the ... *Dept. of Computer Science, University of Arizona Tucson, AZ 85721 ...

A Fast Algorithm for Mining Rare Itemsets
telecommunication equipment failures, linking cancer to medical tests, and ... rare itemsets and present a new algorithm, named Rarity, for discovering them in ...

A Fast Algorithm For Rate Optimized Motion Estimation
Abstract. Motion estimation is known to be the main bottleneck in real-time encoding applications, and the search for an effective motion estimation algorithm has ...

A Fast and Efficient Algorithm for Low-rank ... - Semantic Scholar
The Johns Hopkins University [email protected]. Thong T. .... time O(Md + (n + m)d2) where M denotes the number of non-zero ...... Computer Science, pp. 143–152 ...

A Fast and Efficient Algorithm for Low-rank ... - Semantic Scholar
republish, to post on servers or to redistribute to lists, requires prior specific permission ..... For a fair comparison, we fix the transform matrix to be. Hardarmard and set .... The next theorem is dedicated for showing the bound of d upon which

A Fast String Searching Algorithm
number of characters actually inspected (on the aver- age) decreases ...... buffer area in virtual memory. .... One telephone number contact for those in- terested ...

A Fast String Searching Algorithm
An algorithm is presented that searches for the location, "i," of the first occurrence of a character string, "'pat,'" in another string, "string." During the search operation, the characters of pat are matched starting with the last character of pat

A Fast Bit-Vector Algorithm for Approximate String ...
Mar 27, 1998 - Simple and practical bit- ... 1 x w blocks using the basic algorithm as a subroutine, is significantly faster than our previous. 4-Russians ..... (Eq or (vin = ;1)) capturing the net effect of. 4 .... Figure 4: Illustration of Xv compu

A Fast Distributed Approximation Algorithm for ...
We present a fast distributed approximation algorithm for the MST problem. We will first briefly describe the .... One of our motivations for this work is to investigate whether fast distributed algo- rithms that construct .... and ID(u) < ID(v). At

A fast optimization transfer algorithm for image ...
Inpainting may be done in the pixel domain or in a transformed domain. In 2000 ... Here f and n are the original noise-free image and the Gaussian white noise ...... Step: δ t=0.08. Step: δ t=0.04. Step: Linear Search. Our Method. 0. 100. 200.

A fast convex conjugated algorithm for sparse recovery
of l1 minimization and run very fast on small dataset, they are still computationally expensive for large-scale ... quadratic constraint problem and make use of alternate minimiza- tion to solve it. At each iteration, we compute the ..... Windows XP

A Fast Greedy Algorithm for Generalized Column ...
In Proceedings of the 52nd Annual IEEE Symposium on Foundations of Computer. Science (FOCS'11), pages 305 –314, 2011. [3] C. Boutsidis, M. W. Mahoney, and P. Drineas. An improved approximation algorithm for the column subset selection problem. In P

a fast algorithm for vision-based hand gesture ...
responds to the hand pose signs given by a human, visually observed by the robot ... particular, in Figure 2, we show three images we have acquired, each ...

A Fast Algorithm For Rate Optimized Motion Estimation
uous motion field reduces the bit rate for differentially encoded motion vectors. Our motion ... In [3], we propose a rate-optimized motion estimation based on a “true” motion tracker. ..... ftp://bonde.nta.no/pub/tmn/software/, June 1996. 477.

A Fast Greedy Algorithm for Outlier Mining - Semantic Scholar
Thus, mining for outliers is an important data mining research with numerous applications, including credit card fraud detection, discovery of criminal activities in.

A Fast Distributed Approximation Algorithm for ...
ists graphs where no distributed MST algorithm can do better than Ω(n) time. ... µ(G, w) is the “MST-radius” of the graph [7] (is a function of the graph topology as ...

A Ultra Fast Euclidean Division Algorithm for Prime ...
ing schemes, that is, conversions of array coordinates into bank .... of banks referenced by a stride s request stream is min(M,. M2 gcd(M2,s). ), though it is as ...

A Fast Line Segment Based Dense Stereo Algorithm ...
Intitute of HCI and Media Integration, Key Lab of Pervasive Computing(MOE). 3-524, Fit building, Tsinghua University, Beijing 100084, P.R. China ... survey by Scharstern and Szeliski [1] and the one by Brown et al. [2]. ..... Two registers stores.

A Fast and Simple Surface Reconstruction Algorithm
Jun 17, 2012 - Octree decomposition. Root cell smallest bounding cube of P. Splitting rule split a splittable leaf cell into eight children. Balancing rule split a leaf cell C if it has a neighbor C/ s.t. lC < lC /2. Apply the two rules alternately u

An Algorithm for Fast, Model-Free Tracking ... - Research at Google
model nor a motion model. It is also simple to compute, requiring only standard tools: ... All these sources of variation need to be modeled for ..... in [5] and is available in R [27], an open source sys- tem for .... We will analyze the performance

Fast maximum likelihood algorithm for localization of ...
Feb 1, 2012 - 1Kellogg Honors College and Department of Mathematics and Statistics, .... through the degree of defocus. .... (Color online) Localization precision (standard devia- ... nia State University Program for Education and Research.

A Fast Line Segment Based Dense Stereo Algorithm ...
problem stems from the pixel-based tree construction. Many edges in ... Stereo correspondence has been one of the most important problems in computer vision ...