2021-07-19 07:43:07 +00:00
|
|
|
// functions for calculating steering values.
|
2021-07-19 04:54:32 +00:00
|
|
|
|
|
|
|
function GetPitch {
|
|
|
|
parameter v is SHIP:FACING:FOREVECTOR.
|
|
|
|
return 90 - vectorangle(SHIP:UP:FOREVECTOR, v).
|
|
|
|
}
|
2021-07-19 07:43:07 +00:00
|
|
|
|
2021-07-20 01:29:27 +00:00
|
|
|
function GetAscentVector {
|
|
|
|
parameter minPitch.
|
|
|
|
// face prograde, but hold a solid eastern heading and don't
|
|
|
|
// rotate the ship
|
|
|
|
local newHeading is lookdirup(SHIP:SRFPROGRADE:FOREVECTOR,
|
|
|
|
heading(90, 0, 270):TOPVECTOR).
|
|
|
|
if GetPitch(newHeading:FOREVECTOR) < minPitch {
|
|
|
|
set newHeading to heading(90, minPitch, 270).
|
|
|
|
}
|
|
|
|
return newHeading.
|
|
|
|
}
|
|
|
|
|
2021-08-08 20:23:49 +00:00
|
|
|
// Create a node that will circularize the orbit.
|
|
|
|
// 'where' can be one of:
|
|
|
|
// the special string "APO", for the next Apoapsis.
|
|
|
|
// the special string "PERI", for the next Periapsis.
|
|
|
|
// a time value (either a Time struct or a scalar), representing a target time.
|
2021-07-20 08:18:16 +00:00
|
|
|
function CreateCircularizationNode {
|
2021-08-08 20:23:49 +00:00
|
|
|
parameter where is "APO".
|
2021-07-20 08:18:16 +00:00
|
|
|
|
2021-08-08 20:23:49 +00:00
|
|
|
local dt is 0.
|
|
|
|
local a is 0.
|
|
|
|
local t is 0.
|
|
|
|
if where:IsType("String") {
|
|
|
|
if where = "APO" {
|
|
|
|
set dt to SHIP:ORBIT:ETA:APOAPSIS.
|
|
|
|
set a to SHIP:ORBIT:APOAPSIS.
|
|
|
|
} else if where = "PERI" {
|
|
|
|
set dt to SHIP:ORBIT:ETA:PERIAPSIS.
|
|
|
|
set a to SHIP:ORBIT:PERIAPSIS.
|
|
|
|
} else {
|
|
|
|
print "WARNING: Invalid string passed to CreateCirculazationNode(). Node is invalid.".
|
|
|
|
}
|
|
|
|
|
|
|
|
set t to TIME + dt.
|
|
|
|
} else {
|
|
|
|
set t to where.
|
|
|
|
}
|
2021-07-20 08:18:16 +00:00
|
|
|
|
2021-07-20 19:19:18 +00:00
|
|
|
local Vc is sqrt(SHIP:BODY:MU/(SHIP:BODY:RADIUS + a)).
|
2021-07-20 08:18:16 +00:00
|
|
|
local dV is Vc - VelocityAt(SHIP, t):ORBIT:MAG.
|
|
|
|
local n is Node(t, 0, 0, dV).
|
|
|
|
|
|
|
|
return n.
|
2021-07-19 07:43:07 +00:00
|
|
|
}
|