space_is_hard

LAZcalc

Apr 6th, 2015
940
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.99 KB | None | 0 0
  1. //LAUNCH AZIMUTH CALCULATOR
  2. //LAZcalc.ks
  3.  
  4. //To use: RUN LAZcalc.ks([desired circular orbit altitude in kilometers],[desired orbital inclination],[(A)scending or (D)escending node in quotes])
  5. //Example: RUN LAZcalc.ks(240, 51.6, "A").
  6.  
  7. DECLARE PARAMETER desiredAlt.       //Altitude of desired target orbit (circular)
  8. DECLARE PARAMETER desiredInc.       //Inclination of desired target orbit
  9. DECLARE PARAMETER desiredNode.      //Whether to launch on ascending or descending node
  10. DECLARE inertialAzimuth.        //Launch azimuth before taking into account the rotation of the planet
  11. DECLARE launchAzimuth.          //Launch azimuth after taking into account the rotation of the planet
  12.  
  13. DECLARE targetOrbVel.           //Orbital velocity of the desired target orbit
  14. DECLARE targetOrbSMA.           //Semi-major axis of the desired target orbit
  15. DECLARE equatorialVel.          //Velocity of the planet's equator
  16. DECLARE VXRot.
  17. DECLARE VYRot.
  18.  
  19. //Orbital altitude can't be less than sea level
  20. IF desiredAlt <= 0 {
  21.     SET desiredAlt to 100.
  22. }.
  23.  
  24. //Orbital inclination can't be less than launch latitude or greater than 180 - launch latitude
  25. IF desiredInc < ABS(SHIP:LATITUDE) OR desiredInc > (180 - ABS(SHIP:LATITUDE)) {
  26.     SET desiredInc TO ABS(SHIP:LATITUDE).
  27. }.
  28.  
  29. //Corrects invalid node inputs
  30. IF NOT(desiredNode = "A" OR desiredNode = "D") {
  31.     SET desiredNode TO "A".
  32. }.
  33.  
  34. SET desiredAlt TO desiredAlt * 1000.        //Converts to kilometers
  35. SET targetOrbSMA TO desiredAlt + BODY:RADIUS.
  36. SET targetOrbVel TO SQRT(BODY:MU / targetOrbSMA).
  37. SET equatorialVel TO (2 * CONSTANT():PI * BODY:RADIUS) / BODY:ROTATIONPERIOD.
  38. SET inertialAzimuth TO ARCSIN(COS(desiredInc) / COS(ABS(SHIP:LATITUDE))).
  39. SET VXRot TO (targetOrbVel * SIN(inertialAzimuth)) - (equatorialVel * COS(ABS(SHIP:LATITUDE))).
  40. SET VYRot TO targetOrbVel * COS(inertialAzimuth).
  41. SET launchAzimuth TO ARCTAN(VXRot / VYRot).
  42.  
  43. IF desiredNode = "A" {
  44.     PRINT "Launch Azimuth: " + ROUND(launchAzimuth, 2).
  45.    
  46. } ELSE IF desiredNode = "D" {
  47.     PRINT "Launch Azimuth: " + ROUND(180 - launchAzimuth, 2).
  48.    
  49. }.
Advertisement
Add Comment
Please, Sign In to add comment