Browse Source

add debugging to problematic simulation function

main
cinnaboot 6 months ago
parent
commit
e857ce57a5
  1. 11
      src/simulation.cpp

11
src/simulation.cpp

@ -1,4 +1,5 @@
#include "simulation.h" #include "simulation.h"
#include <cassert>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <cstdio> #include <cstdio>
@ -129,7 +130,14 @@ static void compute_orbital_velocity_from_vis_viva(CelestialBody* body,
double e = body->eccentricity; double e = body->eccentricity;
double a = body->semi_major_axis; 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) { if (e > 0.01) {
printf(" %s: eccentric orbit (e=%.2f, a=%.3e m), speed at r=%.3e m: %.3f km/s\n", 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); vel_dir = vec3_normalize(vel_dir);
body->velocity = vec3_scale(vel_dir, speed); 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); body->velocity = vec3_add(body->velocity, parent->velocity);
} }

Loading…
Cancel
Save