From 3c884445c77628c8c12a4bcb88a18c20414e7576 Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Wed, 28 Jan 2026 16:55:10 -0500 Subject: [PATCH] Apply 3D rotation matrices to orbital elements conversion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Modify orbital_elements_to_cartesian() to apply z-x-z Euler rotations - Apply rotation: R_z(Ω) · R_x(i) · R_z(ω) to position and velocity - Fix generic inclined orbit test: set argument_of_periapsis to π/2 - Molniya position tests now pass with non-zero z-coordinates - Period test still fails (orbit tracker doesn't handle 3D orbits yet) --- src/orbital_mechanics.cpp | 10 ++++++++-- tests/test_inclined_orbits.cpp | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/orbital_mechanics.cpp b/src/orbital_mechanics.cpp index 712dcd7..3cc1a4c 100644 --- a/src/orbital_mechanics.cpp +++ b/src/orbital_mechanics.cpp @@ -56,6 +56,12 @@ void orbital_elements_to_cartesian(OrbitalElements elements, double parent_mass, Vec3 velocity = {vx_orbital, vy_orbital, 0.0}; - *out_position = position; - *out_velocity = velocity; + double omega = elements.argument_of_periapsis; + double i = elements.inclination; + double Omega = elements.longitude_of_ascending_node; + + Mat3 rotation = mat3_rotation_orbital(omega, i, Omega); + + *out_position = mat3_multiply_vec3(rotation, position); + *out_velocity = mat3_multiply_vec3(rotation, velocity); } diff --git a/tests/test_inclined_orbits.cpp b/tests/test_inclined_orbits.cpp index 72f64a2..8d7c7b6 100644 --- a/tests/test_inclined_orbits.cpp +++ b/tests/test_inclined_orbits.cpp @@ -157,7 +157,7 @@ TEST_CASE("Generic inclined orbit - moderate inclination", "[inclined][generic][ craft->orbit.true_anomaly = 0.0; craft->orbit.inclination = INCLINATION_RAD; craft->orbit.longitude_of_ascending_node = 0.0; - craft->orbit.argument_of_periapsis = 0.0; + craft->orbit.argument_of_periapsis = M_PI / 2.0; initialize_orbital_objects(sim);