Asked in
Computers
Computer Programming
C Programming

DDA line algorithm?

Answer

User Avatar
Wiki User
September 17, 2009 3:00PM

DDA Line Drawing Algorithm

Step 1:[Determine The Dx & Dy]

Dx=Xb-Xa

Dy=Yb-Ya

Step 2:[Determine Slope is Gentle or Sharp]

If |Dx|>|Dy| then

Gentle Slope

M=Dy/Dx

Set The Starting Point

If Dx>0 Then

C=CELING(Xb)

D=Yb+M*(C-Xb)

F=FLOOR(Xa)

R=FLOOR(D+0.5)

H=R-D+M

IF M>0 Then

Positive Gentle Slope

M1=M-1

Now Step Through The Columns

WHILE C<=F

C Programming Coding For DDA Algorithm

void linedda(int xa,int ya,int xb,int yb) {

int dx=xb-xa,dy=yb-ya,steps,k;
float xincrement,yincrement,x=xa,y=ya;

if(abs(dx)>abs(dy)) steps=abs(dx);
else steps=abs(dy);

xincrement=dx/(float)steps;
yincrement=dy/(float)steps;

putpixel(round(x),round(y),2)

for(k=0;k<steps;k++) {
x+=xincrement;
y+=yincrement;
putpixel(round(x),round(y),2);
}
}

More Information

http://knol.google.com/k/thiyagaraaj-m/dda-line-algorithm/1lfp8o9xxpx13/78#
http://i.thiyagaraaj.com/articles/articles/dda-line-algorithm