[go: up one dir, main page]

0% found this document useful (0 votes)
87 views6 pages

Sybsc - IT Computer Graphics

The document discusses Bresenham's line drawing algorithm which draws a line between two points (x1, y1) and (x2, y2) by calling a draw_point function to plot each point, and provides Python code to implement this algorithm. It also explains Bresenham's circle drawing algorithm involves initializing the circle's center and radius, plotting points on the circumference using a decision parameter updated through incremental calculations, and exploiting the circle's symmetry. Midpoint circle drawing is similarly described.

Uploaded by

atraw2004
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)
87 views6 pages

Sybsc - IT Computer Graphics

The document discusses Bresenham's line drawing algorithm which draws a line between two points (x1, y1) and (x2, y2) by calling a draw_point function to plot each point, and provides Python code to implement this algorithm. It also explains Bresenham's circle drawing algorithm involves initializing the circle's center and radius, plotting points on the circumference using a decision parameter updated through incremental calculations, and exploiting the circle's symmetry. Midpoint circle drawing is similarly described.

Uploaded by

atraw2004
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/ 6

Bresenhams line drawing algorithm

def draw_line(x1, y1, x2, y2):

dx = abs(x2 - x1)

dy = abs(y2 - y1)

slope = dy > dx

if slope:

x1, y1 = y1, x1

x2, y2 = y2, x2

if x1 > x2:

x1, x2 = x2, x1

y1, y2 = y2, y1

dx = abs(x2 - x1)

dy = abs(y2 - y1)

error = 0

derror = dy * 2

y = y1

for x in range(x1, x2 + 1):

if slope:
draw_point(y, x)

else:

draw_point(x, y)

error += derror

if error > dx:

y += 1 if y2 > y1 else -1

error -= dx * 2

def draw_point(x, y):

print(f"({x}, {y})") # You can replace this with your preferred method of
drawing

# Example usage:

draw_line(1, 1, 8, 5)

This implementation of Bresenham's line drawing algorithm draws a line from


the point (x1, y1) to the point (x2, y2). The draw_point function is called
to draw individual points. You can replace it with your own function or library
calls to draw lines in a graphical environment.
https://mu.ac.in/wp-content/uploads/2022/03/USIT-405-Computer-Graphics-and-Animation.pdf
https://mu.ac.in/wp-content/uploads/2022/03/USIT-405-Computer-Graphics-and-Animation.pdf

explain breseham’s circle drawing algorithm

1. Initialization: Choose the center of the circle (x_center, y_center) and the radius r.
2. Plotting Points: Begin by plotting the points (x, y) on the circumference of the circle, where x
varies from 0 to r and y is determined based on the circle equation.
3. Decision Parameter: At each step, determine the next point to plot based on a decision
parameter. The decision parameter is calculated based on the circle equation and the distance
of the midpoint from the true circle.
4. Incremental Calculations: Use incremental calculations to update the decision parameter and
efficiently move along the circumference of the circle.
5. Symmetry: Exploit the symmetry of the circle to minimize computations. Plot points in one
octant of the circle and mirror them to other octants to complete the circle.
6. Repeat: Continue plotting points until reaching the maximum symmetry point, ensuring that the
entire circumference of the circle is covered.

By following these steps, Bresenham's circle drawing algorithm efficiently draws circles with
minimal computational overhead. It's particularly useful in scenarios where performance is
crucial, such as real-time graphics rendering or embedded systems.

This explanation is in line with the teachings of computer graphics and animation courses,
providing a practical and efficient method for drawing circles that students can understand and
implement.
https://mu.ac.in/wp-content/uploads/2022/03/USIT-405-Computer-Graphics-and-
Animation.pdf

midpoint circle drawing algorithm

Here's a breakdown of the algorithm according to the book:

1. Initialization: Choose the center of the circle (x_center, y_center) and the radius r.
2. Initial Decision Parameter: Calculate the initial decision parameter d based on the selected
point (0, r) and the circle equation.
3. Plotting Points: Begin plotting the points on the circumference of the circle. Start from the
topmost point (0, r) and move along the circumference using symmetry properties.
4. Incremental Calculations: Use incremental calculations to update the decision parameter and
efficiently move along the circumference of the circle. Update the decision parameter based on
the current midpoint and the next potential pixel to be plotted.
5. Symmetry: Exploit the symmetry of the circle to minimize computations. Plot points in one
octant of the circle and mirror them to other octants to complete the circle.
6. Decision Parameter Update: At each step, update the decision parameter to determine
whether to choose the next pixel along the same y-coordinate or to move to the next y-
coordinate.
7. Repeat: Continue plotting points until reaching the maximum symmetry point, ensuring that the
entire circumference of the circle is covered.
By following these steps, the midpoint circle drawing algorithm efficiently draws circles with
minimal computational overhead. It's particularly useful in scenarios where performance is
crucial, such as real-time graphics rendering or embedded systems.

Here's how it works:

1. Start with a Center: You pick a point in the middle of your paper. This is the center of your
circle.
2. Think about Distance: You think about how far away you want the circle's edge to be from the
center. This distance is called the radius.
3. Plot Points: Now, you start plotting points on your paper. You start from the top of the circle
(let's say at 12 o'clock) and move around the circle.
4. Make Decisions: As you move around, you have to make decisions. These decisions are like
guessing which point comes next based on where you are and how far you are from the center.
5. Keep Going: You keep making decisions and plotting points until you reach the starting point
again. This way, you draw the entire circle!
6. Use Symmetry: You don't have to draw every single point. You can be smart and use the fact
that a circle is symmetrical. So, you draw only a part of it, and then just copy that part to fill the
rest.

So, even if you don't have a fancy compass, you can still draw a perfect circle using the midpoint
circle drawing algorithm!

https://mu.ac.in/wp-content/uploads/2022/03/USIT-405-Computer-Graphics-and-
Animation.pdf

draw a circle as radius 4 cm ,using bresenham's circle drawing


algorithm -

def draw_circle(radius):

x=0
y = radius

d = 3 - 2 * radius

draw_points(x, y)

while y >= x:

# Increment x

x += 1

# Mid-point is outside the circle

if d > 0:

y -= 1

d = d + 4 * (x - y) + 10

else:

d=d+4*x+6

draw_points(x, y)

def draw_points(x, y):

# Here, you can use any graphics library or print to console

# For simplicity, let's just print the points

print("(", x, ",", y, ")")


print("(", -x, ",", y, ")")

print("(", x, ",", -y, ")")

print("(", -x, ",", -y, ")")

print("(", y, ",", x, ")")

print("(", -y, ",", x, ")")

print("(", y, ",", -x, ")")

print("(", -y, ",", -x, ")")

# Example usage:

radius = 4

You might also like