|Artificial Intelligence Tutorial|
|Machine Learning Projects Tutorial||Python Video tutorial|
|Computer Graphics Video Tutorial||C++ Video Tutorial|
|Big Data Analytics Video Tutorial||Soft Computing Video Tutorial|
|Placement Video Tutorial||Java Video Tutorial|
Bresenham Line Drawing Algorithm Solved Example
We have three most popular line drawing algorithms in computer graphics.
1. DDA Line Drawing Algorithm
2. Bresenham Line Drawing Algorithm
3. Mid Point Line Drawing Algorithm
In this tutorial we will disscuss the Bresenham line algorithm and also, solve a numarical example using Bresenham algorithm.
Bresenham Line Drawing Algorithm is one of the simplest and most powerful line drawing algorithm in computer graphics. This algorithm overcomes the disadvantages of DDA algorithm.
Starting coordinates = (X, Y)
Ending coordinates = (Xn, Yn)
A four-step approach is followed to generate the line.
Calculate parameters ΔX, ΔY and M from the given input.
These parameters are calculated as –
ΔX = Xn – X
ΔY =Yn – Y
Calculate the decision parameter Pk.
It is calculated as – Pk = 2ΔY – ΔX
This decision variable is used to dicide, whether x coordinate should be incremented or y coordinate should be increamented or both.
Suppose the current point is (Xk, Yk) and the next point is (Xk+1, Yk+1).
Find the next point by following the below three cases –
Case 1: if (Pk<0)
Xk+1= Xk + 1
Pk+1 = Pk + 2ΔY
Case 2: if (Pk >= 0)
Xk+1= Xk + 1
Yk+1= Yk + 1
Pk+1 = Pk + 2ΔY – 2ΔX
Pk+1 will become the decision parameter for the next iteration. (Xk+1, Yk+1) is the (Xk+1, Yk+1) in the next iteration. Keep repeating Step-03 until the endpoint is reached or the number of iterations equals to (ΔX-1) times.