Skip to content

NTW Frame

NTW places Y along the velocity, Z along the orbit normal, and \(X = Y \times Z\) in the orbit plane, pointing outward. It coincides with RTN on a circular orbit and differs from it by the flight-path angle otherwise. Its rate is the two-body turn rate of the velocity direction, \(\mu |h| / (r^3 v^2)\) about Z.

import numpy as np

import brahe as bh

bh.initialize_eop()

# Circular orbit: NTW and RTN coincide
x_circ = bh.state_koe_to_eci(
    np.array([bh.R_EARTH + 700e3, 0.0, 97.8, 15.0, 30.0, 45.0]), bh.AngleFormat.DEGREES
)
print(
    "Circular: NTW equals RTN:",
    np.allclose(bh.rotation_ntw_to_eci(x_circ), bh.rotation_rtn_to_eci(x_circ)),
)

# Eccentric orbit: the NTW T axis is tilted from the RTN along-track axis
# toward R by the flight-path angle
x_ecc = bh.state_koe_to_eci(
    np.array([bh.R_EARTH + 700e3, 0.1, 97.8, 15.0, 30.0, 45.0]), bh.AngleFormat.DEGREES
)
r_ntw = bh.rotation_ntw_to_eci(x_ecc)
r_rtn = bh.rotation_rtn_to_eci(x_ecc)
gamma = np.degrees(np.arcsin(np.dot(r_ntw[:, 1], r_rtn[:, 0])))
print(
    f"Eccentric: flight-path angle from the RTN along-track axis to the NTW T axis: {gamma:.3f} deg"
)

# Rates: the velocity direction turns slower than the position direction near periapsis
print(
    f"omega_ntw z: {bh.omega_ntw(x_ecc)[2]:.6e} rad/s, omega_rtn z: {bh.omega_rtn(x_ecc)[2]:.6e} rad/s"
)

# About Mars, pass the gravitational parameter explicitly
oe_mars = np.array([bh.R_MARS + 400e3, 0.05, 92.6, 45.0, 270.0, 10.0])
x_mars = bh.state_koe_to_inertial_for_body(
    oe_mars, bh.CentralBody.Mars, bh.AngleFormat.DEGREES
)
print(
    f"omega_ntw_for_body about Mars: {bh.omega_ntw_for_body(x_mars, bh.GM_MARS)[2]:.6e} rad/s"
)

# Relative state round trip
x_rel = np.array([200.0, 1000.0, 0.0, 0.0, 0.0, 0.0])
x_deputy = bh.state_ntw_to_eci(x_ecc, x_rel)
print(
    f"Round trip error: {np.linalg.norm(bh.state_eci_to_ntw(x_ecc, x_deputy) - x_rel):.2e}"
)

# Frame graph
epc = bh.Epoch.from_datetime(2024, 3, 1, 0, 0, 0.0, 0.0, bh.UTC)
bh.register_object("SC", lambda epoch: x_ecc, bh.CelestialFrame.GCRF)
r_graph = bh.rotation_frame_to_frame(
    bh.CelestialFrame.GCRF, bh.ReferenceFrame.NTW("SC"), epc
)
print(
    "Frame graph matches rotation_eci_to_ntw:",
    np.allclose(r_graph, bh.rotation_eci_to_ntw(x_ecc)),
)
bh.clear_object_registry()
use brahe as bh;
use brahe::frames::{CelestialFrame, ReferenceFrame};
use brahe::time::{Epoch, TimeSystem};
use brahe::utils::BraheError;
use brahe::utils::state_providers::SStateProvider;
use nalgebra::Vector6;

/// A state provider returning a fixed state at every epoch, for registering
/// the spacecraft as an object.
struct ConstantProvider(Vector6<f64>);
impl SStateProvider for ConstantProvider {
    fn state(&self, _epoch: Epoch) -> Result<Vector6<f64>, BraheError> {
        Ok(self.0)
    }
}

fn main() {
    bh::initialize_eop().unwrap();

    // Circular orbit: NTW and RTN coincide
    let x_circ = bh::state_koe_to_eci(
        Vector6::new(bh::R_EARTH + 700e3, 0.0, 97.8, 15.0, 30.0, 45.0),
        bh::AngleFormat::Degrees,
    );
    println!(
        "Circular: NTW equals RTN: {}",
        (bh::rotation_ntw_to_eci(x_circ) - bh::rotation_rtn_to_eci(x_circ)).norm() < 1e-12
    );

    // Eccentric orbit: the NTW T axis is tilted from the RTN along-track axis
    // toward R by the flight-path angle
    let x_ecc = bh::state_koe_to_eci(
        Vector6::new(bh::R_EARTH + 700e3, 0.1, 97.8, 15.0, 30.0, 45.0),
        bh::AngleFormat::Degrees,
    );
    let r_ntw = bh::rotation_ntw_to_eci(x_ecc);
    let r_rtn = bh::rotation_rtn_to_eci(x_ecc);
    let gamma = r_ntw.column(1).dot(&r_rtn.column(0)).asin().to_degrees();
    println!(
        "Eccentric: flight-path angle from the RTN along-track axis to the NTW T axis: {:.3} deg",
        gamma
    );

    // Rates: the velocity direction turns slower than the position direction near periapsis
    let omega_ntw = bh::omega_ntw(x_ecc);
    let omega_rtn = bh::omega_rtn(x_ecc);
    println!(
        "omega_ntw z: {:.6e} rad/s, omega_rtn z: {:.6e} rad/s",
        omega_ntw[2], omega_rtn[2]
    );

    // About Mars, pass the gravitational parameter explicitly
    let oe_mars = Vector6::new(bh::R_MARS + 400e3, 0.05, 92.6, 45.0, 270.0, 10.0);
    let x_mars = bh::state_koe_to_inertial_for_body(
        oe_mars,
        &bh::CentralBody::Mars,
        bh::AngleFormat::Degrees,
    )
    .unwrap();
    println!(
        "omega_ntw_for_body about Mars: {:.6e} rad/s",
        bh::omega_ntw_for_body(x_mars, bh::GM_MARS)[2]
    );

    // Relative state round trip
    let x_rel = Vector6::new(200.0, 1000.0, 0.0, 0.0, 0.0, 0.0);
    let x_deputy = bh::state_ntw_to_eci(x_ecc, x_rel);
    println!(
        "Round trip error: {:.2e}",
        (bh::state_eci_to_ntw(x_ecc, x_deputy) - x_rel).norm()
    );

    // Frame graph
    let epc = Epoch::from_datetime(2024, 3, 1, 0, 0, 0.0, 0.0, TimeSystem::UTC);
    bh::register_object("SC", ConstantProvider(x_ecc), CelestialFrame::GCRF).unwrap();
    let r_graph =
        bh::rotation_frame_to_frame(CelestialFrame::GCRF, ReferenceFrame::NTW("SC"), epc)
            .unwrap();
    println!(
        "Frame graph matches rotation_eci_to_ntw: {}",
        (r_graph - bh::rotation_eci_to_ntw(x_ecc)).norm() < 1e-12
    );
    bh::clear_object_registry();
}
Output
1
2
3
4
5
6
Circular: NTW equals RTN: True
Eccentric: flight-path angle from the RTN along-track axis to the NTW T axis: 4.360 deg
omega_ntw z: 1.133215e-03 rad/s, omega_rtn z: 1.207042e-03 rad/s
omega_ntw_for_body about Mars: 9.316295e-04 rad/s
Round trip error: 1.21e-10
Frame graph matches rotation_eci_to_ntw: True
1
2
3
4
5
6
Circular: NTW equals RTN: true
Eccentric: flight-path angle from the RTN along-track axis to the NTW T axis: 4.360 deg
omega_ntw z: 1.133215e-3 rad/s, omega_rtn z: 1.207042e-3 rad/s
omega_ntw_for_body about Mars: 9.316295e-4 rad/s
Round trip error: 1.21e-10
Frame graph matches rotation_eci_to_ntw: true

See Also