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

I017 CG Lab3

Uploaded by

jashkathiria98
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views7 pages

I017 CG Lab3

Uploaded by

jashkathiria98
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

SVKM’s NMIMS University

Mukesh Patel School of Technology Management & Engineering

PROGRAM: BTech IT/MBATECH SEMESTER V

COURSE: Computer Graphics Practical Experiment: 3

Part A (To be referred by students)

SAVE THE FILE AND UPLOAD AS (RollNo_Name_Exp1)

Topic covered: Circle Drawing Algorithm (DDA:- Digital Differential Analyzer) and
Bresenham Line Drawing Algorithm.

Learning Objective: Learner would be able to


1. To understand the different algorithm for drawing a circle.
2. Bresenham's and the Mid-Point Circle Drawing algorithm, are designed to determine the points
needed for rasterizing a circle on a grid (like a computer screen or a graph paper) where only discrete
points are available.

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

PROGRAM: BTech IT/MBATECH SEMESTER VI

COURSE: Computer Graphics Practical Experiment:3

Student Name Ritesh Kumar Student Sap ID: - 70412100036


Student Roll Number I017 Date of Conduction :03/ 01 / 2024
Class :- MBA.Tech IT VI sem

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:

import matplotlib.pyplot as plt

x,y = map(int,input("Enter center coordiantes: ").split())


r = int(input("Enter radius: "))

y=r

p=1-r

x_o1,y_o1 = [x,],[y,]

while not(x >= y):


if p < 0:
x=x+1
x_o1.append(x)
y_o1.append(y)
p=p+2*x+1

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]

x_q1 = x_o1 + y_o2

2
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering

PROGRAM: BTech IT/MBATECH SEMESTER VI

COURSE: Computer Graphics Practical Experiment:3

y_q1 = y_o1 + x_o2

x_inv, y_inv = [-x for x in x_q1], [-y for y in y_q1]

#x_final = x_q1 + x_inv + x_inv + x_q1


#y_final = y_q1 + y_q1 + y_inv + y_inv

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)

x_final = x_q1 + x_q1[::-1] + x_inv + x_inv[::-1]


y_final = y_q1 + y_inv[::-1] + y_inv + y_q1[::-1]

plt.plot(x_final, y_final, marker = "o")


plt.axis('scaled')
plt.title("Mid-Point Circle Algorithm")
plt.show()

Output:

3
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering

PROGRAM: BTech IT/MBATECH SEMESTER VI

COURSE: Computer Graphics Practical Experiment:3

2. Draw a circle with Bresenham algorithm with X,Y(0,0) and Radius =10 and display the
coordinates and place a circle.

Code:

import matplotlib.pyplot as plt

x,y = map(int,input("Enter center coordiantes: ").split())


r = int(input("Enter radius: "))

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

PROGRAM: BTech IT/MBATECH SEMESTER VI

COURSE: Computer Graphics Practical Experiment:3

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]

x_q1 = x_o1 + y_o2


y_q1 = y_o1 + x_o2

x_inv, y_inv = [-x for x in x_q1], [-y for y in y_q1]

#x_final = x_q1 + x_inv + x_inv + x_q1


#y_final = y_q1 + y_q1 + y_inv + y_inv

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)

x_final = x_q1 + x_q1[::-1] + x_inv + x_inv[::-1]


y_final = y_q1 + y_inv[::-1] + y_inv + y_q1[::-1]

plt.plot(x_final, y_final, marker = "o")


plt.axis('scaled')
plt.title("Bresenham's Circle Algorithm")
plt.show()

Output:

5
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering

PROGRAM: BTech IT/MBATECH SEMESTER VI

COURSE: Computer Graphics Practical Experiment:3

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

PROGRAM: BTech IT/MBATECH SEMESTER VI

COURSE: Computer Graphics Practical Experiment:3

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

You might also like