MidPoint 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 discuss the Midpoint line algorithm and also, solve a numarical example using the Bresenham algorithm.
Bresenham Algorithm
MidPoint 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.
Given –
Starting coordinates = (X0, Y0)
Ending coordinates = (Xn, Yn)
A four-step approach is followed to generate the line.
Step 1:
Calculate parameters ΔX, ΔY and M from the given input.
These parameters are calculated as –
ΔX = Xn – X0
ΔY =Yn – Y0
Step 2:
Calculate the value of initial decision parameter and ΔD.
These parameters are calculated as –
Dinitial = 2ΔY – ΔX
ΔD = 2(ΔY – ΔX)
This Dinitial is used to decide, whether the X coordinate should be incremented or the Y coordinate should be incremented or both.
Step 3:
Suppose the current point is (Xk, Yk) and the next point is (Xk+1, Yk+1).
The decision whether to increment X or Y coordinate or both depends upon the values of Dinitial. Find the next point by following the below three cases –
Case 1: if (Dinitial<0)
Xk+1= Xk + 1
Yk+1= Yk
Dnew = Dinitial + 2ΔY
Case 2: if (Dinitial >= 0)
Xk+1= Xk + 1
Yk+1= Yk + 1
Dnew = Dinitial + ΔD
Step 4:
Dnew 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.
Video Tutorial MidPoint Line Drawing algorithm Algorithm:
1. Solved Example MidPointLine drawing Algorithm
Video Tutorial Bresenham Line Drawing algorithm Algorithm:
1. Solved Example Bresenham Line drawing Algorithm
Video Tutorial DDA Algorithm:
1. Solved Example DDA Algorithm
2. Solved Example DDA Algorithm
3. Solved Example DDA Algorithm
Bresenham Line Drawing Algorithm Solved Example: If you like the material share it with your friends. Like the Facebook page for regular updates and YouTube channel for video tutorials.