Mid Point Line Generation Algorithm
Mid Point Line Generation Algorithm
The Mid-Point Line Drawing Algorithm is used to draw straight lines between two points
on a pixel grid using mid-point finding approach. It is popular because it is both efficient
and simple. In this chapter, we will explain the internal details of this algorithm with
examples for a better understanding.
We must follow a set of concepts to understand this algorithm well. These are listed
below
Pixel Selection − The algorithm looks at the mid-point between two possible pixel
positions. It then uses a decision variable to pick the pixel that is closest to the
actual line.
Decision Variable − This variable helps decide which pixel is closer to the line. It
is updated with each step to show how much error has built up. This guides the
choice of the next pixel.
Algorithm Steps
Initialization − First, we find the differences Δx and Δy between the start point
(x0, y0) and the end point (x1, y1). Then we set the initial decision variable d based
on the midpoint rule.
Updating the Decision Variable: Update the decision variable d based on how
the error changes when we move to the next pixel.
Example 1
Let us take an example to demonstrate how this algorithm works.
1 4 2 d + dy = -4 + 3 = -1 Increment x (4, 2)
2 5 2 d + dy = -1 + 3 = 2 Increment x (5, 2)
Page 3 of 7
4 7 3 d + dy = -9 + 3 = -6 Increment x (7, 3)
5 8 3 d + dy = -6 + 3 = -3 Increment x (8, 3)
6 9 3 d + dy = -3 + 3 = 0 Increment x (9, 3)
9 12 4 d + dy = -8 + 3 = -5 Increment x (12, 4)
10 13 4 d + dy = -5 + 3 = -2 Increment x (13, 4)
11 14 4 d + dy = -2 + 3 = 1 Increment x (14, 4)
14 17 5 d + dy = -7 + 3 = -4 Increment x (17, 5)
Example 2
Let us see another example. Consider the input points (1, 1) and (5, 12).
2 2 3 d - dx = 16 - 4 = 12 Increment x, y (2, 3)
3 2 4 d - dx = 12 - 4 = 8 Increment y (2, 4)
4 3 5 d - dx = 8 - 4 = 4 Increment x, y (3, 5)
5 3 6 d - dx = 4 - 4 = 0 Increment y (3, 6)
6 3 7 d - dx = 0 - 4 = -4 Increment y (3, 7)
8 4 9 d - dx = 3 - 4 = -1 Increment y (4, 9)
Chapters Categories
Conclusion
In this chapter, we explained the Mid-Point Line Drawing Algorithm in detail. We covered
how it works to draw straight lines on pixel grids. We highlighted the key concepts like