0% found this document useful (0 votes)
106 views4 pages

Bresenham Line Drawing Algorithm

The Bresenham line algorithm is an efficient method for generating raster lines on a digital display. It uses integer calculations rather than floating point, making it more accurate than the DDA algorithm. It works by calculating a decision parameter p(k) at each increment to determine whether to plot the next point as (x(k)+1, y(k)) or (x(k)+1, y(k)+1) in order to most closely follow the true line defined by the equation. The algorithm is optimized to increment p(k+1) efficiently from the previous p(k) value using only integer arithmetic.

Uploaded by

shubham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
0% found this document useful (0 votes)
106 views4 pages

Bresenham Line Drawing Algorithm

The Bresenham line algorithm is an efficient method for generating raster lines on a digital display. It uses integer calculations rather than floating point, making it more accurate than the DDA algorithm. It works by calculating a decision parameter p(k) at each increment to determine whether to plot the next point as (x(k)+1, y(k)) or (x(k)+1, y(k)+1) in order to most closely follow the true line defined by the equation. The algorithm is optimized to increment p(k+1) efficiently from the previous p(k) value using only integer arithmetic.

Uploaded by

shubham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
You are on page 1/ 4

BRESHENHAM LINE ALGORITHM:

-It is an accurate and efficient raster line generating algorithm


-It uses INTEGER increment calculations thus is more accurate than the DDA algorithm
which uses floating point calculations which lead to dieviations
IN this method for finding the next coordinate ,

EXPLAINATION:
1).we increment the prev x coordinate by 1 and calculate the corresponding y value using
the line equation
PREV COORDINATES ->(x(o),y(o))
y=m[x(o)+1]+c;
2).now we compare this new y coordinate with y(o) and y(o)+1;and the point to which y
is closest or (the difference btw which pt is lowest) is chosen
d1=y-y(o);

//comparing y with y(o)

d1=m(x(o)+1)+c-y(o);
d2=(y(o)+1)-y;

//comparing y with y(o)+1

d2=y(o)+1-m(x(o)+1)-c;
3).NOW we consider a new parameter called as a descision parameter: p(k)
k represents the kth iteration parameter,
p(k) (d1-d2);
p(k)=(t)*(d1-d2);
if p(k)<0
i.e d1<d2 thus y(k) is closer to y (the original point) thus y(k) is chosen

else if p(k)>0
i.e d1>d2

thus [y(k)+1] is closer to y thus [y(k)+1] is chosen

4)As we mentioned earlier this algorithm is all about integer calculations...


Then p(k) should be an integer
d1-d2 =

y-y(k)-y(k+1)+y

2y-2y(k)-1

.(since y(k+1)=y(k)+1)

2(m(x(k)+1)+c)-2y(k)-1

2mx(k)-2y(k)+2c+2m-1

Let 2c+2m+1 be some constant b;


Now m =

which can form floating values

Thus if we take constant t in


p(k)=(t)*(d1-d2)
as then we can obtain integral values of p(k)
thus t=;
5).p(k)=2m* *x(k) 2* *y(k)+b;
m = ;
p(k)=2* *x(k) 2* *y(k)+b;

.(1)

6).Thus for just calculating p(k) we have to undergo the above calculation,this increases the
complexity,so for p(k+1); we calculate it using the p(k).
p(k)=2* *x(k) - 2* *y(k)+b;

.(from 1)

Thus k+1,
p(k+1)=2* *x(k+1) - 2* *y(k+1)+b;
Subtracting p(k) from p(k+1),
p(k+1)-p(k)= 2* *[x(k+1)-x(k)] - 2* *[y(k+1)-y(k)];

p(k+1)-p(k)= 2* *[x(k+1)-x(k)] - 2* *[y(k+1)-y(k)];


`but x(k+1)=x(k)+1;
Thus,
p(k+1)-p(k)= 2* - 2* *[y(k+1)-y(k)];
p(k+1)=p(k)+ 2* - 2* *[y(k+1)-y(k)];
IF p(k)<0 then,
p(k+1)=p(k)+2* ;
Else
p(k+1)=p(k)+2* - 2*;
7).Thus for p(0) i.e. the first point
`

p(0)= * (d1-d2)
p(0)= *(y-y(0)-y(0)-1+y)
p(0)= *(2*[m(x(0)+1)+b]-2*y(0)-1)
p(0)= * (2*(m*x(0)+b)-2*y(0)+2*m -1)
but (m*x(0)+b)=y(0)
p(0)= *(2*y(0)-2*y(0)+ 2*m -1)
p(0)= *(2m-1)
p(0)=2* -

ALGORITHM:
1)Get initial and endpoints
2)Calculate

, and p(0);

.(FOR INITIAL POINT)

3)For each k starting FROM k=0,


IF p(k)<0 then,
{
p(k+1)=p(k)+2* ;
and plot (x(k)+1,y(k));
}
Else{
p(k+1)=p(k)+2* - 2*;
and plot (x(k)+1,y(k)+1)
}
4)Repeat the steps from step 3) times.

You might also like