Graphics Reference
In-Depth Information
tations using purely integer arithmetic by multiplying the equation for our line by 2,
that is, let us use
(
) =
(
) =
(
) =
F x y
,
2
f x y
,
2
ax
+
by
+
c
0
.
This has the effect of multiplying our starting value for the decision variable and its
increments by 2. Since only the sign of the variable was important and not its value,
we have lost nothing. Putting all this together leads to Algorithm 2.5.3.1.
Finally, before leaving the subject of line-drawing algorithms, we should point out
that there are other such algorithms other than the ones mentioned here. For example,
there are run-based line drawing algorithms. See [SteL00]. One thing to keep in mind
procedure DrawLine (integer x 0 , y 0 , x 1 , y 1 )
{ We have chosen the equation
f (x, y) = (dy) x - (dx) y + c = 0
as the equation for the line.}
begin
integer dx, dy, d, posInc, negInc, x, y;
dx := x 1 - x 0 ;
dy := y 1 - y 0 ;
d := 2*dy - dx; { Initial value of decision variable }
posInc := 2*dy; { The increment for d when d ≥ 0 }
negInc := 2*(dy - dx); { The increment for d when d < 0 }
x := x 0 ; y := y 0 ;
Draw (x,y);
while x < x 1 do
begin
if (d £ 0)
then d := d + posInc
else
begin
d := d + negInc;
y := y + 1;
end ;
x := x + 1;
Draw (x,y);
end
end;
Algorithm 2.5.3.1.
The midpoint-line drawing algorithm.
Search WWH ::




Custom Search