Skip to content

TNW Frame

TNW is NTW with its in-plane axes reordered, \(X_\mathrm{TNW} = Y_\mathrm{NTW}\) and \(Y_\mathrm{TNW} = -X_\mathrm{NTW}\), so X lies along the velocity and Y points inward. Its rate is the NTW rate about Z.

import numpy as np

import brahe as bh

bh.initialize_eop()

# Circular orbit: X = RTN's T, Z = RTN's N, and the in-plane axes are the RTN pair swapped and negated
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
)
r_tnw = bh.rotation_tnw_to_eci(x_circ)
r_rtn = bh.rotation_rtn_to_eci(x_circ)
print(
    "Circular: TNW Y equals -RTN X, TNW X equals RTN Y, TNW Z equals RTN Z:",
    np.allclose(r_tnw[:, 1], -r_rtn[:, 0])
    and np.allclose(r_tnw[:, 0], r_rtn[:, 1])
    and np.allclose(r_tnw[:, 2], r_rtn[:, 2]),
)

# TNW is NTW with its in-plane axes reordered
r_ntw = bh.rotation_ntw_to_eci(x_circ)
print(
    "TNW is NTW reordered: X_TNW equals Y_NTW, Y_TNW equals -X_NTW:",
    np.allclose(r_tnw[:, 0], r_ntw[:, 1]) and np.allclose(r_tnw[:, 1], -r_ntw[:, 0]),
)

# Rates: TNW shares its rate with NTW
print(
    f"omega_tnw z: {bh.omega_tnw(x_circ)[2]:.6e} rad/s, omega_ntw z: {bh.omega_ntw(x_circ)[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_tnw_for_body about Mars: {bh.omega_tnw_for_body(x_mars, bh.GM_MARS)[2]:.6e} rad/s"
)

# Relative state round trip: 1 km along-track, 200 m above along -N
x_rel = np.array([1000.0, -200.0, 0.0, 0.0, 0.0, 0.0])
x_deputy = bh.state_tnw_to_eci(x_circ, x_rel)
print(
    f"Round trip error: {np.linalg.norm(bh.state_eci_to_tnw(x_circ, 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_circ, bh.CelestialFrame.GCRF)
r_graph = bh.rotation_frame_to_frame(
    bh.CelestialFrame.GCRF, bh.ReferenceFrame.TNW("SC"), epc
)
print(
    "Frame graph matches rotation_eci_to_tnw:",
    np.allclose(r_graph, bh.rotation_eci_to_tnw(x_circ)),
)
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: X = RTN's T, Z = RTN's N, and the in-plane axes are the RTN pair swapped and negated
    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,
    );
    let r_tnw = bh::rotation_tnw_to_eci(x_circ);
    let r_rtn = bh::rotation_rtn_to_eci(x_circ);
    println!(
        "Circular: TNW Y equals -RTN X, TNW X equals RTN Y, TNW Z equals RTN Z: {}",
        (r_tnw.column(1) + r_rtn.column(0)).norm() < 1e-12
            && (r_tnw.column(0) - r_rtn.column(1)).norm() < 1e-12
            && (r_tnw.column(2) - r_rtn.column(2)).norm() < 1e-12
    );

    // TNW is NTW with its in-plane axes reordered
    let r_ntw = bh::rotation_ntw_to_eci(x_circ);
    println!(
        "TNW is NTW reordered: X_TNW equals Y_NTW, Y_TNW equals -X_NTW: {}",
        (r_tnw.column(0) - r_ntw.column(1)).norm() < 1e-12
            && (r_tnw.column(1) + r_ntw.column(0)).norm() < 1e-12
    );

    // Rates: TNW shares its rate with NTW
    let omega_tnw = bh::omega_tnw(x_circ);
    let omega_ntw = bh::omega_ntw(x_circ);
    println!(
        "omega_tnw z: {:.6e} rad/s, omega_ntw z: {:.6e} rad/s",
        omega_tnw[2], omega_ntw[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_tnw_for_body about Mars: {:.6e} rad/s",
        bh::omega_tnw_for_body(x_mars, bh::GM_MARS)[2]
    );

    // Relative state round trip: 1 km along-track, 200 m above along -N
    let x_rel = Vector6::new(1000.0, -200.0, 0.0, 0.0, 0.0, 0.0);
    let x_deputy = bh::state_tnw_to_eci(x_circ, x_rel);
    println!(
        "Round trip error: {:.2e}",
        (bh::state_eci_to_tnw(x_circ, 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_circ), CelestialFrame::GCRF).unwrap();
    let r_graph =
        bh::rotation_frame_to_frame(CelestialFrame::GCRF, ReferenceFrame::TNW("SC"), epc)
            .unwrap();
    println!(
        "Frame graph matches rotation_eci_to_tnw: {}",
        (r_graph - bh::rotation_eci_to_tnw(x_circ)).norm() < 1e-12
    );
    bh::clear_object_registry();
}
Output
1
2
3
4
5
6
Circular: TNW Y equals -RTN X, TNW X equals RTN Y, TNW Z equals RTN Z: True
TNW is NTW reordered: X_TNW equals Y_NTW, Y_TNW equals -X_NTW: True
omega_tnw z: 1.060207e-03 rad/s, omega_ntw z: 1.060207e-03 rad/s
omega_tnw_for_body about Mars: 9.316295e-04 rad/s
Round trip error: 4.71e-10
Frame graph matches rotation_eci_to_tnw: True
1
2
3
4
5
6
Circular: TNW Y equals -RTN X, TNW X equals RTN Y, TNW Z equals RTN Z: true
TNW is NTW reordered: X_TNW equals Y_NTW, Y_TNW equals -X_NTW: true
omega_tnw z: 1.060207e-3 rad/s, omega_ntw z: 1.060207e-3 rad/s
omega_tnw_for_body about Mars: 9.316295e-4 rad/s
Round trip error: 4.71e-10
Frame graph matches rotation_eci_to_tnw: true

See Also