orbit_kepler
Two-body (Kepler) orbits about any central body given by its GM (Earth by default): state vector to classical elements and back, period, specific energy and angular momentum, speeds at periapsis and apoapsis (vis-viva), escape and circular speed, hyperbolic excess speed and turn angle, and propagation in time by Kepler's equation (ellipse, hyperbola; Barker's equation on a parabola). Writes the orbit track as out/orbit.csv. Units: km, s, deg.
- Field
- Space and orbits
- Version
- 0.1.0
- Runs as
- Compiled (Rust)
- Typical run
- 0.02 s
Compiled from source: run sh packs/install.sh once before admitting it.
Known answers it must pass
r0001circular orbit 400 km above R=6378.137 km, GM=398600.4418: closed forms v=sqrt(GM/r)=7.66856 km/s, T=2pi sqrt(r^3/GM), v_esc=sqrt(2) v, energy=-GM/2r, h=sqrt(GM r) (rel 1e-9)passed
v_mag_km_s7.66856 ± 7.7e-097.66856lockedunder 0.01 % of the tolerance usedv_circular_km_s7.66856 ± 7.7e-097.66856lockedunder 0.01 % of the tolerance usedperiod_s5553.62 ± 5.6e-065553.62lockedunder 0.01 % of the tolerance usedv_escape_km_s10.845 ± 1.1e-0810.845lockedunder 0.01 % of the tolerance usedspecific_energy_km2_s2-29.4034 ± 2.9e-08-29.4034lockedunder 0.01 % of the tolerance usedh_km2_s51978.5 ± 5.2e-0551978.5lockedunder 0.01 % of the tolerance usedr_mag_km6778.14 ± 6.8e-096778.14lockedunder 0.01 % of the tolerance usedr0002sidereal-day period 86164.09 s, e=0: Kepler's third law a=(GM T^2/4pi^2)^(1/3)=42164.17 km (geostationary radius), v=sqrt(GM/a) (rel 1e-9)passed
a_km42164.2 ± 4.2e-0542164.2lockedunder 0.01 % of the tolerance usedr_mag_km42164.2 ± 4.2e-0542164.2lockedunder 0.01 % of the tolerance usedv_mag_km_s3.07466 ± 3.1e-093.07466lockedunder 0.01 % of the tolerance usedr0003frame conventions by inspection: r=[0,7000,0], v=[0,0,7] (below circular, so apoapsis) gives i=90, raan=90, argp=180, nu=180, e=1-R v^2/GM, a=R/(1+e); round trip state->elements->state exact (closed form, rel 1e-9)passed
i_deg90 ± 1e-0990lockedunder 0.01 % of the tolerance usedraan_deg90 ± 1e-0990lockedunder 0.01 % of the tolerance usedargp_deg180 ± 1e-09180lockedunder 0.01 % of the tolerance usedtrue_anomaly_deg180 ± 1e-09180lockedunder 0.01 % of the tolerance usede0.139489 ± 1.4e-100.139489lockedunder 0.01 % of the tolerance useda_km6143.1 ± 6.1e-066143.1lockedunder 0.01 % of the tolerance usedperiapsis_radius_km5286.21 ± 5.3e-065286.21lockedunder 0.01 % of the tolerance usedapoapsis_radius_km7000 ± 7e-067000lockedunder 0.01 % of the tolerance usedroundtrip_rel_error≤ 1e-122.71769e-16lockedinside the ranger0004Kepler's equation, ellipse a=10000 km e=0.5 from periapsis, dt=(pi/2-e) sqrt(a^3/GM)=1696.0474 s: exact solution E=90 deg, so r=a and nu=acos(-e)=120 deg (rel 1e-9)passed
r_end_mag_km10000 ± 1e-0510000lockedunder 0.01 % of the tolerance usedtrue_anomaly_end_deg120 ± 1.2e-07120lockedunder 0.01 % of the tolerance usedmean_anomaly_end_deg61.3521 ± 6.1e-0861.3521lockedunder 0.01 % of the tolerance usedenergy_rel_change≤ 1e-121.96085e-15lockedinside the rangeh_rel_change≤ 1e-121.4878e-16lockedinside the ranger0005Barker's equation, parabola e=1 periapsis 500 km: from periapsis dt=(2/3) sqrt(p^3/GM) (p=2 r_p) reaches nu=90 deg at r=p; v_p=sqrt(2GM/r_p) escape speed (closed form, rel 1e-9)passed
orbit_type= parabolicparaboliclockedexact matchtrue_anomaly_end_deg90 ± 9e-0890lockedunder 0.01 % of the tolerance usedr_end_mag_km13756.3 ± 1.4e-0513756.3lockedunder 0.01 % of the tolerance usedv_periapsis_km_s10.7659 ± 1.1e-0810.7659lockedunder 0.01 % of the tolerance usedspecific_energy_km2_s20 ± 1e-09-7.10543e-15lockedunder 0.01 % of the tolerance usedr0006hyperbolic Kepler equation, e=2 periapsis 500 km: turn angle 2 asin(1/e)=60 deg, v_inf=sqrt(GM(e-1)/r_p); from periapsis dt=(2 sqrt3 - ln(2+sqrt3))/n reaches H=ln(2+sqrt3), nu=90 deg, r=p=3 r_p (exact solution, rel 1e-9)passed
turn_angle_deg60 ± 6e-0860lockedunder 0.01 % of the tolerance usedv_infinity_km_s7.61261 ± 7.6e-097.61261lockedunder 0.01 % of the tolerance useda_km-6878.14 ± 6.9e-06-6878.14lockedunder 0.01 % of the tolerance usedtrue_anomaly_end_deg90 ± 9e-0890lockedunder 0.01 % of the tolerance usedr_end_mag_km20634.4 ± 2.1e-0520634.4lockedunder 0.01 % of the tolerance usedr0007Curtis, Orbital Mechanics for Engineering Students, Example 4.3: r=[-6045,-3490,2500] km, v=[-3.457,6.618,2.533] km/s gives h=58310, i=153.2, raan=255.3, e=0.1712, argp=20.07, nu=28.45, a=8788 (textbook prints 4 figures: tolerance half the last digit); one period of propagation returns the start (exact, 1e-9 relative)passed
h_km2_s58310 ± 558311.7locked33 % of the tolerance usedi_deg153.2 ± 0.05153.249locked98 % of the tolerance usedraan_deg255.3 ± 0.05255.279locked41 % of the tolerance usede0.1712 ± 5e-050.171211locked22 % of the tolerance usedargp_deg20.07 ± 0.00520.0681locked37 % of the tolerance usedtrue_anomaly_deg28.45 ± 0.00528.4458locked84 % of the tolerance useda_km8788 ± 0.58788.08locked16 % of the tolerance usedposition_change_km≤ 1e-055.92918e-12lockedinside the rangevelocity_change_km_s≤ 1e-085.65233e-15lockedinside the rangeenergy_rel_change≤ 1e-126.26623e-16lockedinside the rangeh_rel_change≤ 1e-121.28617e-16lockedinside the range
Each line is one reading the kernel checked. The bright band is the tolerance; the needle is the value the instrument actually returned when it was admitted. A needle near the centre line used little of its tolerance.
Inputs
| Name | Unit | Default | Meaning |
|---|---|---|---|
gm_km3_s2 | km^3/s^2 | 398600.4418 | Gravitational parameter GM of the central body. Default: the Earth (WGS 84 / EGM96 value 398600.4418). |
body_radius_km | km | 6378.137 | Radius of the central body; altitudes are measured above it. Default: the Earth's equatorial radius (WGS 84). 0 measures from the centre. |
r_km | km | State mode: position [x, y, z] in an inertial frame centred on the body. Give with v_km_s and no elements. | |
v_km_s | km/s | State mode: velocity [vx, vy, vz]. Give with r_km. | |
a_km | km | Elements mode, size: semi-major axis (positive on an ellipse, negative on a hyperbola). Give exactly one of a_km, period_s, h_km2_s, periapsis_altitude_km. | |
period_s | s | Elements mode, size: orbital period (closed orbits only). | |
h_km2_s | km^2/s | Elements mode, size: specific angular momentum. | |
periapsis_altitude_km | km | Elements mode, size: periapsis altitude above body_radius_km; with apoapsis_altitude_km (then leave e out) or with e. | |
apoapsis_altitude_km | km | Elements mode: apoapsis altitude; needs periapsis_altitude_km. | |
e | 1 | Eccentricity: 0 circle, below 1 ellipse, 1 parabola, above 1 hyperbola. 0 when left out. | |
i_deg | deg | Inclination. 0 when left out. | |
raan_deg | deg | Right ascension of the ascending node. 0 when left out. | |
argp_deg | deg | Argument of periapsis. 0 when left out. | |
true_anomaly_deg | deg | True anomaly at the epoch. 0 (periapsis) when left out. | |
dt_s | s | 0 | Propagate this long from the epoch by Kepler's equation (negative goes back). |
propagate_periods | 1 | 0 | Also propagate this many orbital periods (closed orbits only); added to dt_s. |
samples | 1 | 361 | Rows in out/orbit.csv: one period evenly in time (closed orbit), or a sweep of true anomaly about periapsis (open orbit). |
Readings
| Name | Unit | Meaning |
|---|---|---|
mode | 1 | "state" or "elements": which inputs defined the orbit |
orbit_type | 1 | circular, elliptic, parabolic or hyperbolic |
gm_km3_s2 | km^3/s^2 | |
body_radius_km | km | |
a_km | km | semi-major axis; null on a parabola |
p_km | km | semi-latus rectum h^2/GM |
e | 1 | |
i_deg | deg | |
raan_deg | deg | |
argp_deg | deg | |
true_anomaly_deg | deg | |
mean_anomaly_deg | deg | null on a parabola |
time_since_periapsis_s | s | |
period_s | s | null on an open orbit |
mean_motion_rad_s | rad/s | |
specific_energy_km2_s2 | km^2/s^2 | |
h_km2_s | km^2/s | |
periapsis_radius_km | km | |
apoapsis_radius_km | km | |
periapsis_altitude_km | km | |
apoapsis_altitude_km | km | |
v_periapsis_km_s | km/s | |
v_apoapsis_km_s | km/s | |
v_infinity_km_s | km/s | hyperbolic excess speed; null unless hyperbolic |
turn_angle_deg | deg | hyperbolic turn angle 2 asin(1/e); null unless hyperbolic |
r_km | km | |
v_km_s | km/s | |
r_mag_km | km | |
v_mag_km_s | km/s | |
altitude_km | km | |
v_circular_km_s | km/s | |
v_escape_km_s | km/s | |
dt_s | s | |
r_end_km | km | |
v_end_km_s | km/s | |
r_end_mag_km | km | |
v_end_mag_km_s | km/s | |
altitude_end_km | km | |
true_anomaly_end_deg | deg | |
mean_anomaly_end_deg | deg | |
position_change_km | km | |
velocity_change_km_s | km/s | |
energy_rel_change | 1 | |
h_rel_change | 1 | |
roundtrip_rel_error | 1 | state -> elements -> state, relative |
kepler_iterations | 1 | |
clears_body | 1 | |
warnings | 1 | |
conventions | 1 | |
orbit_csv_rows | 1 |
Try the call
Change a value and the command updates. Nothing runs here; paste it into your terminal or give it to your agent.