-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathellipse_algos.py
57 lines (45 loc) · 1.31 KB
/
ellipse_algos.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import matplotlib.pyplot as plt
import copy
import sys
def get_plot():
graph, plot = plt.subplots()
plot.grid()
return plot
def EllipseMidPointAlgorithm(center_point: list[int], radius_point: list[int], grid_map: list[list[int]]) -> None:
plot = get_plot()
plt.xlim(-len(grid_map), len(grid_map))
plt.ylim(-len(grid_map[0]), len(grid_map[0]))
x0 = 0
y0 = radius_point[1]
p_k = radius_point[1]**2 - radius_point[0]**2 * radius_point[1] + 0.25*radius_point[0]**2
x_plot = 0
y_plot = 0
quad = [(x0, y0)]
# 1st Quad
print("1st Quadrant")
print((x0, y0))
grid_map_quad1 = copy.deepcopy(grid_map)
grid_map_quad1[y0][x0] = 1
while 2*radius_point[1]**2 * x0 < 2*radius_point[0]**2 * y0:
print(2*radius_point[1]**2 * x0, 2*radius_point[0]**2 * y0)
if p_k < 0:
x0 += 1
p_k = p_k + 2*radius_point[1]**2 * x0 + radius_point[1]**2
else:
x0 += 1
y0 -= 1
p_k = p_k + 2*radius_point[1]**2 * x0 - 2*radius_point[0]**2 * y0 + radius_point[1]**2
x_plot = x0 + center_point[0]
y_plot = y0 + center_point[1]
quad.append((x0, y0))
print((x_plot, y_plot))
grid_map_quad1[y_plot][x_plot] = 1
quad += [(item[1], item[0]) for item in quad[::-1]]
plot.imshow(grid_map_quad1)
plt.show()
# !!!!!
sys.exit()
algos = {
1: EllipseMidPointAlgorithm
}
algos_names = ["Ellipse > EllipseMidPointAlgorithm"]