You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3.0 KiB
3.0 KiB
OrbitTracker 3D Fix Plan
Problem
update_orbit_tracker() only uses atan2(y, x) which calculates the angle in the x-y plane. For 3D inclined orbits, this doesn't track the true orbital angular position because:
- The spacecraft moves in an inclined orbital plane (not the x-y plane)
- The x-y projection doesn't represent the true angular progress around the orbit
Current Implementation (Failing)
Vec3 relative_pos = vec3_sub(body->global_position, parent->global_position);
double current_angle = atan2(relative_pos.y, relative_pos.x); // Only works for 2D orbits in x-y plane
Solution
Track the orbital angular position by projecting the 3D position onto the orbital plane and calculating the true anomaly.
Implementation Approach
Option 1: Store Orbital Plane Normal (Recommended)
Add fields to OrbitTracker to store the orbital plane orientation:
Vec3 orbital_plane_normal- Normal vector to the orbital planeVec3 reference_direction- Reference direction in the orbital plane (periapsis direction)
Calculation steps:
-
Compute orbital plane normal from inclination (i) and RAAN (Ω):
n_x = sin(i) * sin(Ω) n_y = -sin(i) * cos(Ω) n_z = cos(i) -
Compute periapsis direction in 3D space:
R_z(Ω) · R_x(i) · R_z(ω) transforms (1, 0, 0) to periapsis direction -
Project position onto orbital plane and calculate angle from periapsis
Option 2: Use Existing Rotation Matrix
Reuse mat3_rotation_orbital() to transform position back to orbital plane coordinates:
- Apply inverse rotation:
R_orbital^T · r_3D = r_orbital_plane - Calculate angle in orbital plane:
atan2(y_orbital, x_orbital)
This is simpler and reuses existing code.
Changes Required
test_utilities.h
- Add
double inclinationfield toOrbitTrackerstruct - Add
double longitude_of_ascending_nodefield - Add
double argument_of_periapsisfield
test_utilities.cpp
- Modify
create_orbit_tracker_with_min_time()to accept orbital elements - Modify
update_orbit_tracker()to:- Build inverse rotation matrix from stored orbital elements
- Transform 3D position back to orbital plane
- Calculate angle in orbital plane
test_inclined_orbits.cpp
- Update
create_orbit_tracker_with_min_time()calls to pass orbital elements
Test
- Molniya orbital period test should pass (12 hours ± tolerance)
- All other orbit tests should continue to pass
Notes
- Backward compatibility: Planar orbits (i=0) should work exactly as before
- The inverse rotation is just the transpose of the rotation matrix (orthogonal)
- Performance: Minimal impact, only called during tests
Files to Modify
src/test_utilities.h- Add orbital element fields to OrbitTrackersrc/test_utilities.cpp- Implement 3D angle calculationtests/test_inclined_orbits.cpp- Update tracker creation callstests/test_orbital_period.cpp- May need updates if using trackertests/test_moon_orbits.cpp- May need updates if using tracker