diff --git a/src/simulation.cpp b/src/simulation.cpp index 9f152a4..eb68a68 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -1,4 +1,5 @@ #include "simulation.h" +#include #include #include #include @@ -129,7 +130,14 @@ static void compute_orbital_velocity_from_vis_viva(CelestialBody* body, double e = body->eccentricity; double a = body->semi_major_axis; - double speed = sqrt(G * parent->mass * (2.0 / distance - 1.0 / a)); + + // FIXME: there's a bug here + // could be unit related, mass is in units of kg, and distance is meters + // insteam of km, velocity is also m/s + //double speed = (double) sqrt(G * parent->mass * (2.0 / distance - 1.0 / a)); + double v_squared = G * parent->mass * (2.0 / distance - 1.0 / a); + assert(v_squared >= 0); + double speed = (double) sqrt(v_squared); if (e > 0.01) { printf(" %s: eccentric orbit (e=%.2f, a=%.3e m), speed at r=%.3e m: %.3f km/s\n", @@ -146,6 +154,7 @@ static void compute_orbital_velocity_from_vis_viva(CelestialBody* body, vel_dir = vec3_normalize(vel_dir); body->velocity = vec3_scale(vel_dir, speed); + // FIXME: this is wrong, we should be simulating in parent coord frame body->velocity = vec3_add(body->velocity, parent->velocity); }