Add code to estimate at what distance from a grounded target we should burn to come to a stop over the target.

This commit is contained in:
Anna Rose Wiggins 2021-08-10 18:08:00 -04:00
parent 224a076b8b
commit aa7e50cfff
3 changed files with 69 additions and 9 deletions

View file

@ -1,5 +1,7 @@
// functions for calculating steering values.
runoncepath("/lib/node").
function GetPitch {
parameter v is SHIP:FACING:FOREVECTOR.
return 90 - vectorangle(SHIP:UP:FOREVECTOR, v).
@ -46,6 +48,41 @@ function CreateCircularizationNode {
return n.
}
// The distance at which to start burning to reach a target on the ground.
// REQUIRES a circular orbit.
// TODO: it would be great to semi-automate this...
function TargetBurnDistance {
return Sqrt(StoppingDistance()^2 + (SHIP:ORBIT:SEMIMAJORAXIS - SHIP:BODY:RADIUS - TARGET:ALTITUDE)^2).
}
// Stopping distance at current velocity. For a circular orbit this is valid at any point in the orbit.
function StoppingDistance {
local dV is SHIP:VELOCITY:SURFACE:MAG.
return dV*BurnTime(dV)/2.
}
// Figure out our closest approach to our current target within the next
// N seconds. (default orbital_period * 2)
// This is a horrible, terrible, no good, very bad brute force hack.
// function timeAtClosestApproach {
// parameter maxSeconds is SHIP:ORBIT:PERIOD * 2.
// // find the closest approach to pos
// local t is TIME.
// local minD is (PositionAt(TARGET, t) - PositionAt(SHIP, t)):MAG.
// local minT is t.
// until false {
// local d is (PositionAt(TARGET, t) - PositionAt(SHIP, t)):MAG.
// if d < minD {
// set minD to d.
// set minT to t.
// }
// set t to t+1.
// }
// return minT.
// }
// function PredictGeo {
// parameter t.