Advertisement
Guest User

KOS polar launch utility

a guest
Sep 4th, 2015
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. //launch_util.ks
  2. //code by "space_is_hard" used as a reference
  3.  
  4. //utility functions for the launch script
  5.  
  6. @LAZYGLOBAL off.
  7.  
  8. //adjust inclination
  9. //returns a heading angle that should
  10. FUNCTION initAzimuth
  11. {
  12. PARAMETER
  13. targetAp,
  14. targetPe,
  15. targetInc.
  16.  
  17. LOCAL azimuthData to LIST().
  18. LOCAL targetAlt to ((targetAp+targetPe)/2).
  19.  
  20. //Step 1: Calculate Orbital Velocity at target altitude
  21. LOCAL targetOrbVel to (SQRT(BODY:MU/(BODY:RADIUS + targetAlt))).
  22. //Step 2: Get X and Y components of target orbital velocity
  23. LOCAL targetXVel to (targetOrbVel * COS(targetInc)).
  24. LOCAL targetYVel to (targetOrbVel * SIN(targetInc)).
  25.  
  26. //Put it in a data structure for real time computing
  27. azimuthData:ADD(targetXVel). //[0]
  28. azimuthData:ADD(targetYVel). //[1]
  29.  
  30. RETURN azimuthData.
  31. }
  32. FUNCTION getAzimuth
  33. {
  34. PARAMETER
  35. azimuthData.
  36.  
  37. LOCAL shipInc to SHIP:OBT:INCLINATION.
  38. //Step 3: Calculate horizontal ship velocity
  39. LOCAL shipVel to (SHIP:VELOCITY:ORBIT:MAG - ABS(SHIP:VERTICALSPEED)).
  40. //Step 4: Get X and Y components of horizontal ship velocity.
  41. LOCAL shipXVel to (shipVel * COS(shipInc)).
  42. LOCAL shipYVel to (shipVel * SIN(shipInc)).
  43. //Step 5: Calculate required azimuth vector from combining both velocities.
  44. LOCAL AzimuthX to (azimuthData[0]-shipXVel).
  45. LOCAL AzimuthY to (azimuthData[1]-shipYVel).
  46. //Step 6: Calculating resulting Azimuth to target from this vector.
  47. Local azimuth to ARCTAN2(AzimuthX, AzimuthY).
  48.  
  49. RETURN MOD(azimuth+360, 360).
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement