Repository navigation
Expand file tree
/
Copy pathvisualization.py
More file actions
61 lines (48 loc) · 1.39 KB
/
Copy pathvisualization.py
File metadata and controls
61 lines (48 loc) · 1.39 KB
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
58
59
60
61
import matplotlib.pyplot as plt
def draw_rocket(length, cg, cp, margin, status):
plt.figure(figsize=(10, 2))
plt.text(
length/2,
0.22,
f"Static Margin = {margin:.2f} calibers",
ha="center",
fontsize=10
)
plt.text(
length/2,
-0.18,
f"Status : {status}",
color="green",
fontsize=14,
ha="center",
fontweight="bold"
)
# Rocket body
plt.plot([0, length], [0, 0],
linewidth=8,
color="dimgray")
# Nose
plt.plot([length, length + 0.08], [0, 0.05], linewidth=3)
plt.plot([length, length + 0.08], [0, -0.05], linewidth=3)
plt.text(length + 0.04, 0.07, "Nose", ha="center", fontsize=10)
# Tail fins
plt.plot([0, -0.06], [0, 0.05], linewidth=3)
plt.plot([0, -0.06], [0, -0.05], linewidth=3)
plt.text(-0.08, 0.07, "Tail Fins", ha="center", fontsize=10)
# Center of Gravity
plt.scatter(cg, 0, s=180, color="blue", zorder=5,label="Center of Gravity (CG)")
# Center of Pressure
plt.scatter(cp, 0, s=180, color="red", zorder=5,label="Center of Pressure (CP)")
plt.title(
"Rocket Stability Visualization",
fontsize=20,
fontweight="bold",
pad=20
)
plt.xlim(-0.3,length+0.3)
plt.ylim(-0.15,0.25)
plt.axis("off")
plt.grid(False)
plt.savefig("screenshots/rocket_visualization.png", dpi=300)
plt.legend(loc="upper right")
plt.show()