Bresenhams Line Drawing Algorithm
Bresenhams Line Drawing Algorithm
Algorithm
Introduction
The points (x1, y1) and (x2, y2) are assumed not
equal and integer valued.
is assumed to be real.
Let x = x2 − x1
Let y = y2 − y1
Let m = y
x
Let j = y1
Let = m − 1
for i = x1 to x2 − 1
illuminate (i, j)
if ( ≥ 0)
j+=1
− = 1.0
end if
i+=1
+=m
next i
finish
The Integer Bresenham’s Algorithm
• Bresenham’s Algorithm, as given in the previous
section, requires the use of floating point arithmetic to
calculate the slope of the line and to evaluate the error
term.
= y - 1
x
and is incremented by y at each step.
x
• Since both y and x are integer quantities, we can
convert to an all integer format by multiplying the
operations through by x. That is, we will consider
the integer quantity , where is initialized to
= x
= y − x
The points (x1, y1) and (x2, y2) are assumed not
equal and integer valued.
is assumed to be real.
Let x = x2 − x1
Let y = y2 − y1
Let m = y
x
Let j = y1
Let = y - x
for i = x1 to x2 − 1
illuminate (i, j)
if ( ≥ 0)
j+=1
− = x
end if
i+=1
+ = y
next i
finish