Bresenham Line Drawing Algorithm
Bresenham Line Drawing Algorithm
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);
d1=m(x(o)+1)+c-y(o);
d2=(y(o)+1)-y;
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
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
.(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(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);