Vous êtes sur la page 1sur 6

BRESENHAMS LINE ALGORITHM

DDA line drawing algorithm is suffered by some


limitations which have been removed in
Bresenhams line drawing algorithm.To understand
the concept first of all we consider the scan
conversion process for lines with positive slope less
than 1
Starting from left end point(x0,y0) we scan
horizontally at step size x=1 & plot the pixel whose
scan line y value is closest to the line path foreg:
we have just ploted the pixel at (xk,yk) and how we
have to plot the next pixel

For next pixel we have two choices (xk+1,yk+1) or


(xk+1,yk) now the y coordinate at the actual line
position when x=xk+1 can be calculate as given
below y=m(xk+1)+b actual value
Now,

D1 =y-yk

yk

D1 = m(xk+1)+b.............................................1eq
D2 =yk+1-y

D2 =yk+1-[m(xk+1)+b]
.2eq
Now d1 d2 =m(xk+1+b-yk (yk+1)+[m(xk+1)+b]
= m(xk+1)+b-yk-yk-1+m(xk+1)+b
=2m(xk+1) -2yk+2b-1
A decision parameter pk for the kth step can be
calculate as given below
Pk = x[d1-d2]
= x[2m(xk+1)-2yk+2b-1]
Or
Pk= x[2y/x(xk+1)-2yk+2b-1]
Pk=[2 y(xk+1)-2 xyk+2 xb-x]
Pk=2yxk+2y-2xyk+2xb-x
PK=2xky-2yk x+ceq 3
Where c=2y+2xb-x
If pK<0 implies that d1<d2 so, we will plot lower
pixel therewise we will plot upper pixel

The next value of the decision parameter can be


calculate by replacing k with k+1 in equation 3
P k+1=2x k+1y-2y k+1x+c..eq 4
Subtract 3 from 4
P k+1- PK= 2 y(xk+1- xk) -2x (y k+1-yk)
eq 5
But

xk+1- xk=1

Therefore from eq 5
P k+1- PK= 2 y- 2x (y k+1-yk)
P k+1= PK+ 2 y- 2x (y k+1-yk)
Here

y k+1-yk can be 0 or 1

The initial value of decision parameter is given by


PO=2 y- x
BLDA
1)

2)
3)

for |m|<|

Input the two line end point &save the left


end point in (x0,y0)
Plot the first point
Calculate the initial value of decision
parameter P0 and constant x, y,2y,2y-2x
P0=2y-x

4)

5)

For each value of xk starting at k=0 check if


Pk<0 then plot
The pixel (x k+1, yk) & next value of decision
parameter is given by
P k+1= PK+ 2 y
Else we will plot the pixel(x k+1, y k+1) and next
value of decision parameter will be given by
P k+1= PK+ 2 y-2 x

Vous aimerez peut-être aussi