Assignment on Computer Graphics urmi
Assignment on Computer Graphics urmi
Assignment on
“ Midpoint Line Drawing Algorithm with explanation ” .
CSE -405 (Computer Graphics)
Submitted To:
Md.Tofazzol Hosen.
Lecturer.
Dept of CSE
The People’s University of Bangladesh.
Submitted By:
Hanufa Akter .
ID: 23559202007
Batch : 59th
Dept of CSE
The People’s University of Bangladesh.
Steps:
1. Initialization:
Δx=x1−x0
Δy=y1−y0
d= 2Δy − Δx
1. Efficiency:
• The algorithm only requires integer arithmetic, making it very fast and suitable
for real-time applications like computer graphics.
• There’s no need for floating-point operations, which speeds up the drawing
process.
2. Simplicity:
3. Optimality:
• It ensures that the line is drawn as close as possible to the ideal line.
• It minimizes errors in the pixel selection process, resulting in a more accurate
representation of the line on a raster grid.
4. No Floating-Point Calculations:
• Since it uses integer values, the algorithm avoids the computational overhead
associated with floating-point calculations, which is advantageous for systems
with limited processing power.
5. Line Quality:
• The algorithm produces good-quality lines that appear smooth and continuous,
without significant gaps or rough edges, when viewed at a reasonable scale.
❖ Disadvantages of Midpoint Line Drawing Algorithm:
• The basic algorithm is most efficient for lines with moderate slopes.
• For very steep lines (near vertical) or lines with extremely shallow slopes, it may
require additional steps or adjustments to handle them properly.
3. Aliasing:
• While the algorithm minimizes errors in pixel selection, there can still be some
aliasing on the line, especially for lines that are not perfectly aligned with the
pixel grid.
• Anti-aliasing techniques are often required for smoother lines.
• The algorithm operates on a raster grid, which means the output is constrained
to the pixel grid.
• The line may not appear as smooth as desired when zoomed in or on very high-
resolution displays unless anti-aliasing techniques are used.
1. Initial values:
o P0 (0,0) , P1 (6,4)
o Δx=6−0=6
o Δy=4−0=4
o d=2×4−6=2
2. Steps:
o Plot (0,0)
o d= 2, d > 0 ⇒ y = 1, d=2+2×(4−6) =−2
o Plot (1,1)
o d = −2, d < 0 ⇒ x = 2, d= −2+2×4 = 6
o Plot (2,1)
o d= 6, d > 0 ⇒ y = 2, d = 6+2×(4−6) = 2
o Plot (3,2)
o d=2, d > 0 ⇒ y=3, d = 2+2×(4−6) = −2
o Plot (4,3)
o d= −2, d < 0 ⇒ x= 5, d = −2+2×4 = 6
o Plot (5,3)
o d=6, d > 0 ⇒ y=4, d = 6+2×(4−6) = 2
o Plot (6,4)
Result: Points plotted: (0,0), (1,1), (2,1), (3,2), (4,3), (5,3), (6,4)
1. Initial values:
o P0(0,0), P1(4,6)
o Δx=4−0=4
o Δy=6−0=6
o d=2×6−4=8
2. Steps:
o Plot (0,0)
o d=8, d>0 ⇒ y=1, d=8+2× (6−4) =12
o Plot (0,1)
o d=12, d>0 ⇒ y=2, d=12+2× (6−4) =16
o Plot (0,2)
o d=16, d>0 ⇒ y=3, d=16+2× (6−4) =20
o Plot (0,3)
o d=20, d>0 ⇒ y=4, d=20+2× (6−4) =24
o Plot (0,4)
o d=24, d>0 ⇒ y=5, d=24+2× (6−4) =28
o Plot (0,5)
o d=28, d>0 ⇒ y=6, d=28+2× (6−4) =32
o Plot (0,6)
Result: Points plotted: (0,0), (0,1), (0,2), (0,3), (0,4), (0,5), (0,6)
Example 3: Line from (0, 0) to (5, 5) (Diagonal line)
1. Initial values:
o P0 (0,0), P1 (5,5)
o Δx=5−0=5
o Δy=5−0=5
o d=2×5−5=5
2. Steps:
o Plot (0,0)
o d=5, d>0 ⇒ y=1, d=5+2× (5−5) =5
o Plot (1,1)
o d=5, d>0 ⇒ y=2, d=5+2× (5−5) =5
o Plot (2,2)
o d=5, d>0d ⇒ y=3, d=5+2× (5−5) =5
o Plot (3,3)
o d=5, d>0 ⇒ y=4, d=5+2× (5−5) =5
o Plot (4,4)
o d=5, d>0 ⇒ y=5, d=5+2× (5−5) =5
o Plot (5,5)
1. Initial values:
o P0 (0,0), P1 (7,3)
o Δx=7−0=7
o Δy=3−0=3
o d=2×3−7= −1
2. Steps:
o Plot (0,0)
o d= −1, d<0 ⇒ x=1, d=−1+2×3=5
o Plot (1,0)
o d=5, d>0 ⇒ y=1, d=5+2× (3−7) =−3
o Plot (2,1)
o d= −3, d<0 ⇒ x=3, d=−3+2×3=3
o Plot (3,1)
o d=3, d>0 ⇒ y=2, d=3+2× (3−7) =−1
o Plot (4,2)
o d= −1, d <0 ⇒ x=5, d= −1+2×3=5
o Plot (5,2)
o d=5, d>0 ⇒ y= 3, d=5+2× (3−7) =−3
o Plot (6,3)
o d=−3, d<0 ⇒ x=7, d=−3+2×3=3
o Plot (7,3)
Result: Points plotted: (0,0), (1,0), (2,1), (3,1), (4,2), (5,2), (6,3), (7,3)
Example 5: Line from (1, 1) to (5, 8) (Steep line)
1. Initial values:
o P0 (1,1) , P1 (5,8)
o Δx=5−1=4
o Δy=8−1=7
o d=2×7−4=10
2. Steps:
o Plot (1,1)
o d=10, d>0 ⇒ y=2, d=10+2×(7−4)=16
o Plot (1,2)
o d=16, d>0 ⇒ y=3, d=16+2×(7−4)=22
o Plot (1,3)
o d=22, d>0 ⇒ y=4, d=22+2×(7−4)=28
o Plot (1,4)
o Plot remaining points similarly.
These five examples show how the Midpoint Line Drawing Algorithm can work for
different types of lines and slopes. By following these steps, we can plot a straight line
between any two points efficiently!
In summary, the Midpoint Line Drawing Algorithm is widely used due to its efficiency
and simplicity, but it may require additional techniques or modifications when working
with more complex scenarios, such as curves, steep lines, or high-quality rendering with
minimal aliasing.