|
|
|
|
@ -263,3 +263,27 @@ orbitClampAngle(double theta)
|
|
|
|
|
double revs = floor(theta / (2 * M_PI)); |
|
|
|
|
return theta - revs * 2 * M_PI; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
double |
|
|
|
|
orbitGetTimeOfFlight(system_2body sys, double theta_0, double theta_1) |
|
|
|
|
{ |
|
|
|
|
double e = sys.ep.e; |
|
|
|
|
|
|
|
|
|
// get mean motion (n)
|
|
|
|
|
double n = getMeanMotion(sys.body.mu, sys.ep.a); |
|
|
|
|
|
|
|
|
|
// get mean anomaly for theta_0 (M0)
|
|
|
|
|
double ecc_1 = getEccAnomFromTrueAnom(sys.ep.e, theta_0); |
|
|
|
|
|
|
|
|
|
// get mean anomaly for theta_1 (M1)
|
|
|
|
|
double ecc_2 = getEccAnomFromTrueAnom(sys.ep.e, theta_1); |
|
|
|
|
|
|
|
|
|
// test if orbit passes through periapsis, and if so, add 2_PI
|
|
|
|
|
// TODO: could also check for multiple revolutions, but that would be
|
|
|
|
|
// pretty unlikely if we're updating the simulation every 33ms
|
|
|
|
|
// use Kepler's equation for time of flight
|
|
|
|
|
double tof_1 = 1 / n * (ecc_1 - e * sin(ecc_1)); |
|
|
|
|
double tof_2 = 1 / n * (ecc_2 - e * sin(ecc_2)); |
|
|
|
|
|
|
|
|
|
return tof_2 - tof_1; |
|
|
|
|
} |
|
|
|
|
|