Digital Differential Algorithm
so draw a vertical line, we need co-ordinates where x is constant & only y varies
but this leads to divide by zero, & output exit's
how to overcome this??
so draw a vertical line, we need co-ordinates where x is constant & only y varies
but this leads to divide by zero, & output exit's
how to overcome this??
Void DDA()
{
int x1=100,y1=100,x2=100,y2=500,dy,dx,m,i;
m = (y1-y2)/(x1-x2);
if(m<=1)
{
dx=1;
dy=m*dx;
}
else
{
dy=1;
dx=dy/m;
}
for(i=x1;i<x2;i++)
{
x1=x1+dx;
y1=y1+dy;
putpixel(x1,y1,RED);
}
}