Unit I J Line Drawing Algorithm - DDA Algorithm, Unit I K Bresenham's Algorithm
Unit I J Line Drawing Algorithm - DDA Algorithm, Unit I K Bresenham's Algorithm
Procedure-
Given-
The points generation using Bresenham Line Drawing Algorithm involves the following steps-
Step-01:
ΔX = Xn – X0
ΔY =Yn – Y0
Step-02:
It is calculated as-
Pk = 2ΔY – ΔX
Step-03:
Suppose the current point is (Xk, Yk) and the next point is (Xk+1, Yk+1).
Find the next point depending on the value of decision parameter P k.
Follow the below two cases-
Step-04:
Keep repeating Step-03 until the end point is reached or number of iterations equals to (ΔX-1)
times.
PRACTICE PROBLEMS BASED ON BRESENHAM
LINE DRAWING ALGORITHM-
Problem-01:
Calculate the points between the starting coordinates (9, 18) and ending coordinates (14, 22).
Solution-
Given-
Step-01:
ΔX = Xn – X0 = 14 – 9 = 5
ΔY =Yn – Y0 = 22 – 18 = 4
Step-02:
= 2ΔY – ΔX
=2x4–5
=3
So, decision parameter Pk = 3
Step-03:
Thus,
Pk+1 = Pk + 2ΔY – 2ΔX = 3 + (2 x 4) – (2 x 5) = 1
Xk+1 = Xk + 1 = 9 + 1 = 10
Yk+1 = Yk + 1 = 18 + 1 = 19
Similarly, Step-03 is executed until the end point is reached or number of iterations equals to 4
times.
(Number of iterations = ΔX – 1 = 5 – 1 = 4)
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).
Solution-
Given-
Step-01:
ΔX = Xn – X0 = 30 – 20 = 10
ΔY =Yn – Y0 = 18 – 10 = 8
Step-02:
=6
So, decision parameter Pk = 6
Step-03:
Thus,
Similarly, Step-03 is executed until the end point is reached or number of iterations equals to 9
times.
(Number of iterations = ΔX – 1 = 10 – 1 = 9)
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 6 30 18
Advantages of Bresenham Line Drawing Algorithm-
It is easy to implement.
It is fast and incremental.
It executes fast but less faster than DDA Algorithm.
The points generated by this algorithm are more accurate than DDA Algorithm.
It uses fixed points only.
Though it improves the accuracy of generated points but still the resulted line is not smooth.
This algorithm is for the basic line drawing.
It can not handle diminishing jaggies.
DDA Algorithm-
Procedure-
Given-
Starting coordinates = (X0, Y0)
Ending coordinates = (Xn, Yn)
The points generation using DDA Algorithm involves the following steps-
Step-01:
Step-02:
Find the number of steps or points in between the starting and ending coordinates.
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.
Problem-01:
Calculate the points between the starting point (5, 6) and ending point (8, 12).
Solution-
Given-
Starting coordinates = (X0, Y0) = (5, 6)
Ending coordinates = (Xn, Yn) = (8, 12)
Step-01:
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-
Starting coordinates = (X0, Y0) = (5, 6)
Ending coordinates = (Xn, Yn) = (13, 10)
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)
Problem-03:
Calculate the points between the starting point (1, 7) and ending point (11, 17).
Solution-
Given-
Starting coordinates = (X0, Y0) = (1, 7)
Ending coordinates = (Xn, Yn) = (11, 17)
Step-01:
Step-02:
Step-03:
As M = 1, so case-02 is satisfied.
Now, Step-03 is executed until Step-04 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)
Procedure-
Given-
Starting coordinates = (X0, Y0)
Ending coordinates = (Xn, Yn)
The points generation using Mid Point Line Drawing Algorithm involves the following
steps-
Step-01:
Step-02:
Step-03:
The decision whether to increment X or Y coordinate depends upon the flowing values
of Dinitial.
Follow the below two cases-
Step-04:
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:
Step-02:
Step-03:
Thus,
Xk+1 = Xk + 1 = 20 + 1 = 21
Yk+1 = Yk + 1 = 10 + 1 = 11
Dnew = Dinitial + ΔD = 6 + (-4) = 2
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).
Solution-
Given-
Starting coordinates = (X0, Y0) = (5, 9)
Ending coordinates = (Xn, Yn) = (12, 16)
Step-01:
Step-02:
Step-03:
Thus,
Xk+1 = Xk + 1 = 5 + 1 = 6
Yk+1 = Yk + 1 = 9 + 1 = 10
Dnew = Dinitial + ΔD = 7 + 0 = 7
5 9
7 7 6 10
7 7 7 11
7 7 8 12
7 7 9 13
7 7 10 14
7 7 11 15
7 12 16