Skip to content

Cartesian Coordinates

Functions for working with Cartesian state vectors and conversions.

State Conversions

state_koe_to_eci builtin

state_koe_to_eci(x_oe: Union[ndarray, Sequence], angle_format: AngleFormat) -> ndarray

Convert osculating orbital elements to Cartesian state.

Transforms a state vector from osculating Keplerian orbital elements to Cartesian position and velocity coordinates.

Parameters:

Name Type Description Default
x_oe ndarray or list

Osculating orbital elements [a, e, i, RAAN, omega, M] where a is semi-major axis (meters), e is eccentricity (dimensionless), i is inclination (radians or degrees), RAAN is right ascension of ascending node (radians or degrees), omega is argument of periapsis (radians or degrees), and M is mean anomaly (radians or degrees).

required
angle_format AngleFormat

Angle format for angular elements (RADIANS or DEGREES).

required

Returns:

Type Description
ndarray

numpy.ndarray: Cartesian state [x, y, z, vx, vy, vz] where position is in meters and velocity is in meters per second.

Example
1
2
3
4
5
6
7
import brahe as bh
import numpy as np

# Orbital elements for a circular orbit
oe = np.array([7000000.0, 0.0, 0.0, 0.0, 0.0, 0.0])  # a, e, i, RAAN, omega, M
x_cart = bh.state_koe_to_eci(oe, bh.AngleFormat.RADIANS)
print(f"Cartesian state: {x_cart}")

state_eci_to_koe builtin

state_eci_to_koe(x_cart: Union[ndarray, Sequence], angle_format: AngleFormat) -> ndarray

Convert Cartesian state to osculating orbital elements.

Transforms a state vector from Cartesian position and velocity coordinates to osculating Keplerian orbital elements.

Parameters:

Name Type Description Default
x_cart ndarray or list

Cartesian state [x, y, z, vx, vy, vz] where position is in meters and velocity is in meters per second.

required
angle_format AngleFormat

Angle format for output angular elements (RADIANS or DEGREES).

required

Returns:

Type Description
ndarray

numpy.ndarray: Osculating orbital elements [a, e, i, RAAN, omega, M] where a is semi-major axis (meters), e is eccentricity (dimensionless), i is inclination (radians or degrees), RAAN is right ascension of ascending node (radians or degrees), omega is argument of periapsis (radians or degrees), and M is mean anomaly (radians or degrees).

Example
1
2
3
4
5
6
7
import brahe as bh
import numpy as np

# Cartesian state vector
x_cart = np.array([7000000.0, 0.0, 0.0, 0.0, 7546.0, 0.0])  # [x, y, z, vx, vy, vz]
oe = bh.state_eci_to_koe(x_cart, bh.AngleFormat.RADIANS)
print(f"Orbital elements: a={oe[0]:.0f}m, e={oe[1]:.6f}, i={oe[2]:.6f} rad")

Arbitrary Central Body

state_koe_to_eci_for_body builtin

state_koe_to_eci_for_body(x_oe: Union[ndarray, Sequence], gm: float, angle_format: AngleFormat) -> ndarray

Convert osculating orbital elements to a Cartesian state about a central body with an arbitrary gravitational parameter. Inverse of state_eci_to_koe_for_body.

Generalizes state_koe_to_eci to central bodies other than Earth (e.g. the Moon or Mars). state_koe_to_eci is equivalent to calling this with gm = GM_EARTH.

Parameters:

Name Type Description Default
x_oe ndarray or list

Osculating orbital elements [a, e, i, RAAN, omega, M], where the semi-major axis is in meters and angles are in the given format.

required
gm float

Gravitational parameter of the central body. Units: (m^3/s^2)

required
angle_format AngleFormat

Angle format for input angular elements (RADIANS or DEGREES).

required

Returns:

Type Description
ndarray

numpy.ndarray: Cartesian state [x, y, z, vx, vy, vz] in the central body's inertial frame. Units: (m; m/s)

Example
1
2
3
4
5
6
import brahe as bh
import numpy as np

# Low lunar orbit elements to a Moon-centered Cartesian state
oe = np.array([bh.R_MOON + 100e3, 0.0, 90.0, 0.0, 0.0, 0.0])
x_cart = bh.state_koe_to_eci_for_body(oe, bh.GM_MOON, bh.AngleFormat.DEGREES)

state_eci_to_koe_for_body builtin

state_eci_to_koe_for_body(x_cart: Union[ndarray, Sequence], gm: float, angle_format: AngleFormat) -> ndarray

Convert Cartesian state to osculating orbital elements about a central body with an arbitrary gravitational parameter.

Generalizes state_eci_to_koe to central bodies other than Earth (e.g. the Moon or Mars). state_eci_to_koe is equivalent to calling this with gm = GM_EARTH.

Parameters:

Name Type Description Default
x_cart ndarray or list

Cartesian state [x, y, z, vx, vy, vz] in the central body's inertial frame, where position is in meters and velocity is in meters per second.

required
gm float

Gravitational parameter of the central body. Units: (m^3/s^2)

required
angle_format AngleFormat

Angle format for output angular elements (RADIANS or DEGREES).

required

Returns:

Type Description
ndarray

numpy.ndarray: Osculating orbital elements [a, e, i, RAAN, omega, M] about the central body with gravitational parameter gm.

Example
1
2
3
4
5
6
import brahe as bh
import numpy as np

# Cartesian state vector about the Moon
x_cart = np.array([1837.4e3, 0.0, 0.0, 0.0, 1600.0, 0.0])
oe = bh.state_eci_to_koe_for_body(x_cart, bh.GM_MOON, bh.AngleFormat.RADIANS)

See Also