3 - DDA Algorithm
3 - DDA Algorithm
DDA Algorithm-
Procedure-
Given-
The points generation using DDA Algorithm involves the following steps-
Digital Differential Analyzer
Step-01:
ΔX = Xn – X0
ΔY =Yn – Y0
M = ΔY / ΔX
Step-02:
Find the number of steps or points in between the starting and ending coordinates.
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-
Digital Differential Analyzer
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.
Problem-01:
Calculate the points between the starting point (5, 6) and ending point (8, 12).
Solution-
Given-
Digital Differential Analyzer
Starting coordinates = (X0, Y0) = (5, 6)
Ending coordinates = (Xn, Yn) = (8, 12)
Step-01:
ΔX = Xn – X0 = 8 – 5 = 3
ΔY =Yn – Y0 = 12 – 6 = 6
M = ΔY / ΔX = 6 / 3 = 2
Step-02:
Step-03:
5 6 5.5 7 (6, 7)
6 8 (6, 8)
6.5 9 (7, 9)
7 10 (7, 10)
8 12 (8, 12)
Problem-02:
Calculate the points between the starting point (5, 6) and ending point (13, 10).
Solution-
Given-
Step-01:
Step-02:
Step-03:
5 6 6 6.5 (6, 7)
7 7 (7, 7)
8 7.5 (8, 8)
9 8 (9, 8)
10 8.5 (10, 9)
11 9 (11, 9)
13 10 (13, 10)
Digital Differential Analyzer
Problem-03:
Calculate the points between the starting point (1, 7) and ending point (11, 17).
Solution-
Given-
Step-01:
ΔX = Xn – X0 = 11 – 1 = 10
ΔY =Yn – Y0 = 17 – 7 = 10
M = ΔY / ΔX = 10 / 10 = 1
Digital Differential Analyzer
Step-02:
Calculate the number of steps.
As |ΔX| = |ΔY| = 10 = 10, so number of steps = ΔX = ΔY = 10
Step-03:
As M = 1, so case-02 is satisfied.
1 7 2 8 (2, 8)
3 9 (3, 9)
4 10 (4, 10)
5 11 (5, 11)
6 12 (6, 12)
7 13 (7, 13)
8 14 (8, 14)
9 15 (9, 15)
10 16 (10, 16)
11 17 (11, 17)
Digital Differential Analyzer
It is a simple algorithm.
It is easy to implement.
It avoids using the multiplication operation which is costly in terms of time complexity.