vibe coding an orbital mechanics simulation to try out claude code
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.
 
 
 
 
 

64 lines
2.1 KiB

#ifndef BODIES_H
#define BODIES_H
#include "physics.h"
// Celestial body structure
struct CelestialBody {
char name[64];
double mass; // kg
double radius; // meters
Vec3 local_position; // position relative to parent (meters)
Vec3 local_velocity; // velocity relative to parent (m/s)
Vec3 position; // global position (meters from origin)
Vec3 velocity; // global velocity (m/s)
double soi_radius; // sphere of influence radius (meters)
int parent_index; // index of gravitational parent (-1 for root body like Sun)
float color[3]; // RGB color for rendering
double eccentricity; // orbital eccentricity (0 = circular, <1 = elliptical)
double semi_major_axis; // meters
};
// Simulation state
struct SimulationState {
CelestialBody* bodies;
int body_count;
int max_bodies;
double time; // simulation time (seconds)
double dt; // time step (seconds)
};
// Simulation management functions
SimulationState* create_simulation(int max_bodies, double time_step);
void destroy_simulation(SimulationState* sim);
// SOI and simulation update functions
int find_dominant_body(SimulationState* sim, int body_index);
void update_soi(CelestialBody* body, CelestialBody* parent, double semi_major_axis);
void update_simulation(SimulationState* sim);
// Velocity initialization
void calculate_initial_velocities(SimulationState* sim);
// SOI helpers
void calculate_soi_radii(SimulationState* sim);
// Coordinate frame management
void initialize_local_coordinates(SimulationState* sim);
void compute_global_coordinates(SimulationState* sim);
// Orbital elements calculation
struct OrbitalElements {
double time_days;
double semi_major_axis_au;
double eccentricity;
double specific_energy;
double distance_to_sun_au;
double distance_to_ref_body_au;
double velocity_magnitude;
};
OrbitalElements calculate_orbital_elements(CelestialBody* body, CelestialBody* primary,
CelestialBody* optional_ref_body, double current_time);
#endif