From e1c96579184f3c0baa9a801231facc4ce4f5309d Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Fri, 22 Jul 2022 08:39:18 -0400 Subject: [PATCH] add orbitGetTransferVelocity() --- src/game.cpp | 9 --------- src/main.cpp | 12 +++++++++--- src/orbits.cpp | 19 ++++++++++++++++++- src/orbits.h | 4 ++++ 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index fbd2292..66942a8 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -155,15 +155,6 @@ addManeuver(GameOrbit* orbit, if (node.impulse_type == ImpulseType::PROGRADE) { - double clamped_theta = orbitClampAngle(true_anomaly) + 2 * M_PI; - LOGF(Debug, "adding prograde maneuver\n," - "theta: %f,\n" - "clamped theta: %f,\n" - "dv: %f\n", - true_anomaly, - clamped_theta, - impulse_delta_v); - node.true_anomaly = true_anomaly; node.impulse_delta_v = impulse_delta_v; node.active = true; diff --git a/src/main.cpp b/src/main.cpp index e513e65..dd55a08 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -250,9 +250,15 @@ loadScene(GameState* gs, RenderState* rs) gs->coord_overlay = addCoordinateOverlay(rs); - OrbitalElements el = orbitInit(8000, 0, 0, 0, 0, DEG2RAD(-90)); - GameOrbit* go_1 = loadOrbit(gs, rs, body, el, rg, "sat_01"); - addManeuver(go_1, ImpulseType::PROGRADE, DEG2RAD(180), 1); + OrbitalElements el1 = orbitInit(8000, 0, 0, 0, 0, DEG2RAD(-90)); + GameOrbit* go_1 = loadOrbit(gs, rs, body, el1, rg, "sat_01"); + + OrbitalElements el2 = orbitInit(20000, 0, 0, 0, 0, 0); + loadOrbit(gs, rs, body, el2, rg, "sat_02"); + //GameOrbit* go_2 = loadOrbit(gs, rs, body, el2, rg, "sat_02"); + + double v_transfer = orbitGetTransferVelocity(go_1->system, el2); + addManeuver(go_1, ImpulseType::PROGRADE, DEG2RAD(180), v_transfer); return true; } diff --git a/src/orbits.cpp b/src/orbits.cpp index d5be426..f2c70ea 100644 --- a/src/orbits.cpp +++ b/src/orbits.cpp @@ -60,7 +60,6 @@ ellipseInitAE(double a, double e) OrbitalElements orbitInit(double a, double e, double iota, double ohm, double omega, double nu) { - // TODO: remaining elements: iota, ohm, omega, nu OrbitalElements o = {0}; o.a = a; o.e = e; @@ -326,6 +325,24 @@ orbitGetTimeOfFlight(TwoBodySystem sys, double theta_begin, double theta_end) return tof_end - tof_begin; } +double +orbitGetTransferVelocity(const TwoBodySystem& sys, + const OrbitalElements& target) +{ + const OrbitalElements& el1 = sys.elements; + assert(el1.iota == target.iota); + assert(el1.e == 0 && target.e == 0); + + const double mu = sys.body.mu; + double a_t = (el1.a + target.a) / 2; + double transfer_energy = orbitGetSpecificEnergy(a_t, mu); + double r_periapse = el1.a; // NOTE: circular orbit + + double v1 = orbitGetVelocity(orbitGetSpecificEnergy(el1.a, mu), mu, el1.a); + double vt = orbitGetVelocity(transfer_energy, mu, r_periapse); + return vt - v1; +} + // internal diff --git a/src/orbits.h b/src/orbits.h index 15625b0..bbea848 100644 --- a/src/orbits.h +++ b/src/orbits.h @@ -254,3 +254,7 @@ orbitGetPropagatedTrueAnomaly(TwoBodySystem sys, double orbitGetTimeOfFlight(TwoBodySystem sys, double theta_begin, double theta_end); + +// NOTE return impulse magnitute for Hohmann transfer orbit +double orbitGetTransferVelocity(const TwoBodySystem& sys, + const OrbitalElements& target);