|
|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
#include "test_utilities.h" |
|
|
|
|
#include <cstdlib> |
|
|
|
|
#include <cmath> |
|
|
|
|
#include <cstdio> |
|
|
|
|
|
|
|
|
|
double calculate_kinetic_energy(CelestialBody* body) { |
|
|
|
|
double v_squared = body->global_velocity.x * body->global_velocity.x + |
|
|
|
|
@ -164,3 +165,38 @@ bool compare_vec3(Vec3 a, Vec3 b, double tolerance) {
|
|
|
|
|
fabs(a.y - b.y) <= tolerance && |
|
|
|
|
fabs(a.z - b.z) <= tolerance; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void dump_simulation_state(SimulationState* sim, const char* label) { |
|
|
|
|
printf("\n=== %s (t=%.0f s) ===\n", label, sim->time); |
|
|
|
|
|
|
|
|
|
printf("Bodies (%d):\n", sim->body_count); |
|
|
|
|
for (int i = 0; i < sim->body_count; i++) { |
|
|
|
|
printf(" [%d] %s: mass=%.2e kg\n", |
|
|
|
|
i, sim->bodies[i].name, sim->bodies[i].mass); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
printf("Spacecraft (%d):\n", sim->craft_count); |
|
|
|
|
for (int i = 0; i < sim->craft_count; i++) { |
|
|
|
|
Spacecraft* s = &sim->spacecraft[i]; |
|
|
|
|
double r = sqrt(s->local_position.x*s->local_position.x + |
|
|
|
|
s->local_position.y*s->local_position.y + |
|
|
|
|
s->local_position.z*s->local_position.z); |
|
|
|
|
double v = sqrt(s->local_velocity.x*s->local_velocity.x + |
|
|
|
|
s->local_velocity.y*s->local_velocity.y + |
|
|
|
|
s->local_velocity.z*s->local_velocity.z); |
|
|
|
|
printf(" [%d] %s: r=%.1f v=%.1f nu=%.5f a=%.1f e=%.6f\n", |
|
|
|
|
i, s->name, r, v, |
|
|
|
|
s->orbit.true_anomaly, s->orbit.semi_major_axis, s->orbit.eccentricity); |
|
|
|
|
printf(" pos=(%.1f, %.1f, %.1f) vel=(%.1f, %.1f, %.1f)\n", |
|
|
|
|
s->local_position.x, s->local_position.y, s->local_position.z, |
|
|
|
|
s->local_velocity.x, s->local_velocity.y, s->local_velocity.z); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
printf("Maneuvers (%d):\n", sim->maneuver_count); |
|
|
|
|
for (int i = 0; i < sim->maneuver_count; i++) { |
|
|
|
|
Maneuver* m = &sim->maneuvers[i]; |
|
|
|
|
printf(" [%d] %s: craft=%d dir=%d dv=%.4f trigger=%d val=%.2f exec=%d\n", |
|
|
|
|
i, m->name, m->craft_index, m->direction, m->delta_v, |
|
|
|
|
m->trigger_type, m->trigger_value, m->executed); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|