What is DDA Algorithm?
Digital differential Analyzer is a line drawing algorithm which calculates and plots coordinates on the basis of the previously calculated intermediate points until it reaches to the final point. However, this algorithm works on the concept of the slopeintercept equation.
Algorithm:


 Since, A line segment has an initial point (x_{0},y_{0}) and a final point (x_{1},y_{1}), so get the input from the user regarding initial and final point.
 After getting the input, calculate the value of Δx and Δy. (Δ represents the difference between two points) Δx= x_{1}x_{0}, Δy= y_{1}y_{0}
 Find the slope of the line by usin.g: Slope =Δy/Δx
 if Slope > 1 then do,

While x isn’t equivalent to the final point (x_{1}) do,
x_{0+k} = x_{k} + (1/m)
y=y+1
plot(x,y)
End while
else
While y isn’t equivalent to the final point (y_{1}) do,
y_{0+k} = y_{k} + (m), x=x+1
plot(x,y)
End While
C program to draw a line using DDA algorithm in computer graphics
Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 
#include<graphics.h> #include<stdio.h> #include<conio.h> void main() { float x,y,x1,y1,delx,dely; float slope; int gr=DETECT,gm; initgraph(&gr,&gm,"C:\\TURBOC3\\BGI"); printf("\n please enter the initial points of x, y = "); scanf("%f %f",&x,&y); printf("\n enter the final points of x, y = "); scanf("%f %f",&x1,&y1); dely= y1y; delx=x1x; slope=dely/delx; if(slope>1.0) { while(y<=y1){ putpixel(x,y,1); x=x+(1/slope); y=y+1.0; } } else{ while(x<=x1){ putpixel(x,y,1); y=y+slope; x=x+1.0; } } getch(); } 
Output:
You must be logged in to take the quiz.