Advertisement
space_is_hard

LIB_LAZcalc.ks

Apr 10th, 2015
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.37 KB | None | 0 0
  1. //=====LAUNCH AZIMUTH CALCULATOR=====
  2. //~~LIB_LAZcalc.ks~~
  3. //~~Version 0.9b~~
  4.  
  5. //To use: RUN LAZcalc.ks([desired circular orbit altitude in kilometers],[desired orbital inclination],[(A)scending or (D)escending node in quotes])
  6. //Example: RUN LAZcalc.ks(240, 51.6, "A").
  7.  
  8. @LAZYGLOBAL OFF.
  9.  
  10. DECLARE FUNCTION LAZcalc {
  11.  
  12.     //#open Variable Declaration
  13.    
  14.     DECLARE PARAMETER desiredAlt.       //Altitude of desired target orbit (circular)
  15.     DECLARE PARAMETER desiredInc.       //Inclination of desired target orbit
  16.     DECLARE PARAMETER launchNode.       //Whether to launch on ascending or descending node
  17.  
  18.     DECLARE inertialAzimuth.        //Launch azimuth before taking into account the rotation of the planet
  19.     DECLARE launchAzimuth.          //Launch azimuth after taking into account the rotation of the planet
  20.     DECLARE targetOrbVel.           //Orbital velocity of the desired target orbit
  21.     DECLARE targetOrbSMA.           //Semi-major axis of the desired target orbit
  22.     DECLARE equatorialVel.          //Velocity of the planet's equator
  23.     DECLARE VXRot.
  24.     DECLARE VYRot.
  25.  
  26.     //#close Variable Declaration
  27.  
  28.     //#open Input Sterilization
  29.  
  30.     //Orbital altitude can't be less than sea level
  31.     IF desiredAlt <= 0 {
  32.         SET desiredAlt to 100.
  33.     }.
  34.  
  35.     //Orbital inclination can't be less than launch latitude or greater than 180
  36.     IF desiredInc < ABS(SHIP:LATITUDE) OR desiredInc > (180 - SHIP:LATITUDE) {
  37.         SET desiredInc TO SHIP:LATITUDE.
  38.     }.
  39.  
  40.     //Corrects invalid node inputs
  41.     IF NOT(launchNode = "A" OR launchNode = "D") {
  42.         SET launchNode TO "A".
  43.     }.
  44.  
  45.     //#close Input Sterilization
  46.  
  47.     //#open Calculations
  48.  
  49.     SET desiredAlt TO desiredAlt * 1000.        //Converts to kilometers
  50.     SET targetOrbSMA TO desiredAlt + BODY:RADIUS.
  51.     SET targetOrbVel TO SQRT(BODY:MU / (targetOrbSMA)).
  52.     SET equatorialVel TO (2 * CONSTANT():PI * BODY:RADIUS) / BODY:ROTATIONPERIOD.
  53.     SET inertialAzimuth TO ARCSIN(COS(desiredInc) / COS(SHIP:LATITUDE)).
  54.     SET VXRot TO (targetOrbVel * SIN(inertialAzimuth)) - (equatorialVel * COS(SHIP:LATITUDE)).
  55.     SET VYRot TO (targetOrbVel * COS(inertialAzimuth)).
  56.     SET launchAzimuth TO ARCTAN(VXRot / VYRot).
  57.  
  58.     //#close Calculations
  59.  
  60.     //#open Output
  61.  
  62.     IF launchNode = "A" {
  63.         PRINT "Launch Azimuth: " + ROUND(launchAzimuth, 2) + " degrees".
  64.        
  65.     } ELSE IF launchNode = "D" {
  66.         PRINT "Launch Azimuth: " + ROUND(90 + (90 - launchAzimuth), 2) + " degrees".
  67.        
  68.     }.
  69.    
  70.     RETURN launchAzimuth.
  71.  
  72.     //#close Output
  73.  
  74. }. //FUNCTION LAZcalc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement