Recovered from patate
This commit is contained in:
commit
3c5f245b49
1 changed files with 53 additions and 0 deletions
53
ksp_toolbox/plane_change.py
Normal file
53
ksp_toolbox/plane_change.py
Normal file
|
@ -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)
|
Loading…
Reference in a new issue