cederberg1979
cederberg1979
)1
1. rNTI:oI)I:(‘TIoN
FIGURE 2
Normally f(z, y) is positive on one side of the curve and negative on the other.
The value of f in combination wit’h the values of the partial derivatives of f
and the direction (v+ or v-) give a set of mutually exclusive Boolean equations
that define one possible step along the line from each point (see Fig. 1).
The algorithm of Bresenham is illustrated by Fig. 2a. In the first octant, the
next step from Pi is M; if ri < qi and M, if ri 3 q;. For computational conve-
nicnce Vi = (r’i - q’i)Aa is used in selecting the appropriate movement. Vi is
shown to satisfy the recursive relation,
V1 = 2Ab - Au,
A;.,1 = Vi $ 2Ab - 2Aa, if Vi > 0,
= Vi + 2A6, if vi < 0,
Vi < 0 3 Ml,
Vi > 0 * Mz.
The algorithm can be generalized to produce lines in all octants.
Another approach to line generation is to use the structural properties of the line.
These algorithms usually deal only with straight lines. Bongiovanni et al. [l]
presents an algorithm with two st’eps: First find t’he equat’ions defined by the
points in the digital rcpresentat’ion of the line, t’hrn find thr right sequence of
these equations. Figure 2b gives a simple example.
Reggiori [7] gives a straight-line generation algorithm that initially uses the
structural properties to get two subperiods. These subpcriods are concatenated
with a conditional algorithm. An algorithm which is entirely structural is given
by Brons [S]. The algorithm to be presented in this paper is based upon the same
fundamentals and is to some extent similar to the algorithm of Brons. From this
basic discrete equation of the straight line, a method to center the discrete equa-
tion to the straight line is given, and a fast hardware generator is proposed.
Finally the storage of code and computation time are discussed briefly.
,Inothcr fundamental propthrty of tho ch:tin cods wprcwntntion of st might
lincls i,+the occurrence of digit groups. All straight linw consist of a basic groul)
that r(Lpwts itself along tht> lincl. l’h(a group can bc vcsry long and somctimw, if
the lincx is not long enough, the group may nc’vw by rcpcntcd. In that caeo t 11~:
tc~rminal point (P.,) is the first, point in the array i hat cwwtly coincidw with t h(a
analog straight lint beginning :Lt I’,.
Consider n straight lint in two dimwsions dcfinod by two points, t’hc initial
point I’1 nnd the terminal point P,r (Fig. 5). Lint 9 can only lx drawn bctwwn
points twlonging to the point spacc~.
As indicated in the prcwding section the two digits in the chain code for thr%
line arc’ dt+wmined by the position of PrL rc+rtiw to 1’1 (oncxof the eight octants).
If th(J two digits are denoted by (2 nnd A’, thctir rckiion is given 1)~
2
3 1
4 0
100 7 6 0 0
5 x 7
6
1% ROGER L. T. CEDERBERG
and if Ax < Ay
q = Ay - Ax
(lb)
r = Ax.
The problem of finding the best approximation t’o the ideal line is equivalent to
alternating Q and R to the maximum extent. In the following presentation Elm
is short for a series of R’s e.g., O6 = 000000.
Let us assume that q 2 r. Set
aa = q,
bo = r,
where QaoRbocan be regarded as the “zero approximation” to the ideal line.
Then
To gc+ th(k optimal straight line th(a two groups must altc~rnatc :LS much :lh
FIGURE 5
-j&=0, R = 1,
q = 155, r = 38,
155 = 4-38 + 3,
ko = 1, a1 = 35,
m. = 4, bl = 3,
35 = 12.3 - 1,
kl = - 1, a2 = 2,
ml = 12, b? = 1,
2 = 2.1 + 0,
3
m2 = _.
The values of ki and rni in combination with Eq. (3) result in the smoothest ap-
proximation of a straight line with slope Q: = arctan (38/193)
+Q=O R = 1,
q = A4 , r = 26,
124 = 5.26 - 6,
ko = - 1, al = 20,
mo = 5, bl = 6,
20 = 3.6 + 2,
kl = + 1, a2 = 4,
ml = 3, b2 = 2,
4 = 2.2 + 0,
m2 = 2,
==+t[:~Q~~~3~Q4~~12C~Q5~~4~Q4~~112.
A sf:\v ~lI~:‘r1101~
E’o1:\‘I~:(“roll (1l~:NI<l:.\7‘1oN I X!)
190 ROGER L. T. CEDERBERG
ideal line (see Fig. 7). This is corrected by a permutation of Eq. (3), which is
equivalent to changing the initial values for RCi, and as a consequence Ui. How
WC get these values is explained by the following discussion.
The start point should be the point at the midline between the two extremes
(determining d in Fig. 4), if there is one, or else the point closest to the middle.
Our method of getting opt’imal smoothness gave Eq. (3) a hierarchical form.
To get the midline, WC begin at the lowest level and keep to the midline through
all levels, to the best approximation. The method is proved by induction.
Consider the line QmoR.It is easily verified that we get exact centering for
Qno~2RQm~/2 if m. is even. If m. is odd there are two equally good solutions
Q(mu+l)/2RQ(mo-U/2 and &ho-1)/2RQ(mo+l)/2
&I = QmoR,
R1 = Qd-kaR
and
Q2 = &I-I,
Rz = QIml+klR1.
We can see that all lcvcls consist of Qi groups and an 12; group. The method of
keeping to the midline is therefore only dependent upon whether mi is even or odd
and where the midline was found in the preceding levels.
How to get the midline at the lowest level was explained above. If mois even,
the vector generation should start, in the middle of a &I group and consequently
RCo is preloadnd with mo/2. If m. is even, the vector generation is started with
an RI group, and the Uo flip-flop has to be reset
m. even =+ RCo+ mo,/2
m,, odd =+ RCo+ (m, + ko)/2, U. is reset.
‘l‘.\l~l,l~:I
‘h: I’wl~u~dil~g l:kilc~
Even though WC start with a permuted form of Eq. (:l)> the length is still con-
tained, but the stop criteria has to be changed.
Three operations are needed to generate the optimal straight line, given I’,
:I nd I’.,, :
(1) Iterative computation of the constants ML, k,, and 0,.
(2) I’crmutation of Eq. (3) t,o get the start point.
(3) Jncrcmcntal generation of the line.
192 ROGER L. T. CEI~ERBERG
b) /
\ 1 distance given by
/ preceding level
, /
point at'
midline
FIG. 8. (a) m. odd + midpoint in RI * RCI f ml; (b) ml odd (5) * RC, + (m, - 1)/2;
(c) ml even (4), /cl = + 1 =+ RC, t (ml + ICI - 1)/2, UI is reset.
5. CONCLUSION
An optimal vector generator has been derived from observations of “structural
properties.” The generator is optimal in the sense of smoothness (d) and centering
to the ideal line.
The method is primarily to be used in areas where the constants arc first
computed, and then the line is drawn several times, as is the case in computer
graphics.
It is of interest to know t in Eq. (3) for different Ax and Ay. t determines the
extent of the hardware in Fig. 6, and gives the average computation time needed
to compute the constants. The average number of memory locations used for
storage of the constants are also derived from t.
Figure 9 presents the number of lines as a function of t for Ax = 500, Ay = 0
-+ 500, and Ax = 2048, Ay = 0 -+ 2048. i\Sotice that the change in Ay does not
change the total number of increments p + r.
hO,l
200 i 00
400
100
100
L-
6 t Ll
1234i67R
L- t
194 ROGER. I,. T. CEDERBERG
vi+zo - vi Cl Aa - Ab
x0 =
C,-=z= A6 ’
a0 - n0 Aa - Ab - no
Eq. (2) =+ m. = -=
bo Ab *
ACKNOWLEDGMENTS
REFERENCES
1. G. Bongiovanni, F. Luccio, and A. Zorat, The Discrete Equation of the Straight Line,
Nota Scientifica S-73-6, Universita degli studi di Pisa, Nov. 1973.
2. J. E. Bresenham, Algorithm for computer control of a digital plotter, IBM Systems J. 4, 1965,
25-30.
3. R. Brons, Linguistic Methods for the Description of a Straight Line on a Grid, Comput. Graphics
Image Proc. 3, 1974, 48-62.
4. P. E. Danielsson, Incremental curve generation, IEEE Trans. Comput. C-19, 1970, 783-793.
.z xI~:b- sff~:‘I’ffof~ l+Y)f: Yf~:(‘Tof: (~fi~f~:f:.2’l‘IoN I !),-I