WHAT IS DDA?
The Digital Differential Analyzer (DDA) is a scan-conversion algorithm used in
computer graphics for drawing lines between two points.
It uses a mathematical equation to determine the pixels that make up the line.
The DDA algorithm process can be broken down into the following steps:
->Calculate the difference in x and y coordinates.
->The algorithm first calculates the difference in x and y coordinates between the
start and end points of the line.
-> Let's call these dx and dy respectively.
->Determine the number of steps.
-> The algorithm then determines the total number of steps needed to draw the line.
->This is calculated by finding the greatest absolute value between dx and dy and
adding 1.
->Calculate the increment in x and y.
->The algorithm then calculates the increment in x and y for each step.
->This is calculated by dividing dx and dy by steps.
->Let's call these Xincr and Yincr respectively.
->Initialize the current position: The algorithm initializes the current position
to the starting point of the line.
->Iterate and plot the pixels: The algorithm then iterates the number of steps, and
at each step, it calculates the new position of the line by adding Xincr and Yincr
to the current position. The algorithm then plots a pixel at the new position.
For example,
let's say we want to draw a line between the points (2,3) and (8,6).
The difference in x is 6 and the difference in y is 3.
The total number of steps is max(6,3) + 1 = 7 steps.
The increment in x is 6/7 = 0.857 and the increment in y is 3/7 = 0.428. Starting
at the point (2,3),
we calculate the new position for each step and plot a pixel:
Step 1: (2 + 0.857, 3 + 0.428) = (2.857, 3.428)
Step 2: (2.857 + 0.857, 3.428 + 0.428) = (3.714, 3.856)
Step 3: (3.714 + 0.857, 3.856 + 0.428) = (4.571, 4.284)
Step 4: (4.571 + 0.857, 4.284 + 0.428) = (5.428, 4.712)
Step 5: (5.428 + 0.857, 4.712 + 0.428) = (6.285, 5.14)
Step 6: (6.285 + 0.857, 5.14 + 0.428) = (7.142, 5.568)
Step 7: (7.142 + 0.857, 5.568 + 0.428) = (8, 6)
Conclusion:
The DDA algorithm is a simple and efficient scan-conversion algorithm for drawing
lines in computer graphics.
The algorithm calculates the pixels that make up the line by taking the difference
in x and y coordinates, determining the number of steps, calculating the increment
in x and y, and iterating to plot the pixels.
The example above demonstrates the algorithm in action, drawing a line between the
points (2,3) and (8,6).