0% found this document useful (0 votes)
2 views13 pages

cederberg1979

The document presents a new algorithm for vector generation that computes constants for the smoothest digital representation of a straight line based on structural properties. It discusses various existing methods for curve generation and introduces a fast hardware generator for applications requiring high speed. The algorithm is designed to optimize the drawing of lines in computer graphics and numerical control by utilizing discrete equations and centering techniques.

Uploaded by

Groleo Mutt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views13 pages

cederberg1979

The document presents a new algorithm for vector generation that computes constants for the smoothest digital representation of a straight line based on structural properties. It discusses various existing methods for curve generation and introduces a fast hardware generator for applications requiring high speed. The algorithm is designed to optimize the drawing of lines in computer graphics and numerical control by utilizing discrete equations and centering techniques.

Uploaded by

Groleo Mutt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

1’0.211’1 TI.lf (:I: \1’111(‘5 .\SI) Ihl\(:I~: l’I~O(‘I~:SSING 9, 18:i I!).; it%!

)1

A New Method for Vector Generation

An algorithm for thr cwnputatirm of cwnstsnts in an cylmtiorl detwnkring the snlooth-


est digital representation of a straight line with slope 01 = :wt:m (P,,‘I-‘,r) is prmentcd.
Tht, equation is based upon struc*trual proprrtiw. A fast hardwart~ gclnerator, giwn the
(*onstants, is proposed. The vwtor gtwcmtor is prinmrily intwdcd for applic*ations whew
a given lirw is gmrratrd swc~r:~l tirrlc>s with high spwfl.

1. rNTI:oI)I:(‘TIoN

Gcbnchration of curv(‘s using incrc~nic~nl:4 ,stc>p::i s important in ar(‘as such ah


computer graphics, digital plottcq and numc~rical control. Thr~rc arc’ scvcA
m&hods, of which the classical I)I),$ tc&niquc~, th(k nonparamc+ric algorithm
proposcxd by Danickon ([4], comp:trck [Ci]) and thcl lincx gc\nteLtion algorithm of
Hrcsclnhsm [t’] can b(l mcxntioncxd. ‘I’h(t I> I),\ uses th(L paramr~tric equation,<
.c = .r(ll.
y = g (t !
in t,wo dimensions. Thosc~ equations arc’ diftf(~rc~nti:itc~dand tlict solut,ion to thcb
diffcrc,ntial quat,ions rc$sults in :l curve’. In t hfb nonparam(+ric C:LS(~any twvo-
dimclnsional curve can b(L d(Lscrib(kd b?
J(.rs !/) = 0.
184 ROGER L. T. CEDEltI3EItG

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’,.

::. TrIF: I)I(;IT.ZT, LINI*: I’QI!‘.~‘N0N

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)~

(3, K E [O. 1, . . . . i].


( C) - K / rllocl s = 1.

2
3 1

4 0

100 7 6 0 0
5 x 7
6
1% ROGER L. T. CEDERBERG

FIG. 4. The deviation (d).

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

no = moba + no, (2)


where bo - /no / 2 j noI and no can be negative.
Equation (2) can bc rewritten as

ao = mdbo - InoIl + (ma + kO)[nol.


Equation (2) involves bo - InO] groups
QmoR
and I.noj groups
I;,, = + 1 if //(I 3 0,
=- 1 if II ,I < 0.

To gc+ th(k optimal straight line th(a two groups must altc~rnatc :LS much :lh

‘I’hc algorithm ends wh(ln ni = 0. ~5,> 1 intlic:ltcbs b, - 1 intcbrsclctions with the


id4 lint> and points in the> digital rc,p~c,ac~rlt:ltioIl. This occurs wh(ln thci intc.gce
q and T have a common factor.
188 ROGER L. T. CEDERBERG

FIGURE 5

EXAMPLE 1. PI = (0, 0), PT = (193, 38)

-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)

EXAMPLE 2. PI = (0, 0), PT = (L50, 26)

+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

FIG. 7. Centering of the digital line by permutation of Eq. (3).

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.

4. CENTERING TO THE GIVEN LINE

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

It is impossible to get exact centering in this case.


When no = 0, Eq. (3) has t’hc form [QmaRlboand the centering problem is
solved. If no # 0 we have the possibility to choose either m. or m. + ko (one of
them is even) and divide.
Except at the top level we get exact centering because either rni or rni + ki
is even, and at the t-level, mt decides whether there is one (exact) or two equal
solutions to the centering problem.
To get the general preloading or permutat’ion rule let

&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~

hlidpoint in fl, 1 I:(‘, + ,,I.


I’, -1 = 0

IIidpoint in Ii’, 2 ,I,, (!“,‘,I IN’, t ,t,, 2


I-,+, = 1 ,,I, cdtl KC’, ‘+ (NJ + k,i.:!
I.,~? = 0 [ . ., j<I r(-qLt

l.,~, = 1 I?, / C~V(‘Il M’, + (/?/. i- k, - I) 2


I‘, 2= 1 ,),$ otltl IK’, t (I)/, - I I 2

The situation at the next level is illustrated by Fig. S.


When m. is odd (Fig. Sa) the midpoint is in IZ r. 1)epending on 111~the X1 group
is situated in the middle of a Q2 group or in the IZa group. In both cases 121 is
followed by QI~LIJZ1,which implies that fI’C1 is proloaded with ~1.
If the midpoint is in Q1 (~1~is even 1, we have two cases depending on ~(1 (Fig. Sb
and c). When ~~~~ is odd, the midpoint is in Q2 and &Cl is prcloadcd with (ml- 1j,, 2
and when ml is even, the midpoint i5 in I?, which implic,s that A’(71 is preloaded
with (~1 + lir - I),‘?.
We can see i hat, the prelouding rule is different, for KC, and RCl; t,his is because
t’he midpoint is inside one of the Q1 groups in the latter case and consequently
there is one group less to divide.
The above discussion is applicable for any level. ‘I’h(~ rule to be used at, a levc~l
is directed by the placement of th(b midpoint, at the two lower levels.
The method of permuting $21. (:I) to get the optimal start, point is summarizecl
in Table 1.
l3XA\IT’LE 1. /I/ = (1, 12, 2): /i = (1, --I).
I’(’ I/ 10 I:( ’1 1-1 I<(’1

,,h, L’ I (III! + kl - I) 2 II ,,iI’


‘2 1 5 0 6)
_--~~ .-~~ _~ ~-_ ~~_. ~~ ~~
i’:XA\II-‘LE “. ))I = (3, :j, “) ; /c = - 1, 1 ).

RC’, 1 .,I /I’( ’ , 1 ‘I IIT,

(nl,i + k”),l% 0 ,,,I 1 ,I, y 12


2 0 :: I I

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.

All three operations can be implemented either in software or hardware, but


it is advantageous to do the iterative computation in software and build a hard-
ware generator.
The permutation is rather easy to do in either case.

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

The next M2 increment gives

V ,+#-1 = Vi+r, - Cl, (7)


where
vi+.ro+l < 0.

If vi+ro+l = Vi, the group MpMZ will be repeated forever. Thus

vi+zo - vi Cl Aa - Ab
x0 =
C,-=z= A6 ’
a0 - n0 Aa - Ab - no
Eq. (2) =+ m. = -=
bo Ab *

The condition that m. = x0 implies no = 0, which gives the sequence (MlmoM2)bo.


The algorithms produce the same sequence for this case.
When Vi+zo+~ # Vi, the group MlxoMz will be repeated until Vi+, > 0

vi+p = vi + (xoC2 - C1)Xl (8)


and V<+s < 0,
vi+* = vi+, + (x0 - uo)Cz - Cl. (9)
It is easy to show that Eqs. (8) and (9) and Vits = Vi imply that x0 = mo,
x1 = ml, and vo = ko when nl = 0. The sequences can be shown to be similar
for any number of xi by induction.
The start value Vr of Bresenham’s algorithm corresponds to the centering of the
presented algorithm.
Thus we have verified that two very different met’hods, one based on structural
properties discussed by Freeman [5, S] and the other based on a closeness
criterion, give the same code sequence.
The algorithm of Bresenham is simpler and fast’er in an application where the
line is drawn once. The presented algorithm has advantages in applications where
the constants are computed and stored, whereafter each line is generat’cd several
times with high speed.

ACKNOWLEDGMENTS

The author is grateful to Professor P. E. Danielsson and Professor H. Freeman


for their constructive criticism of this paper.

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

You might also like