When bodies change gravitational parents, properly update their
local coordinates to maintain physics accuracy. This fixes the
bug where local positions were never updated when changing parents.
Also remove unused variable warning.
Document current progress after completing Phase 2:
- Phase 1 complete: Dual coordinate storage foundation
- Phase 2 complete: Local frame integration working
- Earth Moon test now passing (major success!)
- 7/9 tests passing (up from 6/9)
- Phases 3-5 deferred for future work
Added detailed status, commit references, and notes for future development
Modified physics integration to operate in local coordinate frames.
Parent bodies are treated as origin in child's reference frame.
Changes:
- rk4_step() now integrates local_position/local_velocity
- evaluate_acceleration() calculates gravity with parent at origin
- update_simulation() computes global coords FROM local after integration
- Added compute_global_coordinates() after root and child updates
Results:
- Earth Moon orbital stability test: NOW PASSING! (was failing)
- Moon drift reduced significantly (improved numerical precision)
- Test improvements: 3 failures → 2 failures (7/9 passing)
- Still failing: Io (Jupiter) and Titan (Saturn) - likely need tuning
Implements hierarchical_frames_plan.md Phase 2
Add dual coordinate storage to CelestialBody for hierarchical frames.
Both local (relative to parent) and global (absolute) coordinates maintained.
- Added local_position and local_velocity fields to CelestialBody
- Added initialize_local_coordinates() to convert global→local
- Added compute_global_coordinates() to convert local→global
- Updated config_loader to initialize local coords after velocity calc
- Updated update_simulation() to sync local coords after integration
- Phase 1 complete: foundation for local frame integration
Tests: Same 3 moon failures as before (no regression)
Implements hierarchical_frames_plan.md Phase 1
Removed barycentric orbit calculations for binary/multiple star systems.
Simplified calculate_initial_velocities() to only support single root body.
- Removed: compute_system_barycenter()
- Removed: compute_total_root_mass()
- Removed: set_root_bodies_velocity()
- Removed: print_system_info_if_multiple_roots()
- Simplified: calculate_initial_velocities() now sets root body velocity to zero
Remove unused multiple root body support
- Created tests/test_moon_orbits.cpp with 4 test cases:
* Moon orbital stability around Earth
* Galilean moons orbital stability around Jupiter
* Titan orbital stability around Saturn
* Combined solar system parent stability
- Enhanced test_utilities.h/cpp:
* Added min_time_days field to OrbitTracker
* Added create_orbit_tracker_with_min_time() for short-period orbits
- Fixed parent indexes in tests/configs/solar_system.toml:
* Moon: parent 3 (Mars) → 2 (Earth)
* Io/Europa/Ganymede/Callisto: parent 5 (Saturn) → 4 (Jupiter)
* Titan: parent 6 (Uranus) → 5 (Saturn)
- Updated semi_major_axis for moons to actual orbital distances
Tests reveal need for hierarchical orbit physics implementation.
Net change: +368 lines
- Removed add_body() function (unused across codebase)
- Renamed compute_initial_velocities() to calculate_initial_velocities()
- Removed redundant wrapper function
Removed 26 lines of dead code
- Rename bodies.h/cpp to simulation.h/cpp
- Refactor velocity initialization into smaller functions
- Add vec3_cross() utility for reusable calculations
- Clean up public API by making helpers static
- Break up calculate_initial_velocities() (114 lines) into 8 focused functions
- Add vec3_cross() utility to physics.cpp for reusable cross product calculation
- Make helper functions static in simulation.cpp (internal implementation detail)
- Remove unnecessary helper declarations from simulation.h (cleaner public API)
New helper functions:
- compute_perpendicular_orbital_velocity() - root body orbits
- compute_orbital_velocity_from_vis_viva() - child body orbits
- compute_system_barycenter() - barycenter calculation
- compute_total_root_mass() - total mass calculation
- set_root_bodies_velocity() - set all root velocities
- set_child_bodies_velocity() - set all child velocities
- print_system_info_if_multiple_roots() - debug output
Benefits:
- Code reuse: vec3_cross() used 2x (eliminates duplicate perpendicular logic)
- Testability: smaller functions easier to test individually
- Readability: descriptive names for each body type scenario
- Maintainability: main function reduced from 114 to 10 lines
Claude
- Renamed src/bodies.h to src/simulation.h
- Renamed src/bodies.cpp to src/simulation.cpp
- Updated all include references in src/ and tests/
- Updated Makefile to reference simulation.cpp
- Updated documentation references
Claude
- Add tomlc17 library as git submodule
- Update Makefile to build tomlc17.c with C compiler
- Replace config_loader.cpp with TOML-based implementation
- Add helper functions for parsing TOML tables (position, color)
- Convert all 5 config files from .txt to .toml format:
* configs/solar_system.toml - full solar system with planets and moons
* configs/example_binary_star.toml - binary star system
* configs/test_simple.toml - various orbit types for testing
* tests/configs/earth_circular.toml - Earth orbit test
* tests/configs/mars_circular.toml - Mars orbit test
- Update all test files to reference .toml extensions
- Remove old .txt config files (maintain compatibility)
- Support both INT64 and FP64 TOML values (tomlc17 type flexibility)
- All automated tests pass with new TOML format
Claude
Added bodies to demonstrate different trajectory types:
- Parabolic: e=1.0 at 0.5 AU (exactly at escape velocity)
- Inclined: circular orbit at 1.2 AU with 30° inclination
- Hyperbolic: e=1.5 at 0.5 AU (interstellar visitor trajectory)
These showcase the new dynamic orbital rendering capabilities
for parabolic, hyperbolic, and inclined orbits.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Calculate orbital elements dynamically from current state and parent
- Orbits now update automatically when parent body changes
- Add support for parabolic trajectories (e ≈ 1)
- Add support for hyperbolic trajectories (e > 1) with limited extent
- Properly orient orbits in 3D space using eccentricity vector
- Limit hyperbolic/parabolic drawing to avoid infinite vertices
Refactored for code reuse and separation of concerns:
- calculate_orbital_basis(): Computes orbital reference frame
- orbital_to_cartesian(): Transforms orbital coords to 3D space
- draw_orbit_segment(): Handles rendering of individual segments
- render_elliptical_orbit(): Draws closed elliptical paths
- render_hyperbolic_orbit(): Draws open hyperbolic/parabolic paths
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
The renderer already applies coordinate transforms, so keep the
original r × z_axis cross product direction.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>