// functions for calculating steering values. function GetPitch { parameter v is SHIP:FACING:FOREVECTOR. return 90 - vectorangle(SHIP:UP:FOREVECTOR, v). } 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. } // 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. function CreateCircularizationNode { parameter where is "APO". local t is TIME. if where:IsType("String") { if where = "APO" { set t to TIME + SHIP:ORBIT:ETA:APOAPSIS. } else if where = "PERI" { set t to TIME + SHIP:ORBIT:ETA:PERIAPSIS. } else { print "WARNING: Invalid string passed to CreateCirculazationNode(). Node is invalid.". } } else { // we've been passed a time at which to circularize. set t to where. } local Vc is sqrt(SHIP:BODY:MU/(PositionAt(SHIP, t) - SHIP:BODY:POSITION):MAG). local dV is Vc - VelocityAt(SHIP, t):ORBIT:MAG. local n is Node(t, 0, 0, dV). return n. }