Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=====LAUNCH AZIMUTH CALCULATOR=====
- //~~LIB_LAZcalc.ks~~
- //~~Version 0.9b~~
- //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").
- @LAZYGLOBAL OFF.
- DECLARE FUNCTION LAZcalc {
- //#open Variable Declaration
- DECLARE PARAMETER desiredAlt. //Altitude of desired target orbit (circular)
- DECLARE PARAMETER desiredInc. //Inclination of desired target orbit
- DECLARE PARAMETER launchNode. //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.
- //#close Variable Declaration
- //#open Input Sterilization
- //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
- IF desiredInc < ABS(SHIP:LATITUDE) OR desiredInc > (180 - SHIP:LATITUDE) {
- SET desiredInc TO SHIP:LATITUDE.
- }.
- //Corrects invalid node inputs
- IF NOT(launchNode = "A" OR launchNode = "D") {
- SET launchNode TO "A".
- }.
- //#close Input Sterilization
- //#open Calculations
- 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(SHIP:LATITUDE)).
- SET VXRot TO (targetOrbVel * SIN(inertialAzimuth)) - (equatorialVel * COS(SHIP:LATITUDE)).
- SET VYRot TO (targetOrbVel * COS(inertialAzimuth)).
- SET launchAzimuth TO ARCTAN(VXRot / VYRot).
- //#close Calculations
- //#open Output
- IF launchNode = "A" {
- PRINT "Launch Azimuth: " + ROUND(launchAzimuth, 2) + " degrees".
- } ELSE IF launchNode = "D" {
- PRINT "Launch Azimuth: " + ROUND(90 + (90 - launchAzimuth), 2) + " degrees".
- }.
- RETURN launchAzimuth.
- //#close Output
- }. //FUNCTION LAZcalc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement