import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
# --- Physikalische Parameter (Reale Werte) ---
MU = 398600.0
R_ERDE_REAL = 6371.0
H_ISS_REAL = 400.0
H_VERS_START_REAL = 350.0
R_ISS_REAL = R_ERDE_REAL + H_ISS_REAL
R_VERS_REAL = R_ERDE_REAL + H_VERS_START_REAL
A_TRANS_REAL = (R_ISS_REAL + R_VERS_REAL) / 2.0
v_iss_const = np.sqrt(MU / R_ISS_REAL)
# --- Didaktische Parameter für die Grafik ---
R_ERDE_GRAPH = 1.0
R_VERS_GRAPH = 2.1
R_ISS_GRAPH = 3.3
LIMIT = 4.5
# --- Zeit-Parameter ---
FPS = 30
DAUER_SEKUNDEN = 60
ANZAHL_FRAMES = FPS * DAUER_SEKUNDEN
t = np.linspace(0, 1, ANZAHL_FRAMES)
# --- Bahndaten ---
EXZ_GRAPH = (R_ISS_GRAPH - R_VERS_GRAPH) / (R_ISS_GRAPH + R_VERS_GRAPH)
A_TRANS_GRAPH = (R_ISS_GRAPH + R_VERS_GRAPH) / 2.0
phi_start = 1.25 * np.pi
nu = np.pi * t
r_transfer = A_TRANS_GRAPH * (1 - EXZ_GRAPH ** 2) / (1 + EXZ_GRAPH * np.cos(nu))
# Reale v-Werte berechnen
r_real_t = A_TRANS_REAL * (1 - ((R_ISS_REAL - R_VERS_REAL) / (R_ISS_REAL + R_VERS_REAL)) ** 2) / (
1 + ((R_ISS_REAL - R_VERS_REAL) / (R_ISS_REAL + R_VERS_REAL)) * np.cos(nu))
v_vers_t = np.sqrt(MU * (2 / r_real_t - 1 / A_TRANS_REAL))
x_vers = r_transfer * np.cos(nu + phi_start)
y_vers = r_transfer * np.sin(nu + phi_start)
phi_iss = (phi_start + np.pi) - (0.8 * np.pi * (1 - t))
x_iss = R_ISS_GRAPH * np.cos(phi_iss)
y_iss = R_ISS_GRAPH * np.sin(phi_iss)
# --- Grafik-Setup ---
fig, ax = plt.subplots(figsize=(10, 10))
ax.set_facecolor('#000000')
# Erde
ax.add_artist(plt.Circle((0, 0), R_ERDE_GRAPH, color='#1a4e8a'))
# Orbits
phi_full = np.linspace(0, 2 * np.pi, 500)
ax.plot(R_VERS_GRAPH * np.cos(phi_full), R_VERS_GRAPH * np.sin(phi_full), color='#444444', linestyle=':', alpha=0.4)
ax.plot(R_ISS_GRAPH * np.cos(phi_full), R_ISS_GRAPH * np.sin(phi_full), color='#888888', linestyle='--', alpha=0.3)
# Flugobjekte - Versorger jetzt in DodgerBlue
iss_dot, = ax.plot([], [], 'ro', markersize=11, markeredgecolor='white', label='ISS')
vers_dot, = ax.plot([], [], color='dodgerblue', marker='o', markersize=9, markeredgecolor='white', label='Versorger')
spur, = ax.plot([], [], color='dodgerblue', lw=2, alpha=0.6)
# Telemetrie mit optimierten Farben
v_text_iss = ax.text(0, 0, '', color='red', fontsize=11, fontweight='bold')
v_text_vers = ax.text(0, 0, '', color='dodgerblue', fontsize=11, fontweight='bold')
ax.set_xlim(-LIMIT, LIMIT)
ax.set_ylim(-LIMIT, LIMIT)
ax.set_aspect('equal')
ax.axis('off')
plt.title("Hohmann-Transfer mit Telemetrie (v in km/s)", color='white', fontsize=16, pad=20)
ax.legend(loc='lower center', frameon=True, facecolor='#111', labelcolor='white', ncol=2)
def update(frame):
iss_point_x, iss_point_y = x_iss[frame], y_iss[frame]
vers_point_x, vers_point_y = x_vers[frame], y_vers[frame]
iss_dot.set_data([iss_point_x], [iss_point_y])
vers_dot.set_data([vers_point_x], [vers_point_y])
spur.set_data(x_vers[:frame], y_vers[:frame])
# Texte leicht versetzt positionieren
v_text_iss.set_position((iss_point_x + 0.2, iss_point_y + 0.2))
v_text_iss.set_text(f"v: {v_iss_const:.4f}")
v_text_vers.set_position((vers_point_x + 0.2, vers_point_y - 0.4))
v_text_vers.set_text(f"v: {v_vers_t[frame]:.4f}")
return iss_dot, vers_dot, spur, v_text_iss, v_text_vers
ani = FuncAnimation(fig, update, frames=ANZAHL_FRAMES, interval=33, blit=True)
plt.show()