Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //LAUNCH AZIMUTH CALCULATOR
- //LAZcalc.ks
- //To use: RUN LAZcalc.ks([desired circular orbit altitude in kilometers],[desired orbital inclination],[(A)scending or (D)escending node in quotes])
- //Example: RUN LAZcalc.ks(240, 51.6, "A").
- DECLARE PARAMETER desiredAlt. //Altitude of desired target orbit (circular)
- DECLARE PARAMETER desiredInc. //Inclination of desired target orbit
- DECLARE PARAMETER desiredNode. //Whether to launch on ascending or descending node
- DECLARE inertialAzimuth. //Launch azimuth before taking into account the rotation of the planet
- DECLARE launchAzimuth. //Launch azimuth after taking into account the rotation of the planet
- DECLARE targetOrbVel. //Orbital velocity of the desired target orbit
- DECLARE targetOrbSMA. //Semi-major axis of the desired target orbit
- DECLARE equatorialVel. //Velocity of the planet's equator
- DECLARE VXRot.
- DECLARE VYRot.
- //Orbital altitude can't be less than sea level
- IF desiredAlt <= 0 {
- SET desiredAlt to 100.
- }.
- //Orbital inclination can't be less than launch latitude or greater than 180 - launch latitude
- IF desiredInc < ABS(SHIP:LATITUDE) OR desiredInc > (180 - ABS(SHIP:LATITUDE)) {
- SET desiredInc TO ABS(SHIP:LATITUDE).
- }.
- //Corrects invalid node inputs
- IF NOT(desiredNode = "A" OR desiredNode = "D") {
- SET desiredNode TO "A".
- }.
- SET desiredAlt TO desiredAlt * 1000. //Converts to kilometers
- SET targetOrbSMA TO desiredAlt + BODY:RADIUS.
- SET targetOrbVel TO SQRT(BODY:MU / targetOrbSMA).
- SET equatorialVel TO (2 * CONSTANT():PI * BODY:RADIUS) / BODY:ROTATIONPERIOD.
- SET inertialAzimuth TO ARCSIN(COS(desiredInc) / COS(ABS(SHIP:LATITUDE))).
- SET VXRot TO (targetOrbVel * SIN(inertialAzimuth)) - (equatorialVel * COS(ABS(SHIP:LATITUDE))).
- SET VYRot TO targetOrbVel * COS(inertialAzimuth).
- SET launchAzimuth TO ARCTAN(VXRot / VYRot).
- IF desiredNode = "A" {
- PRINT "Launch Azimuth: " + ROUND(launchAzimuth, 2).
- } ELSE IF desiredNode = "D" {
- PRINT "Launch Azimuth: " + ROUND(180 - launchAzimuth, 2).
- }.
Advertisement
Add Comment
Please, Sign In to add comment