DDA Algorithm in computer graphics

C Graphics » DDA Algorithm in computer graphics

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 slope-intercept equation.

Algorithm:-

      1. Since, A line segment has an initial point (x0,y0) and a final point (x1,y1), so get the input from the user regarding initial and final point.
      2.  After getting the input, calculate the value of Δx and Δy.  (Δ represents the difference between two points)   Δx= x1-x0,  Δy= y1-y0
      3. Find the slope of the line by usin.g: Slope =Δy/Δx
      4.  if Slope > 1 then do,

          While x isn’t equivalent to the final point (x1)          do,

x0+k = xk + (1/m)

y=y+1

plot(x,y)

          End while

         else

         While y isn’t equivalent to the final point (y1)          do,

y0+k = yk + (m),  x=x+1

plot(x,y)

End While

 

C program to draw a  line using DDA algorithm in computer graphics

Program:

 

Output:


You must be logged in to take the quiz.

error: Content is protected !!