diff --git a/src/simulation.cpp b/src/simulation.cpp index 7bad5af..728121d 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -173,7 +173,9 @@ static void compute_orbital_velocity_from_vis_viva(CelestialBody* body, double a = body->semi_major_axis; double v_squared; - if (fabs(e - 1.0) < 0.0001) { + if (fabs(e) < 0.0001) { + v_squared = G * parent->mass / a; + } else if (fabs(e - 1.0) < 0.0001) { v_squared = 2.0 * G * parent->mass / distance; } else { v_squared = G * parent->mass * (2.0 / distance - 1.0 / a); @@ -181,6 +183,7 @@ static void compute_orbital_velocity_from_vis_viva(CelestialBody* body, assert(v_squared >= 0); double speed = (double) sqrt(v_squared); + Vec3 z_axis = {0.0, 0.0, 1.0}; Vec3 vel_dir = vec3_cross(r, z_axis); diff --git a/tests/configs/solar_system.toml b/tests/configs/solar_system.toml index 6fbb09c..7719540 100644 --- a/tests/configs/solar_system.toml +++ b/tests/configs/solar_system.toml @@ -131,11 +131,11 @@ semi_major_axis = 4.495e12 semi_major_axis = 1.883e9 [[bodies]] - name = "Titan" - mass = 1.345e23 - radius = 2.575e6 - position = { x = 1.435e12, y = 0.0, z = 0.0 } - parent_index = 5 - color = { r = 0.9, g = 0.6, b = 0.3 } - eccentricity = 0.0 - semi_major_axis = 1.222e9 + name = "Titan" + mass = 1.345e23 + radius = 2.575e6 + position = { x = 1.43522e12, y = 0.0, z = 0.0 } + parent_index = 5 + color = { r = 0.9, g = 0.6, b = 0.3 } + eccentricity = 0.0 + semi_major_axis = 1.222e9