Mid-Point Line Drawing Algorithm in Computer Graphics
The Mid-point Subdivision algorithm is the extension of the Cyrus-Beck algorithm. The Mid-Point line plotting algorithm was introduced by “Pitway and Van Aken.” It is an incremental line drawing algorithm. In this algorithm, we perform incremental calculations. The calculations are based on the previous step to find the value of the next point. We perform the same process for each step. By using the mid-point subdivision algorithm, we can draw a line with close approximation between two points. The mid-point subdivision line drawing algorithm subdivides the line at its midpoints continuously.
The Mid-point Subdivision algorithm helps to compute or calculate the visible areas of lines that appear in the window. This line plotting algorithm follows the bisection method to divide the line into equal partitions.
Figure:1
In figure 1, we have a previous point K (x_{k},y_{k}), and there are two next points; the lower point B (x_{k }+ 1,y_{k}) and the above point AB (x_{k }+ 1,y_{k }+ 1). If the midpoint m is below the line, then we select point AB.
Let us assume, we have two points of the line = (x_{1}, x_{2}) and (y_{1}, y_{2}).
Here, it is (x_{1}< x_{2})
The Linear equation of a line is:
(x, y) = ax + by +c = 0 …………… (1)
d_{x }=x_{2 }- x_{1}
d_{y }=y_{2 }- y_{1}
As we know, the equation of simple line is:
y = mx +B
Here, m = dy/dx, we can write it as y = (dy/dx) x +B
Put the value of y in above equation, we get
(x, y) = dy (x) - (dx) y +B. dx = 0…………… (2)
By comparing equation (1) and (2)
a = dy
b = -dx
c = B. dx
There are some conditions given-
Condition 1: If all the points are on the line, then (x, y) = 0
Condition 2: If all the points are on the line, then (x, y) = Negative Number
Condition 3: If all the points are on the line, then (x, y) = positive Number
Now, m = (x_{k }+1, y_{k }+ 1/2)
d = m = (x_{k }+1, y_{k }+ 1/2)
Now, we calculate the distance value (d). Here, we discuss two cases:
Case 1: If
We select the lower point B
Then
The value of d is negative (d < 0)
We calculate the new and old value of d-
d_{n} = (x_{k }+2, y_{k }+ 1/2) {The value of x coordinate is incremented by 1}
Place the value of (x, y) in equation (1) andwe got the value of d_{o}
d_{n} = a (x_{k }+2) + b (y_{k }+ 1/2) + c {New Value of d}
d_{o} = a (x_{k }+1) + b (y_{k }+ 1/2) + c {Old Value of d}
Thus,
?d = d_{n }– d_{o }
_{ }= a (x_{k}+2) + b (y_{k }+1/2) + c – a (x_{k}+1) – b (y_{k }+1/2) - c
= a
?d = d_{n }– d_{o}
?d = d_{o }+ a
?d = d_{o }+dy {a = dy}
Case 2: If
We select the upper point AB
Then
The value of d is positive (d > 0)
We calculate the new and old value of d-
d_{n} = (x_{k }+2, y_{k }+ 3/2) {The value of x and y coordinate is incremented by 1}
We put the value of (x, y) in equation (1) andwe got the value of d_{o}
d_{n} = a (x_{k }+2) + b (y_{k }+ 3/2) + c {New Value of d}
d_{o} = a (x_{k }+1) + b (y_{k }+ 1/2) + c {Old Value of d}
Thus,
?d = d_{n }– d_{o }
_{ }= a (x_{k}+2) + b (y_{k }+3/2) + c – a (x_{k}+1) – b (y_{k }+1/2) - c
= a + b
?d = d_{n }– d_{o}
?d = d_{o }+ a +b
?d = d_{o }+dy – dx {a + (-b) = dy- dx}
Now, we calculate the initial decision parameter (d_{i})
d_{i }=(x_{1 }+1, y_{1}+ 1/2)
Put the value of d_{i }in equation (1)
d_{i} = a (x_{1 }+1) + b (y_{1 }+ 1/2) + c
= ax_{1 }+a + by_{1 }+ b/2 + c
= (x_{1}, y_{2}) + a + b/2
= 0 + a + b/2
d_{i }= dy – dx/2
Algorithm of Mid-Point Subdivision Line Drawing
Step 1: Start.
Step 2: Consider the starting point as (x_{1}, y_{1}) and endingpointas (x_{2}, y_{2}).
Step 3: Now, we will calculate ?d.
?d = 2 (?y -?x)
Step 4: Now, we will calculate the decision parameter d_{i }with the following formula.
_{ }d_{i }= 2?y - ?x
Step 5: The increment of x or y coordinate depends on the following two cases-
Case 1: If
d_{i }< 0
Then
x_{k+1 }=x_{k }+1
y_{k+1 }= y_{k }
_{ }d_{n }= d_{i }+ 2?y
Case 2: If _{}
d_{i }>= 0
Then
x_{k+1 }=x_{k }+1
y_{k+1 }=y_{k }+1
d_{n }= d_{i }+?d
Step 6: We will repeat step 5 until we found the ending point of the line.
Step 7: Stop.
Example: A line has a starting point (6,10) and ending point (13,17). Apply the Mid-point Line Drawing algorithm to draw a line.
Solution: We have two coordinates,
Starting Point = (x_{1}, y_{1}) = (6,10)
Ending Point = (x_{2}, y_{2}) = (13,17)
Step 1: First, we calculate ?x, ?y.
?x = x_{2 }– x_{1 }= 13-6 = 7
?y = y_{2 }– y_{1 }= 17-10 = 7
Step 2: Now, we are going to calculate the ?d.
?d= 2(?y-?x)
= 2 (7 – 7) = 0
The value of ?d= 0
Step 3: Now, we will calculate the decision parameter d_{i }with following formula.
_{ }d_{i }= 2?y - ?x
= 2 x 7 – 7 = 7
Step 4: The value of d_{i }>= 0. Case 2 is satisfied. Then
x_{k+1 }=x_{k }+1 = 6 +1 = 7
y_{k+1 }=y_{k }+1 = 10 + 1 = 11
d_{n }= d_{i }+?d = 7 + 0 = 7
d_{i} | d_{n} | x_{k+1} | y_{k+1} |
6 | 10 | ||
7 | 7 | 7 | 11 |
7 | 7 | 8 | 12 |
7 | 7 | 9 | 13 |
7 | 7 | 10 | 14 |
7 | 7 | 11 | 15 |
7 | 7 | 12 | 16 |
7 | 7 | 13 | 17 |
Step 5: Stop.
The Coordinates of drawn lines are-
P_{1 }= (6, 10)
P_{2 }= (7, 11)
P_{3 }= (8, 12)
P_{4 }= (9, 13)
P_{5 }= (10, 14)
P_{6 }= (11, 15)
P_{7 }= (12, 16)
P_{8 }= (13, 17)
Advantages of Mid-point Subdivision Line Drawing Algorithm
- It is very easy to implement.
- It is a less time-consuming algorithm.
- This algorithm uses basic arithmetic operations.
- It only requires integer data.
- The drawn line is smooth than other line drawing algorithms.
Disadvantages of Mid-point Subdivision Algorithm
- Sometimes this algorithm is not suitable due to critical images and graphics.
- The points have less accuracy. There are improvements needed.
Related Posts:
- Line Drawing Algorithm in Computer Graphics
- Line Clipping in Computer Graphics
- Filled Area Primitives Computer Graphics
- Midpoint Circle Drawing Algorithm in Computer Graphics
- Bresenham’s Line Drawing Algorithm in Computer Graphics
- Bresenham’s Circle Drawing Algorithm in Computer Graphics
- DDA line Drawing Algorithm in Computer Graphics
- Polygon Clipping in Computer Graphics
- Display Devices in Computer Graphics
- Applications of Computer Graphics