orbits
cosmic_warp.physics.orbits
Orbital-element helpers.
Host-side (pure Python/NumPy) utilities that convert between classical orbital elements and Cartesian ECI states, plus Warp twins of the forward conversion used inside reset kernels (kept side by side with the NumPy implementation so the two cannot silently drift apart).
elements_to_state
elements_to_state(
semi_major_axis: float,
eccentricity: float = 0.0,
inclination: float = 0.0,
raan: float = 0.0,
arg_periapsis: float = 0.0,
true_anomaly: float = 0.0,
mu: float = MU_EARTH,
)
Convert classical orbital elements to an ECI position/velocity pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
semi_major_axis
|
float
|
Semi-major axis [m] |
required |
eccentricity
|
float
|
Eccentricity (0 <= e < 1, bound orbits only) |
0.0
|
inclination
|
float
|
Inclination [rad], in [0, pi] |
0.0
|
raan
|
float
|
Right ascension of the ascending node [rad] |
0.0
|
arg_periapsis
|
float
|
Argument of periapsis [rad] |
0.0
|
true_anomaly
|
float
|
True anomaly [rad] |
0.0
|
mu
|
float
|
Gravitational parameter of the central body [m^3/s^2] |
MU_EARTH
|
Returns:
| Type | Description |
|---|---|
(position, velocity)
|
NumPy arrays of shape (3,), ECI frame [m], [m/s] |
Source code in cosmic_warp/physics/orbits.py
circular_orbit_state
circular_orbit_state(
altitude: float,
inclination: float = 0.0,
raan: float = 0.0,
true_anomaly: float = 0.0,
mu: float = MU_EARTH,
planet_radius: float = RE_EARTH,
)
Convenience wrapper: circular orbit specified by altitude above the surface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
altitude
|
float
|
Altitude above planet_radius [m] |
required |
inclination
|
float
|
Inclination [rad], in [0, pi] |
0.0
|
raan
|
float
|
Right ascension of the ascending node [rad] |
0.0
|
true_anomaly
|
float
|
Angular position along the orbit [rad] |
0.0
|
mu
|
float
|
Gravitational parameter of the central body [m^3/s^2] |
MU_EARTH
|
planet_radius
|
float
|
Central body equatorial radius [m] |
RE_EARTH
|
Returns:
| Type | Description |
|---|---|
(position, velocity)
|
NumPy arrays of shape (3,), ECI frame [m], [m/s] |
Source code in cosmic_warp/physics/orbits.py
state_to_elements
Inverse of elements_to_state: ECI position/velocity -> classical elements.
Conventions for the degenerate cases: equatorial orbits report raan = 0 with arg_periapsis measured from +X; circular orbits report arg_periapsis = 0 with true_anomaly measured from the ascending node (argument of latitude). Angles are returned in [0, 2*pi).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
ArrayLike
|
ECI position, array-like of shape (3,) [m] |
required |
velocity
|
ArrayLike
|
ECI velocity, array-like of shape (3,) [m/s] |
required |
mu
|
float
|
Gravitational parameter of the central body [m^3/s^2] |
MU_EARTH
|
Returns:
| Type | Description |
|---|---|
dict
|
dict with semi_major_axis, eccentricity, inclination, raan, |
dict
|
arg_periapsis, true_anomaly |
Raises:
| Type | Description |
|---|---|
ValueError
|
for rectilinear motion (zero angular momentum, including r = 0) or an unbound orbit (e >= 1), where the elements of an ellipse are undefined. |
Source code in cosmic_warp/physics/orbits.py
elements_to_rv
elements_to_rv(
sma: float64,
ecc: float64,
inc: float64,
raan: float64,
argp: float64,
true_anomaly: float64,
mu: float64,
) -> spatial_vectord
Warp twin of elements_to_state for use inside kernels.
Returns position and velocity packed in a spatial vector: unpack with wp.spatial_top (position [m]) and wp.spatial_bottom (velocity [m/s]).
Source code in cosmic_warp/physics/orbits.py
mean_to_true_anomaly
Solve Kepler's equation E - e*sin(E) = M and return the true anomaly.
Newton iteration with Danby's starter E0 = M + 0.85esign(sin M) and a fixed iteration count, so it is branch-free in data-dependent trip count and safe inside CUDA graph captures. Accurate to machine precision for bound orbits (e < 1).