Browse Source

fix tests

main
cinnaboot 5 years ago
parent
commit
bc8f84a297
  1. 35
      tests/orbit_test.cpp

35
tests/orbit_test.cpp

@ -19,42 +19,37 @@ TEST_CASE("orbit construction", "[orbits]")
// NOTE: example 4.6 in "Space Flight Dynamics" by Craig A. Kluever // NOTE: example 4.6 in "Space Flight Dynamics" by Craig A. Kluever
TEST_CASE("orbit propagation", "[orbits]") TEST_CASE("orbit propagation", "[orbits]")
{ {
orbital_elements orbit = {}; double a = 26564.5; // NOTE: semi-major axis in km
double a = 26564.5; // kilometers double e = 0.7411; // NOTE: eccentricity
double e = 0.7411; double mu = 398601.68; // NOTE: gravitational parameter
ellipse_parameters ep = ellipseInitAE(a, e); double r = 6378; // NOTE: body radius in km
orbit.ep = ep; double initial_anom = 260 * M_PI / 180; // NOTE: radians
double initial_anom = 260 * M_PI / 180; // radians unsigned int time_step = 60 * 50; // NOTE: seconds
unsigned int time_step = 60 * 50; // seconds system_2body sys = systemInit(gravBodyInit(mu, r), orbitInit(a, e));
// NOTE: solve for gravitational parameter from mean motion double E1 = getEccAnomFromTrueAnom(sys.ep.e, initial_anom);
double mean_motion = 0.00014582; // rad/s
orbit.mu = pow(mean_motion, 2) * pow(ep.a, 3);
double E1 = getEccAnomFromTrueAnom(ep.e, initial_anom);
REQUIRE_THAT(E1, WithinAbs(-0.8615, 1e-4)); REQUIRE_THAT(E1, WithinAbs(-0.8615, 1e-4));
double M1 = getMeanAnomFromEccAnom(E1, ep.e); double M1 = getMeanAnomFromEccAnom(E1, sys.ep.e);
REQUIRE_THAT(M1, WithinAbs(-0.2992, 1e-4)); REQUIRE_THAT(M1, WithinAbs(-0.2992, 1e-4));
double n = getMeanMotion(orbit.mu, orbit.ep.a); double n = getMeanMotion(sys.body.mu, sys.ep.a);
REQUIRE_THAT(n, WithinAbs(0.00014582, 1e-8)); REQUIRE_THAT(n, WithinAbs(0.00014582, 1e-8));
double M2 = getPropagatedMeanAnom(M1, n, time_step); double M2 = getPropagatedMeanAnom(M1, n, time_step);
REQUIRE_THAT(M2, WithinAbs(0.1383, 1e-5)); REQUIRE_THAT(M2, WithinAbs(0.1383, 1e-5));
// TODO: could also test for the other trial values listed in table 4.1 // TODO: could also test for the other trial values listed in table 4.1
double E2_1 = getInitialTrialValue(M2, ep.e); double E2_1 = getInitialTrialValue(M2, sys.ep.e);
REQUIRE_THAT(E2_1, WithinAbs(0.315452, 1e-5)); REQUIRE_THAT(E2_1, WithinAbs(0.315452, 1e-5));
double ecc_anom = getPropagatedEccAnomaly(orbit, initial_anom, time_step); double ecc_anom = getPropagatedEccAnomaly(sys, initial_anom, time_step);
REQUIRE_THAT(ecc_anom, WithinAbs(0.481518, 1e-5)); REQUIRE_THAT(ecc_anom, WithinAbs(0.481518, 1e-5));
double true_anom = getPropagatedTrueAnomaly(orbit, initial_anom, time_step); double true_anom = getPropagatedTrueAnomaly(sys, initial_anom, time_step);
REQUIRE_THAT(true_anom, WithinAbs(1.1339, 1e-4)); REQUIRE_THAT(true_anom, WithinAbs(1.1339, 1e-4));
double r2 = getRadialDistance(ep.e, ep.p, true_anom); double r2 = orbitGetRadialDistance(sys.ep.e, sys.ep.p, true_anom);
REQUIRE_THAT(r2, WithinAbs(9116.1, 0.1)); REQUIRE_THAT(r2, WithinAbs(9116.1, 0.1));
glm::vec2 pos = polarToRect(true_anom, r2); glm::vec2 pos = polarToRect(true_anom, r2);

Loading…
Cancel
Save