2018-07-27 17:23:38 +02:00
|
|
|
@LAZYGLOBAL OFF.
|
|
|
|
|
2018-07-27 21:32:14 +02:00
|
|
|
|
|
|
|
function semi_major_axis {
|
|
|
|
//
|
|
|
|
// Semi-major axis
|
|
|
|
// Based on:
|
|
|
|
// https://en.wikipedia.org/wiki/Semi-major_and_semi-minor_axes
|
|
|
|
// http://www.orbiterwiki.org/wiki/Front_Cover_Equations
|
|
|
|
//
|
2018-08-05 19:40:16 +02:00
|
|
|
parameter ap is APOAPSIS.
|
|
|
|
parameter pe is PERIAPSIS.
|
2018-07-27 21:32:14 +02:00
|
|
|
|
2018-08-05 19:40:16 +02:00
|
|
|
return (ap + pe + 2*BODY:radius) / 2. // Add 2x body radius because KSP measures apoapsis/periapsis from the surface
|
2018-07-27 21:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function orbital_period {
|
|
|
|
//
|
|
|
|
// The orbital period.
|
|
|
|
// Note that for all ellipses with a given semi-major axis, the orbital period is the same, disregarding their eccentricity.
|
|
|
|
// Based on:
|
|
|
|
// https://en.wikipedia.org/wiki/Semi-major_and_semi-minor_axes#Astronomy
|
|
|
|
// http://www.orbiterwiki.org/wiki/Front_Cover_Equations
|
|
|
|
//
|
2018-08-05 19:40:16 +02:00
|
|
|
parameter sme is semi_major_axis().
|
2018-07-27 21:32:14 +02:00
|
|
|
|
2018-08-05 19:40:16 +02:00
|
|
|
return 2 * CONSTANT:PI * sqrt(sme^3 / BODY:mu).
|
2018-07-27 21:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function orbital_period_from_ap_pe {
|
2018-08-05 19:40:16 +02:00
|
|
|
parameter ap, pe.
|
|
|
|
return orbital_period(semi_major_axis(ap, pe)).
|
2018-07-27 21:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 17:23:38 +02:00
|
|
|
function orbital_velocity {
|
2018-07-27 21:32:14 +02:00
|
|
|
//
|
|
|
|
// The required velocity to maintain orbit at provided altitude.
|
|
|
|
// Based on:
|
|
|
|
// https://en.wikipedia.org/wiki/Orbital_speed#Precise_orbital_speed
|
|
|
|
// http://www.orbiterwiki.org/wiki/Front_Cover_Equations
|
|
|
|
// https://en.wikipedia.org/wiki/Vis-viva_equation
|
2018-07-27 17:23:38 +02:00
|
|
|
parameter altitude.
|
2018-07-28 00:58:17 +02:00
|
|
|
parameter sma is semi_major_axis().
|
2018-07-27 21:32:14 +02:00
|
|
|
|
2018-08-05 19:40:16 +02:00
|
|
|
return sqrt(BODY:mu * ((2 / (altitude+BODY:radius)) - (1 / sma))). // add body radius because KSP measures altitude from the surface
|
2018-07-27 21:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function orbital_velocity_from_ap_pe {
|
2018-08-05 19:40:16 +02:00
|
|
|
parameter altitude, ap, pe.
|
|
|
|
return orbital_velocity(altitude, semi_major_axis(ap, pe)).
|
2018-07-27 21:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function orbital_eccentricity {
|
|
|
|
//
|
|
|
|
// The orbital eccentricity, i.e. the ratio by which the orbit deviates from a perfect circle, where e=0 is circular.
|
|
|
|
// Based on:
|
|
|
|
// https://en.wikipedia.org/wiki/Orbital_eccentricity#Calculation
|
|
|
|
// http://www.orbiterwiki.org/wiki/Front_Cover_Equations
|
2018-08-05 19:40:16 +02:00
|
|
|
parameter ap is APOAPSIS.
|
|
|
|
parameter pe is PERIAPSIS.
|
2018-07-27 17:23:38 +02:00
|
|
|
|
2018-08-05 19:40:16 +02:00
|
|
|
return (ap - pe) / (ap + pe).
|
2018-07-27 17:23:38 +02:00
|
|
|
}
|