You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.9 KiB
56 lines
1.9 KiB
#!/usr/bin/env python3 |
|
"""Precalculate expected values for test_extreme_orientation_mixed.""" |
|
|
|
import sys |
|
import os |
|
import math |
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) |
|
import sim_engine |
|
from sim_engine import Simulator |
|
|
|
# Load config via sim_engine (TOML 1.0 parsing + spacecraft initialization) |
|
sim = Simulator("tests/test_extreme_orientation_mixed.toml", dt=60.0) |
|
|
|
mu = 6.67430e-11 * 5.972e24 # Earth's gravitational parameter |
|
|
|
print(f"# mu = {mu:.6f} m^3/s^2") |
|
print() |
|
|
|
for i, craft in enumerate(sim.spacecraft): |
|
a = craft.orbit.a |
|
e = craft.orbit.e |
|
name = craft.name |
|
|
|
print(f"# Spacecraft {i}: {name} (a={a}, e={e})") |
|
|
|
# Periapsis (nu=0) |
|
r_peri = a * (1.0 - e) |
|
v_peri = math.sqrt(mu * (2.0/r_peri - 1.0/a)) |
|
print(f"# nu=0: r={r_peri:.6e} m, v={v_peri:.6f} m/s") |
|
|
|
# Apoapsis (nu=pi) |
|
if e < 1.0: |
|
r_apo = a * (1.0 + e) |
|
v_apo = math.sqrt(mu * (2.0/r_apo - 1.0/a)) |
|
print(f"# nu=pi: r={r_apo:.6e} m, v={v_apo:.6f} m/s") |
|
|
|
# nu=pi/2 |
|
r_nu90 = a * (1.0 - e*e) / (1.0 + e * math.cos(math.pi/2)) |
|
v_nu90 = math.sqrt(mu * (2.0/r_nu90 - 1.0/a)) |
|
print(f"# nu=pi/2: r={r_nu90:.6e} m, v={v_nu90:.6f} m/s") |
|
|
|
# nu=3pi/2 |
|
r_nu270 = a * (1.0 - e*e) / (1.0 + e * math.cos(3*math.pi/2)) |
|
v_nu270 = math.sqrt(mu * (2.0/r_nu270 - 1.0/a)) |
|
print(f"# nu=3pi/2: r={r_nu270:.6e} m, v={v_nu270:.6f} m/s") |
|
|
|
# Round-trip check: convert to cartesian and back |
|
parent_mass = mu / 6.67430e-11 |
|
pos, vel = sim_engine.orbital_to_cartesian(craft.orbit, parent_mass) |
|
recovered = sim_engine.cartesian_to_orbital_elements(pos, vel, parent_mass) |
|
print(f"# round-trip: e_err={abs(recovered.e - e):.2e}, " |
|
f"i_err={abs(recovered.inc - craft.orbit.inc):.2e}, " |
|
f"O_err={abs(recovered.Omega - craft.orbit.Omega):.2e}, " |
|
f"w_err={abs(recovered.omega - craft.orbit.omega):.2e}") |
|
print()
|
|
|