0% found this document useful (0 votes)
6 views7 pages

Assignment on Computer Graphics urmi

The document provides an assignment on the Midpoint Line Drawing Algorithm, detailing its definition, steps for implementation, advantages, and disadvantages. It includes mathematical examples demonstrating the algorithm's application for various line slopes. The conclusion emphasizes the algorithm's efficiency and simplicity while noting its limitations in handling complex scenarios.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views7 pages

Assignment on Computer Graphics urmi

The document provides an assignment on the Midpoint Line Drawing Algorithm, detailing its definition, steps for implementation, advantages, and disadvantages. It includes mathematical examples demonstrating the algorithm's application for various line slopes. The conclusion emphasizes the algorithm's efficiency and simplicity while noting its limitations in handling complex scenarios.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

The people’s university of Bangladesh

Department of Computer Science and Engineering

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.

Submission Date: 20-03-25


Topic:
• Midpoint Line Drawing Algorithm with explanation.
• Math solves (Minimum five)

• Midpoint Line Drawing Algorithm with explanation.

❖ Definition of Midpoint Line drawing Algorithm:

➢ The Midpoint Line Drawing Algorithm is an efficient algorithm used to


draw straight lines on raster displays.
➢ It is based on the idea of determining the closest pixel to the theoretical
line at each step by using the midpoint between two possible pixel
positions.
➢ This algorithm is a more optimized version of the Bresenham's line
algorithm and works for all octants of the line (in all directions).

❖ Explanation of the Midpoint Line Drawing Algorithm:

Steps:

1. Initialization:

• First, calculate the differences in the coordinates:

Δx=x1−x0

Δy=y1−y0

• Depending on the slope of the line, either Δx or Δy is more significant in


determining the direction of movement. For simplicity, we'll assume the slope is
between 0 and 1 (the line is "shallow").

2. Decision Variable: Define the initial decision variable d as:

d= 2Δy − Δx

This is based on the difference in the y-direction compared to the x-direction.


3. Plot the initial point: Plot the starting point P0 (x0 ,y0) on the screen.
4. Increment the x-coordinate:
o For each subsequent step, check the value of d:
▪ If d < 0, the next point will be plotted horizontally (i.e., increment
the x-coordinate).
▪ If d ≥ 0, the next point will be plotted both horizontally and
vertically (i.e., increment both x and y coordinates).
o Update the decision variable d after each step:
▪ If d < 0, update d by adding 2 Δy (i.e., d = d + 2Δy ).
▪ If d ≥ 0, update d by adding 2 (Δy−Δx) (i.e., d=d+2 (Δy−Δx))
5. Repeat steps until the endpoint is reached.

❖ Advantages of Midpoint Line Drawing Algorithm:

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:

• It is relatively simple to implement.


• The algorithm primarily works by calculating the midpoint between two pixels
and deciding which pixel to color, based on the error term.

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:

1. Limited to Lines with Moderate Slopes:

• 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.

2. Not Suitable for Curves:

• The algorithm is specifically designed for drawing straight lines.


• It cannot be directly applied to curves without modifications, making it less
versatile for complex shapes.

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.

4. Requires a Discrete Grid:

• 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.

5. Limited to Integer Arithmetic:

• While integer arithmetic is an advantage in terms of speed, it can also be a


limitation in cases where more precision .
• floating-point calculations might be beneficial, especially for more complex
graphical operations.
• Math solves (Minimum five)

Example 1: Line from (0, 0) to (6, 4) (Shallow line)

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)

Example 2: Line from (0, 0) to (4, 6) (Steep line)

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)

Result: Points plotted: (0,0), (1,1), (2,2), (3,3), (4,4), (5,5)

Example 4: Line from (0, 0) to (7, 3) (Shallow line)

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy