I017 CG Lab3
I017 CG Lab3
Topic covered: Circle Drawing Algorithm (DDA:- Digital Differential Analyzer) and
Bresenham Line Drawing Algorithm.
Prerequisites:-
- Python and c
Outcomes:-
- Student will explore the method to draw line with x and y coordinates for drawing a circle.
1|P a g e
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
Aim:- To learn the algorithm to draw a midpoint and Bresenham circle Drawing Algorithm with
given x and y coordinates.
Assignment 2
1. Draw a circle with Midpoint algorithm with X,Y(0,0) and Radius =10 and display the
coordinates and place a circle.
Code:
y=r
p=1-r
x_o1,y_o1 = [x,],[y,]
elif p >= 0:
x=x+1
x_o1.append(x)
y=y-1
y_o1.append(y)
p=p-2*y+2*x+1
x_o2 = x_o1[::-1]
y_o2 = y_o1[::-1]
2
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
print("Quadrant one(x):",x_q1)
print("Quadrant one(y):",y_q1)
print("Quadrant two(x):",x_inv)
print("Quadrant two(y):",y_q1)
print("Quadrant three(x):",x_inv)
print("Quadrant three(y):",y_inv)
print("Quadrant four(x):",x_q1)
print("Quadrant four(y):",y_inv)
Output:
3
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
2. Draw a circle with Bresenham algorithm with X,Y(0,0) and Radius =10 and display the
coordinates and place a circle.
Code:
y=r
d=3-2*r
x_o1,y_o1 = [x,],[y,]
while x < y:
4
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
x += 1
if d < 0:
d=d+4*x+6
else:
y -= 1
d = d + 4 * (x - y) + 10
x_o1.append(x)
y_o1.append(y)
x_o2 = x_o1[::-1]
y_o2 = y_o1[::-1]
print("Quadrant one(x):",x_q1)
print("Quadrant one(y):",y_q1)
print("Quadrant two(x):",x_inv)
print("Quadrant two(y):",y_q1)
print("Quadrant three(x):",x_inv)
print("Quadrant three(y):",y_inv)
print("Quadrant four(x):",x_q1)
print("Quadrant four(y):",y_inv)
Output:
5
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
3. Find out the difference in both the algorithms and justify which one is better algorithm for
circle drawing algorithm.
Ans.
Midpoint Algorithm:
Pros:
Generally more accurate in depicting the ideal circle equation, especially for steep
lines.
Can result in smoother lines with less aliasing due to its error correction mechanism.
Cons:
Slower than Bresenham's algorithm due to more complex calculations.
Less straightforward implementation.
6
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
Bresenham's Algorithm:
Pros:
Extremely fast due to its reliance on integer arithmetic.
Simple and efficient to implement.
Widely used and well-understood algorithm.
Cons:
Slightly less accurate than the midpoint algorithm, especially for steep lines.
Can exhibit minor aliasing in certain situations.
Midpoint is the better algorithm as it provides a more accurate circle but at the cost of more
calculations.
Conclusion:-
Find out the below parameters for both the algorithm.
Sr.N Parameters Bresenham's Circle Drawing Mid-Point Circle Drawing
o Algorithm Algorithm
1. Efficiency in Pixel Selection More efficient because it Efficient but less than that of
involves fewer calculations and Bresenham’s Algorithm.
utilizes integer arithmetic
extensively
2. Balancing Accuracy and Performance Balances well, emphasizes Balances well, accuracy maintained
efficiency
3. Rasterizing Geometric Shapes Widely used for rasterization Commonly used for rasterization
4. Symmetry Utilization Utilizes symmetry for Utilizes symmetry for optimization
optimization
5. Smoothness in Low-Resolution Displays Provides smooth circles Provides smooth circles