Bresenham's Line Drawing Algorithm: Computer Graphics
Bresenham's Line Drawing Algorithm: Computer Graphics
Procedure-
Given-
Starting coordinates = (X0, Y0)
Ending coordinates = (Xn, Yn)
The points generation using Bresenham Line Drawing Algorithm involves the
following steps-
Step-01:
Step-02:
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-
Starting coordinates = (X0, Y0) = (9, 18)
Ending coordinates = (Xn, Yn) = (14, 22)
Step-01:
Step-02:
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
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-
Starting coordinates = (X0, Y0) = (20, 10)
Ending coordinates = (Xn, Yn) = (30, 18)
Step-01:
Step-02:
Step-03:
Thus,
Pk+1 = Pk + 2ΔY – 2ΔX = 6 + (2 x 8) – (2 x 10) = 2
Xk+1 = Xk + 1 = 20 + 1 = 21
Yk+1 = Yk + 1 = 10 + 1 = 11
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-
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
Advantages of Mid Point Line Drawing
Algorithm-
The advantages of Mid Point Line Drawing Algorithm are-
Accuracy of finding points is a key feature of this algorithm.
It is simple to implement.
It uses basic arithmetic operations.
It takes less time for computation.
The resulted line is smooth as compared to other line drawing algorithms.
The points for other octact are generated using the eight symmetry property.
Procedure-
Given-
Centre point of Circle = (X0, Y0)
Radius of Circle = R
Step-01:
Step-02:
Step-03:
Suppose the current point is (Xk, Yk) and the next point is (Xk+1, Yk+1).
Find the next point of the first octant depending on the value of decision
parameter Pk.
Follow the below two cases-
Step-04:
If the given centre point (X0, Y0) is not (0, 0), then do the following and plot
the point-
Xplot = Xc + X0
Yplot = Yc + Y0
Step-05:
Step-06:
Problem-01:
Given the centre point coordinates (0, 0) and radius as 8, generate all the
points to form a circle.
Solution-
Given-
Centre Coordinates of Circle (X0, Y0) = (0, 0)
Radius of Circle = 8
Step-01:
Step-02:
Step-03:
Thus,
Xk+1 = Xk + 1 = 0 + 1 = 1
Yk+1 = Yk = 8
Pk+1 = Pk + 4 x Xk+1 + 6 = -13 + (4 x 1) + 6 = -3
Step-04:
This step is not applicable here as the given centre point coordinates is (0,
0).
Step-05:
(0, 8)
-13 -3 (1, 8)
-3 11 (2, 8)
11 5 (3, 7)
5 7 (4, 6)
7 (5, 5)
Algorithm Terminates
These are all points for Octant-1.
(0, 8) (5, 5)
(1, 8) (6, 4)
(2, 8) (7, 3)
(3, 7) (8, 2)
(4, 6) (8, 1)
(5, 5) (8, 0)
Here, all the points have been generated with respect to quadrant-1-
Given the centre point coordinates (10, 10) and radius as 10, generate all the
points to form a circle.
Solution-
Given-
Centre Coordinates of Circle (X0, Y0) = (10, 10)
Radius of Circle = 10
Step-01:
Step-02:
Step-03:
Thus,
Xk+1 = Xk + 1 = 0 + 1 = 1
Yk+1 = Yk = 10
Pk+1 = Pk + 4 x Xk+1 + 6 = -17 + (4 x 1) + 6 = -7
Step-04:
This step is applicable here as the given centre point coordinates is (10, 10).
Xplot = Xc + X0 = 1 + 10 = 11
Yplot = Yc + Y0 = 10 + 10 = 20
Step-05:
Step-03 and Step-04 are executed similarly until X plot => Yplot as follows-
Algorithm Terminates
These are all points for Octant-1.
Algorithm calculates all the points of octant-1 and terminates.
Now, the points of octant-2 are obtained using the mirror effect by swapping
X and Y coordinates.
Here, all the points have been generated with respect to quadrant-1-