Skip to content

Commit 478d8de

Browse files
Add files via upload
1 parent 29a31d5 commit 478d8de

3 files changed

Lines changed: 217 additions & 0 deletions

File tree

calculation of v1 and v2.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import math
2+
import matplotlib.pyplot as plt
3+
import numpy as np
4+
5+
# ========== Constants ==========
6+
mu_earth = 3.986e14 # gravitational constant × Earth’s mass
7+
r_earth = 6371e3 # Earth radius (m)
8+
9+
# ========== Example orbits ==========
10+
r1 = r_earth + 200e3 # Low Earth Orbit (200 km)
11+
r2 = r_earth + 35786e3 # Geostationary Orbit (35,786 km)
12+
13+
def hohmann_delta_v(r1, r2, mu=mu_earth):
14+
# ========== Hohmann transfer Δv (two burns) ==========
15+
v1 = math.sqrt(mu / r1)
16+
v2 = math.sqrt(mu / r2)
17+
a_transfer = (r1 + r2) / 2
18+
19+
v_perigee = math.sqrt(mu * (2/r1 - 1/a_transfer))
20+
v_apogee = math.sqrt(mu * (2/r2 - 1/a_transfer))
21+
22+
delta_v1 = abs(v_perigee - v1)
23+
delta_v2 = abs(v2 - v_apogee)
24+
return delta_v1, delta_v2, delta_v1 + delta_v2
25+
26+
dv1, dv2, total = hohmann_delta_v(r1, r2)
27+
print(f"Δv1 = {dv1/1000:.2f} km/s")
28+
print(f"Δv2 = {dv2/1000:.2f} km/s")
29+
print(f"Gesamtes Δv = {total/1000:.2f} km/s")
30+
31+
def rocket_equation(delta_v, Isp=320, m0=1000):
32+
g0 = 9.80665
33+
mf = m0 * math.exp(-delta_v / (Isp * g0))
34+
fuel_used = m0 - mf
35+
return fuel_used, (fuel_used / m0) * 100
36+
37+
fuel, percent = rocket_equation(total)
38+
print(f"Verbrauchtes Treibstoff: {fuel:.2f} kg ({percent:.1f}% von Gesamtmasse)")
39+
40+
41+
isp_values = np.linspace(200, 450, 100)
42+
43+
44+
fuel_list = []
45+
for i in isp_values:
46+
f, _ = rocket_equation(total, Isp=i)
47+
fuel_list.append(f)
48+
49+
50+
plt.figure(figsize=(8, 4))
51+
plt.plot(isp_values, fuel_list, color='blue', linewidth=2)
52+
plt.title(f'Treibstoff für LEO -> GEO Transfer ({int(total)} m/s)')
53+
plt.xlabel('Spezifischer Impuls (s)')
54+
plt.ylabel('Treibstoffmasse (kg)')
55+
plt.grid(True, linestyle='--', alpha=0.6)
56+
57+
58+
plt.scatter([320], [fuel], color='red', zorder=5)
59+
plt.text(330, fuel, f'Mein Satellit\n(Isp=320s, Treibstoff={int(fuel)}kg)', color='red')
60+
61+
plt.show()

sim_v2.py

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Der Code ist in Englisch, da ich eher Englisch spreche.
2+
3+
import numpy as np
4+
import matplotlib.pyplot as plt
5+
from matplotlib.animation import FuncAnimation
6+
7+
# ================== CONSTANTS ==================
8+
mu = 3.986e14
9+
r_earth = 6.371e6
10+
g0 = 9.80665
11+
12+
Isp = 320
13+
m0 = 1000
14+
15+
r1 = 7e6
16+
r2 = 4.2e7
17+
18+
# ================== HOHMANN TRANSFER ==================
19+
a_t = (r1 + r2) / 2
20+
e_t = (r2 - r1) / (r1 + r2)
21+
22+
T1 = 2*np.pi*np.sqrt(r1**3 / mu)
23+
Tt = np.pi*np.sqrt(a_t**3 / mu)
24+
T2 = 2*np.pi*np.sqrt(r2**3 / mu)
25+
26+
N1, Nt, N2 = 200, 300, 200
27+
28+
# ================== ORBIT 1 ==================
29+
t1 = np.linspace(0, T1, N1)
30+
theta1 = 2*np.pi*t1/T1
31+
x1 = r1*np.cos(theta1)
32+
y1 = r1*np.sin(theta1)
33+
34+
# ================== TRANSFER ORBIT ==================
35+
def kepler(M, e):
36+
E = M.copy()
37+
for _ in range(10):
38+
E -= (E - e*np.sin(E) - M) / (1 - e*np.cos(E))
39+
return E
40+
41+
t_t = np.linspace(0, Tt, Nt)
42+
M = np.sqrt(mu/a_t**3) * t_t
43+
E = kepler(M, e_t)
44+
45+
theta_t = 2*np.arctan2(
46+
np.sqrt(1+e_t)*np.sin(E/2),
47+
np.sqrt(1-e_t)*np.cos(E/2)
48+
)
49+
50+
r_t = a_t * (1 - e_t*np.cos(E))
51+
x_t = r_t*np.cos(theta_t)
52+
y_t = r_t*np.sin(theta_t)
53+
54+
# ================== ORBIT 2 ==================
55+
T2 = 2*T2
56+
t2 = np.linspace(0, T2, N2)
57+
theta2 = theta_t[-1] + 2*np.pi*t2/T2
58+
x2 = r2*np.cos(theta2)
59+
y2 = r2*np.sin(theta2)
60+
61+
# ================== COMBINE ==================
62+
x = np.concatenate([x1, x_t, x2])
63+
y = np.concatenate([y1, y_t, y2])
64+
r = np.sqrt(x**2 + y**2)
65+
66+
# ================== SPEED & ENERGY ==================
67+
v = np.zeros_like(r)
68+
69+
v[:N1] = np.sqrt(mu / r1)
70+
v[N1:N1+Nt] = np.sqrt(mu * (2/r[N1:N1+Nt] - 1/a_t))
71+
v[N1+Nt:] = np.sqrt(mu / r2)
72+
73+
energy = 0.5*v**2 - mu/r
74+
75+
# ================== FIGURE ==================
76+
fig = plt.figure(figsize=(11, 6))
77+
gs = fig.add_gridspec(2, 2)
78+
79+
ax_orbit = fig.add_subplot(gs[:, 0])
80+
ax_speed = fig.add_subplot(gs[0, 1])
81+
ax_energy = fig.add_subplot(gs[1, 1])
82+
83+
# ================== ORBIT VIEW ==================
84+
ax_orbit.set_aspect('equal')
85+
lim = r2 * 1.15
86+
ax_orbit.set_xlim(-lim, lim)
87+
ax_orbit.set_ylim(-lim, lim)
88+
ax_orbit.set_title("Hohmann-Transfer")
89+
90+
ax_orbit.add_patch(plt.Circle((0,0), r_earth, color='skyblue', zorder=0))
91+
ax_orbit.plot(x1, y1, '--', color='gray')
92+
ax_orbit.plot(x_t, y_t, '--', color='orange')
93+
ax_orbit.plot(x2, y2, '--', color='gray')
94+
95+
sat, = ax_orbit.plot([], [], 'ro', markersize=6)
96+
97+
# ================== SPEED GRAPH ==================
98+
ax_speed.set_title("Geschwindigkeit vs Zeit")
99+
ax_speed.set_ylabel("m/s")
100+
ax_speed.set_xlim(0, len(x))
101+
ax_speed.set_ylim(v.min()*0.95, v.max()*1.05)
102+
line_v, = ax_speed.plot([], [], 'r')
103+
104+
# ================== ENERGY GRAPH ==================
105+
ax_energy.set_title("Spezifische Energie")
106+
ax_energy.set_xlabel("Zeitschritt")
107+
ax_energy.set_ylabel("J/kg")
108+
ax_energy.set_xlim(0, len(x))
109+
ax_energy.set_ylim(energy.min()*1.05, energy.max()*0.95)
110+
line_e, = ax_energy.plot([], [], 'b')
111+
112+
# ================== ANIMATION ==================
113+
def update(i):
114+
sat.set_data([x[i]], [y[i]])
115+
line_v.set_data(np.arange(i), v[:i])
116+
line_e.set_data(np.arange(i), energy[:i])
117+
return sat, line_v, line_e
118+
119+
anim = FuncAnimation(
120+
fig,
121+
update,
122+
frames=len(x),
123+
interval=20,
124+
blit=False
125+
)
126+
127+
plt.tight_layout()
128+
plt.show()

visualisation.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
4+
# ========== Constants ==========
5+
mu = 3.986e14 # gravitational constant × Earth’s mass
6+
R_earth = 6371e3 # Earth's radius (m)
7+
8+
# ========== Orbit altitudes (from 200 km to 36,000 km) ==========
9+
h = np.linspace(200e3, 36000e3, 200)
10+
r = R_earth + h
11+
12+
# ========== Orbital velocity at that altitude ==========
13+
v_orbit = np.sqrt(mu / r)
14+
15+
# ========== Approximate Δv to reach that orbit from Earth ==========
16+
v_surface = np.sqrt(mu / R_earth)
17+
print(v_surface)
18+
delta_v = v_orbit - v_surface # not realistic, but only for comparison
19+
delta_v = np.abs(delta_v)
20+
21+
# ========== Plot ==========
22+
plt.figure(figsize=(8, 5))
23+
plt.plot(h/1000, delta_v/1000, color='royalblue', linewidth=2)
24+
plt.title("Δv vs Orbit Altitude", fontsize=14)
25+
plt.xlabel("Orbit altitude (km)")
26+
plt.ylabel("Δv (km/s)")
27+
plt.grid(True)
28+
plt.show()

0 commit comments

Comments
 (0)