Line Drawing Algos
Line Drawing Algos
Problem-02:
Calculate the points between the starting point (5, 6) and ending point (13, 10).
Problem-03
Calculate the points between the starting point (1, 7) and ending point (11, 17).
9 18
3 1 10 19
1 -1 11 20
-1 7 12 20
7 5 13 21
5 3 14 22
Problem-02:
Calculate the points between the starting coordinates (20, 10) and ending coordinates (30, 18).
Mid Point Line Drawing Algorithm
Problem-01:
Calculate the points between the starting coordinates (20, 10) and ending coordinates (30, 18).
Solution-
Given-
Starting coordinates = (X0, Y0) = (20, 10) ,Ending coordinates = (Xn, Yn) = (30, 18)
Step-01: Calculate ΔX and ΔY from the given input.
ΔX = Xn – X0 = 30 – 20 = 10 ΔY =Yn – Y0 = 18 – 10 = 8
Step-02: Calculate Dinitial and ΔD as-:
Dinitial = 2ΔY – ΔX = 2 x 8 – 10 = 6 ΔD = 2(ΔY – ΔX) = 2 x (8 – 10) = -4
Step-03:
As Dinitial >= 0, so case-02 is satisfied.
Thus, Xk+1 = Xk + 1 = 20 + 1 = 21. Yk+1 = Yk + 1 = 10 + 1 = 11, Dnew = Dinitial + ΔD = 6 + (-4) = 2
Similarly, Step-03 is executed until the end point is reached.
20 10
6 2 21 11
2 -2 22 12
-2 14 23 12
14 10 24 13
10 6 25 14
6 2 26 15
2 -2 27 16
-2 14 28 16
14 10 29 17
10 30 18
Problem-02:
Calculate the points between the starting coordinates (5, 9) and ending coordinates (12, 16).