From 3c5f245b49876b1c0d2704856761c8d0dce52639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Mon, 5 Aug 2024 18:27:04 +0200 Subject: [PATCH] Recovered from patate --- ksp_toolbox/plane_change.py | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 ksp_toolbox/plane_change.py diff --git a/ksp_toolbox/plane_change.py b/ksp_toolbox/plane_change.py new file mode 100644 index 0000000..c096041 --- /dev/null +++ b/ksp_toolbox/plane_change.py @@ -0,0 +1,53 @@ +import math +from math import pi, sqrt, sin + + +class Const: + G = 6.67408e-11 + + class Mun: + M = 9.7599066e20 + R = 200e3 + + +def withbody(fun): + def wrapped(*args, body=None, **kwargs): + if body is None: + body = Const.Mun + return fun(*args, body=body, **kwargs) + + return wrapped + + +@withbody +def v_at(r, body, a=None): + if a is None: + a = r + return sqrt(Const.G * body.M * ((2 / r) - (1 / a))) + + +@withbody +def dv_change_alt(r1, r2, rconst, body): + """Δv to change the opposite side from r1 to r2, being at rconst""" + v_cur = v_at(rconst, body=body, a=(rconst + r1) / 2) + v_target = v_at(rconst, body=body, a=(rconst + r2) / 2) + return v_target - v_cur + + +@withbody +def dv_plane_change(theta, r, a, body): + return 2 * v_at(r, body=body, a=a) * sin(theta / 2) + + +@withbody +def dv_total(r_init, theta, r_high, body): + return ( + abs(dv_change_alt(r_init, r_high, r_init, body=body)) + + abs(dv_plane_change(theta, r_high, (r_high + r_init) / 2, body=body)) + + abs(dv_change_alt(r_high, r_init, r_high, body=body)) + ) + + +@withbody +def dv_total_alt(alt_init, theta, alt_high, body): + return dv_total(alt_init + body.R, theta, alt_high + body.R, body=body)