--------------------------------------------------------
-- A routine to calculate the escape burn to achieve a 'out of plane' 1:1 resonance using a simple linked-conics model
--
-- Inputs:
-- 1. The required inclination of the final heliocentric orbit relative to Earth's orbital plane
-- 2. The altitude of the LEO prior to Earth escape
--
-- Outputs:
-- 1. The elements of the Escape Burn in TransX coordinates (prograde, outward, plane-change)
-- 2. The magnitude of the escape burn needed to effect this escape burn from LEO
--
------------------------------------
-- define relevant constants for this script
muE = 398600441800000.0 -- Gravitational constant for the Earth
-- get the handles for the Sun, the Earth and the Moon
sun = oapi.get_objhandle("Sun")
earth = oapi.get_objhandle("Earth")
moon = oapi.get_objhandle("Moon")
-- pause the simulation and set the MJD to the date of interest
str = proc.wait_input("Input the tilt angle (degrees):")
theta = tonumber(str) * math.pi /180
str = proc.wait_input("Altitude of LOE departure orbit (km):")
r = (tonumber(str) + 6371) * 1000
-- get positions and masses of the gravitating bodies
q ={}
q[0] = oapi.get_globalpos(sun)
q[1] = oapi.get_globalpos(earth)
q[2] = oapi.get_globalpos(moon)
p = {}
p[0] = oapi.get_globalvel(sun)
p[1] = oapi.get_globalvel(earth)
p[2] = oapi.get_globalvel(moon)
m = {}
m[1] = oapi.get_mass(earth)
m[2] = oapi.get_mass(moon)
-- swap over to a conventional co-ordinate system
for i = 0, 2, 1 do
tempq = q[i].y
tempp = p[i].y
q[i].y = q[i].z
p[i].y = p[i].z
q[i].z = tempq
p[i].z = tempp
end
-- calculate the state vectors of the Centre of Mass of the Earth-Moon system in heliocentric coordinates.
q[3] = vec.sub( vec.div( vec.add( vec.mul(q[1],m[1]), vec.mul(q[2],m[2]) ), m[1]+m[2] ), q[0] )
p[3] = vec.sub( vec.div( vec.add( vec.mul(p[1],m[1]), vec.mul(p[2],m[2]) ), m[1]+m[2] ), p[0] )
-- construct the rotation matrix for the velocity vector
w = vec.div( q[3], vec.length(q[3] ))
R = {}
R.m11 = (1 - math.cos(theta)) * w.x * w.x + math.cos(theta)
R.m22 = (1 - math.cos(theta)) * w.y * w.y + math.cos(theta)
R.m33 = (1 - math.cos(theta)) * w.z * w.z + math.cos(theta)
R.m12 = (1 - math.cos(theta)) * w.x * w.y - math.sin(theta) * w.z
R.m13 = (1 - math.cos(theta)) * w.x * w.z + math.sin(theta) * w.y
R.m23 = (1 - math.cos(theta)) * w.y * w.z - math.sin(theta) * w.x
R.m21 = (1 - math.cos(theta)) * w.x * w.y + math.sin(theta) * w.z
R.m31 = (1 - math.cos(theta)) * w.x * w.z - math.sin(theta) * w.y
R.m32 = (1 - math.cos(theta)) * w.y * w.z + math.sin(theta) * w.x
-- calculate the change in heliocentric velocity needed to effect the tilt in the coordinates.
p[4] = mat.mul( R , p[3])
pE = vec.sub( p[1], p[0])
qE = vec.sub( q[1], q[0])
deltaV = vec.sub( p[4], pE )
-- work out the TransX reference frame
fward = vec.div( pE, vec.length(pE))
plane = vec.crossp( pE, qE)
plane = vec.div( plane, vec.length(plane))
oward = vec.crossp( plane, fward)
-- calculate the escape plan needed - using TransX coordinates
vf = vec.dotp( fward, deltaV)
vo = vec.dotp( oward, deltaV)
vp = vec.dotp( plane, deltaV)
velp = math.sqrt( vec.dotp( deltaV, deltaV) + 2 * muE / r) - math.sqrt(muE / r)
-- print out the results
term.out(' ')
term.out('TransX escape plan - current time & date')
term.out('------------------------------')
term.out('Prograde: ' .. vf .. ' m/s')
term.out('Outward: ' .. vo .. ' m/s')
term.out('Plane change: ' .. vp .. ' m/s')
term.out(' ')
term.out('Escape burn altitude: ' .. (r - 6371000) / 1000 .. ' km' )
term.out('Escape burn magnitude: ' .. velp .. ' m/s')
term.out(' ')
term.out(' ')