Bresenhams Line Algorithm
unknown
python
2 years ago
841 B
29
Indexable
import matplotlib.pyplot as plt def draw_midpoint_circle(h, k, r): x = r y = 0 P = 1 - r points = [] while x > y: points.extend([(x + h, y + k), (y + h, x + k), (-x + h, y + k), (-y + h, x + k), (-x + h, -y + k), (-y + h, -x + k), (x + h, -y + k), (y + h, -x + k)]) if P <= 0: y += 1 P = P + 2 * y + 1 else: x -= 1 y += 1 P = P + 2 * (y - x) + 1 return points # Example usage: midpoint_circle_points = draw_midpoint_circle(5, 5, 4) # Plotting x_vals, y_vals = zip(*midpoint_circle_points) plt.plot(x_vals, y_vals, marker='o', linestyle='', markersize=3) plt.title('Midpoint Circle Drawing Algorithm') plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.grid(True) plt.show()
Editor is loading...
Leave a Comment