Example 1: Draw line segment from point (2, 4) to (9, 9) by using Digital Differential Analyzer algorithm.
Solution: We know usual equation of line is specified via
y = mx+c; here m =( y_{1} - y_{0}/( x_{1} - x_{0})
Specified (x_{0}, y_{0}) → (2, 4) ; (x_{1}, y_{1}) → (9, 9)
⇒ m = ( y_{1} -y_{0})/( x_{1} - x_{0})
= (9 - 4) /(9 - 2)= 5/7..that is 0< m<1
C = y_{1}- mx_{1} = 9 - ((5/7)* 9) = (63 - 45)/7 = 18/7
Conversely, by Equation of line (y = mx + c) we have
Y = (5/7)x + (18/7)
DDA Algorithm Two case:
Case 1: m < 1 x_{i} + 1 = x_{i} + 1 y_{i} + 1 = y_{i} + m
Case 2: m > 1 x_{i} + 1 = x_{i} + (1/m)
y_{i} + 1 = y_{i} + 1
Since 0 < m < 1 so as per to DDA algorithm case 1
x_{i} + 1 = x_{i} + 1 y_{i} + 1 = y_{i} + m
Specified (x_{0}, y_{0}) = (2, 4)
1) x_{1} = x_{0} + 1 = 3
Y_{1} = y_{0} + m= 4 +5/7= 4 (5/7)
Place pixel (x_{0}, round y, colour)
That is put on (3, 5)
2) x_{2} = x_{1} + 1 = 3 + 1 = 4
y_{2} = y_{1} + m = (33/7) +(5/7)
Place on (4, 5)
Likewise go on till (9, 9) is reached.