kOS/lib/navigation.ks

67 lines
2.0 KiB
Plaintext
Raw Normal View History

2021-07-19 07:43:07 +00:00
// functions for calculating steering values.
function GetPitch {
parameter v is SHIP:FACING:FOREVECTOR.
return 90 - vectorangle(SHIP:UP:FOREVECTOR, v).
}
2021-07-19 07:43:07 +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.
}
// 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".
2021-08-09 00:47:14 +00:00
local t is TIME.
if where:IsType("String") {
if where = "APO" {
2021-08-09 00:47:14 +00:00
set t to TIME + SHIP:ORBIT:ETA:APOAPSIS.
} else if where = "PERI" {
2021-08-09 00:47:14 +00:00
set t to TIME + SHIP:ORBIT:ETA:PERIAPSIS.
} else {
print "WARNING: Invalid string passed to CreateCirculazationNode(). Node is invalid.".
}
} else {
2021-08-09 00:47:14 +00:00
// we've been passed a time at which to circularize.
set t to where.
}
2021-08-09 00:47:14 +00:00
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.
2021-07-19 07:43:07 +00:00
}
2021-08-09 17:51:24 +00:00
// function PredictGeo {
// parameter t.
// local pos is PositionAt(SHIP,t).
// local rDir is VDOT(SHIP:BODY:NORTH:FOREVECTOR,SHIP:BODY:ANGULARVEL). //the number of radians the body will rotate in one second (negative if rotating counter clockwise when viewed looking down on north
// local dT is t - TIME:SECONDS.
// local geoPos is SHIP:BODY:GeoPositionOf(pos).
// local drift is rDir * dT * CONSTANT:RADTODEG.
// local long is Mod(geoPos:LNG + drift, 360).
// if long < -180 {
// set long to long + 360.
// }
// if long > 180 {
// set long TO long - 360.
// }
// return LatLng(geoPos:LAT, long).
// }