Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__/
*.pyc
*.pyo
62 changes: 34 additions & 28 deletions jugend-forscht-2026/visualisation.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
import numpy as np
import matplotlib.pyplot as plt

# ========== Constants ==========
mu = 3.986e14 # gravitational constant × Earth’s mass
R_earth = 6371e3 # Earth's radius (m)

# ========== Orbit altitudes (from 200 km to 36,000 km) ==========
h = np.linspace(200e3, 36000e3, 200)
r = R_earth + h

# ========== Orbital velocity at that altitude ==========
v_orbit = np.sqrt(mu / r)

# ========== Approximate Δv to reach that orbit from Earth ==========
v_surface = np.sqrt(mu / R_earth)
print(v_surface)
delta_v = v_orbit - v_surface # not realistic, but only for comparison
delta_v = np.abs(delta_v)

# ========== Plot ==========
plt.figure(figsize=(8, 5))
plt.plot(h/1000, delta_v/1000, color='royalblue', linewidth=2)
plt.title("Δv vs Orbit Altitude", fontsize=14)
plt.xlabel("Orbit altitude (km)")
plt.ylabel("Δv (km/s)")
plt.grid(True)
plt.show()
import numpy as np
import matplotlib.pyplot as plt

# ========== Constants ==========
mu = 3.986e14 # gravitational constant × Earth's mass
R_earth = 6371e3 # Earth's radius (m)

# ========== Orbit altitudes (from 200 km to 36,000 km) ==========
h = np.linspace(200e3, 36000e3, 200)
r2 = R_earth + h
r1 = R_earth + 200e3 # reference LEO at 200 km

# ========== Hohmann transfer Δv from LEO (200 km) to each target orbit ==========
a_transfer = (r1 + r2) / 2
v_circ1 = np.sqrt(mu / r1)
v_circ2 = np.sqrt(mu / r2)
v_perigee = np.sqrt(mu * (2 / r1 - 1 / a_transfer))
v_apogee = np.sqrt(mu * (2 / r2 - 1 / a_transfer))

delta_v1 = np.abs(v_perigee - v_circ1)
delta_v2 = np.abs(v_circ2 - v_apogee)
delta_v_total = delta_v1 + delta_v2

# ========== Plot ==========
plt.figure(figsize=(8, 5))
plt.plot(h / 1000, delta_v_total / 1000, color='royalblue', linewidth=2, label='Total Δv (Hohmann)')
plt.plot(h / 1000, delta_v1 / 1000, color='green', linewidth=1.5, linestyle='--', label='Δv₁ (departure burn)')
plt.plot(h / 1000, delta_v2 / 1000, color='orange', linewidth=1.5, linestyle='--', label='Δv₂ (insertion burn)')
plt.title("Hohmann Transfer Δv from LEO (200 km) vs Target Orbit Altitude", fontsize=13)
plt.xlabel("Target orbit altitude (km)")
plt.ylabel("Δv (km/s)")
plt.legend()
plt.grid(True)
plt.show()
4 changes: 2 additions & 2 deletions multi-body-orbital-mechanics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ A beautiful Python simulation of planets orbiting a star, powered by **Newton’
```bash
pip install matplotlib numpy
```
2. Install dependencies:
2. Run the simulation:
```bash
pip install matplotlib numpy
python main.py
```
# 💡 Made for space lovers & future astrophysicists.
33 changes: 30 additions & 3 deletions multi-body-orbital-mechanics/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
dt = 60 * 60 * 24 # 1 day per frame
frame_count = 0
sun_gravity_on = True # Sun gravity toggle
paused = False # Pause toggle
elapsed_days = 0 # Simulation time tracker

# --- Planet data ---
planets = [
Expand All @@ -20,7 +22,9 @@
{"name": "Mars", "pos": [1.52 * 1.496e11, 0], "vel": [0, 24077],
"mass": 6.417e23, "mass_on": True, "x_path": [], "y_path": [], "color": "red"},
{"name": "Jupiter", "pos": [5.2 * 1.496e11, 0], "vel": [0, 13070],
"mass": 1.898e27, "mass_on": True, "x_path": [], "y_path": [], "color": "brown"}
"mass": 1.898e27, "mass_on": True, "x_path": [], "y_path": [], "color": "brown"},
{"name": "Saturn", "pos": [9.537 * 1.496e11, 0], "vel": [0, 9690],
"mass": 5.683e26, "mass_on": True, "x_path": [], "y_path": [], "color": "goldenrod"}
]

# --- Store initial positions/velocities for reset ---
Expand Down Expand Up @@ -68,8 +72,11 @@ def update_positions():

# --- Animation ---
def animate(frame):
global frame_count
global frame_count, elapsed_days
if paused:
return
frame_count += 1
elapsed_days += dt / (60 * 60 * 24)
ax.clear()
ax.set_facecolor("black")
ax.set_aspect('equal', adjustable='box')
Expand Down Expand Up @@ -97,14 +104,24 @@ def animate(frame):
# Planet glow halo
planet_alpha = 0.1 + 0.05 * (math.sin(frame_count * 0.1) + 1) / 2
ax.scatter(p["pos"][0], p["pos"][1], color=p["color"], s=150, alpha=planet_alpha, zorder=2)
# Planet name label
ax.text(p["pos"][0], p["pos"][1], f" {p['name']}", color=p["color"],
fontsize=6, va='center', zorder=5)

# Elapsed time display
years = elapsed_days / 365.25
ax.text(0.02, 0.97, f"Time: {years:.2f} years", transform=ax.transAxes,
color='white', fontsize=9, va='top')

# --- Button callbacks ---
def reset(event):
global elapsed_days
for i, p in enumerate(planets):
p["pos"] = initial_states[i]["pos"][:]
p["vel"] = initial_states[i]["vel"][:]
p["x_path"].clear()
p["y_path"].clear()
elapsed_days = 0

def toggle_mass(planet_index):
def inner(event):
Expand All @@ -119,19 +136,29 @@ def toggle_sun_gravity(event):
status = "ON" if sun_gravity_on else "OFF"
print(f"Sun gravity toggled {status}")

def toggle_pause(event):
global paused
paused = not paused
status = "PAUSED" if paused else "RUNNING"
print(f"Simulation {status}")

# --- Add buttons ---
ax_reset = plt.axes([0.81, 0.05, 0.1, 0.05])
btn_reset = Button(ax_reset, 'Reset')
btn_reset.on_clicked(reset)

ax_pause = plt.axes([0.81, 0.12, 0.1, 0.05])
btn_pause = Button(ax_pause, 'Pause/Play')
btn_pause.on_clicked(toggle_pause)

# Buttons for each planet
for i, p in enumerate(planets):
ax_btn = plt.axes([0.01, 0.05 + i*0.06, 0.1, 0.05])
btn = Button(ax_btn, p["name"])
btn.on_clicked(toggle_mass(i))

# Sun gravity toggle button
ax_sun = plt.axes([0.81, 0.12, 0.1, 0.05])
ax_sun = plt.axes([0.81, 0.19, 0.1, 0.05])
btn_sun = Button(ax_sun, "Sun Gravity")
btn_sun.on_clicked(toggle_sun_gravity)

Expand Down