I014 - CG-Lab 3
I014 - CG-Lab 3
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 mid point and Bresenham circle Drawing Algorithm with
given x and y coordinates.
Assignment 2
1. Draw a circle with Mid point algorithm with X,Y(0,0) and Radius =10 and display the
coordinates and place a circle.
2
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.
import matplotlib.pyplot as plt
def bresenham_circle(x0, y0, radius):
x = radius
y=0
err = 0
points = []
while x >= y:
points.append((x0 + x, y0 + y))
points.append((x0 + y, y0 + x))
points.append((x0 - y, y0 + x))
points.append((x0 - x, y0 + y))
points.append((x0 - x, y0 - y))
points.append((x0 - y, y0 - x))
points.append((x0 + y, y0 - x))
points.append((x0 + x, y0 - y))
y += 1
err += 1 + 2*y
if 2*(err-x) + 1 > 0:
x -= 1
err += 1 - 2*x
return points
points = bresenham_circle(0, 0, 10)
# plot the points
plt.scatter([x for x, y in points], [y for x, y in points])
# draw the circle
circle = plt.Circle((50, 50), 30, fill=False)
plt.gcf().gca().add_artist(circle)
plt.show()
3
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.
Comparison:
Both algorithms are highly efficient and accurate for drawing circles, and the differences between
them are subtle.
The Midpoint Circle Algorithm generally requires fewer arithmetic operations per pixel compared to
Bresenham's algorithm, making it slightly more efficient in terms of computation.
The differences in performance are usually minimal, and the choice between the two often depends
on factors such as ease of implementation and specific requirements of the application.
Conclusion:-
In practice, the choice between the Midpoint Circle Algorithm and Bresenham's Circle Algorithm may not
significantly impact performance in modern computing environments.
Both algorithms are widely used and have stood the test of time, demonstrating their reliability and efficiency.
The choice between them may come down to personal preference, ease of understanding, or specific requirements of
the application or platform.
Ultimately, both algorithms are excellent choices for drawing circles, and the "better" algorithm depends on the
specific context and requirements of the application.