@LAZYGLOBAL OFF. 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 // parameter ap is APOAPSIS. parameter pe is PERIAPSIS. return (ap + pe + 2*BODY:radius) / 2. // Add 2x body radius because KSP measures apoapsis/periapsis from the surface } 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 // parameter sme is semi_major_axis(). return 2 * CONSTANT:PI * sqrt(sme^3 / BODY:mu). } function orbital_period_from_ap_pe { parameter ap, pe. return orbital_period(semi_major_axis(ap, pe)). } function orbital_velocity { // // 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 parameter altitude. parameter sma is semi_major_axis(). return sqrt(BODY:mu * ((2 / (altitude+BODY:radius)) - (1 / sma))). // add body radius because KSP measures altitude from the surface } function orbital_velocity_from_ap_pe { parameter altitude, ap, pe. return orbital_velocity(altitude, semi_major_axis(ap, pe)). } function orbital_velocity_circular { parameter altitude. return orbital_velocity_from_ap_pe(altitude, altitude, altitude). } 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 parameter ap is APOAPSIS. parameter pe is PERIAPSIS. return (ap - pe) / (ap + pe). }