Browse Source

add test case for orbit shaping

main
cinnaboot 4 years ago
parent
commit
157e770bb8
  1. 15
      src/orbits.cpp
  2. 25
      tests/orbit_test.cpp

15
src/orbits.cpp

@ -287,3 +287,18 @@ orbitGetTimeOfFlight(TwoBodySystem sys, double theta_begin, double theta_end)
return tof_end - tof_begin;
}
// internal
double
getApoapsis(double a, double e)
{
return a * (1 + e);
}
double
getPeriapsis(double a, double e)
{
return a * (1 - e);
}

25
tests/orbit_test.cpp

@ -250,3 +250,28 @@ TEST_CASE("time of flight example 4.2", "[orbits]")
double tof = orbitGetTimeOfFlight(sys, theta_1, theta_2);
REQUIRE_THAT(tof, WithinAbs(7867.5, 2 * 0.5));
}
TEST_CASE("orbit shaping example 7.1", "[orbits]")
{
double a = 8500.0;
double e = 0.15;
double mu = EARTH_GRAVITATIONAL_PARAMETER;
double epsilon = orbitGetSpecificEnergy(a, mu);
double r_apogee = getApoapsis(a, e);
REQUIRE_THAT(r_apogee, WithinAbs(9775, 1));
double r_perigee = getPeriapsis(a, e);
REQUIRE_THAT(r_perigee, WithinAbs(7225, 1));
double v_apogee = orbitGetVelocity(epsilon, mu, r_apogee);
REQUIRE_THAT(v_apogee, WithinAbs(5.8873, 1e-4));
double a_target = r_apogee;
double epsilon_target = orbitGetSpecificEnergy(a_target, mu);
double v_target = orbitGetVelocity(epsilon_target, mu, r_apogee);
REQUIRE_THAT(v_target, WithinAbs(6.3857, 1e-4));
double delta_v = v_target - v_apogee;
REQUIRE_THAT(delta_v, WithinAbs(0.4983, 1e-4));
}

Loading…
Cancel
Save