In: Computer Science
Using DDA algorithm, find the pixels for the line drawn from (8, 8) to (16, 14)..
Procedure-
Given-
The points generation using DDA Algorithm involves the following steps-
Step-01:
Calculate ΔX, ΔY and M from the given input.
These parameters are calculated as-
Step-02:
Find the number of steps or points in between the starting and ending coordinates.
if (absolute (ΔX) > absolute (ΔY))
Steps = absolute (ΔX);
else
Steps = absolute (ΔY);
Step-03:
Suppose the current point is (Xp, Yp) and the next point is (Xp+1, Yp+1).
Find the next point by following the below three cases-
Step-04:
Keep repeating Step-03 until the end point is reached or the number of generated new points (including the starting and ending points) equals to the steps count.
solution
Given-
step 1
Calculate ΔX, ΔY and M from the given input.
Step-02:
Calculate the number of steps.
As |ΔX| > |ΔY| = 8 > 6, so number of steps = ΔX = 8
Step-03:
As M < 1, so case-01 is satisfied.
Now, Step-03 is executed until Step-04 is satisfied.
Xp | Yp | Xp+1 | Yp+1 | Round off (Xp+1, Yp+1) |
8 | 8 | 9 | 8.75 | (9, 9) |
10 | 9.5 | (10, 10) | ||
11 | 10.25 | (11,10 ) | ||
12 | 11 | (12, 11) | ||
13 | 11.75 | (13, 12) | ||
14 |
12.5 | (14,13) |
15 | 13.25 | (15, 13) | ||
16 | 14 | (16, 14) |