Advertisement
Guest User

lib_physics.ks

a guest
Apr 17th, 2015
971
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. // A library of routines to help do basic physics calculations
  2.  
  3. @LAZYGLOBAL off.
  4.  
  5. // Return the gravity acceleration at SHIP's current location.
  6. declare function g_here {
  7. return constant():G * ((ship:body:mass)/((ship:altitude + body:radius)^2)).
  8. }.
  9.  
  10. // Return the force on SHIP due to gravity acceleration at SHIP's current location.
  11. declare function Fg_here {
  12. return ship:mass*g_here().
  13. }.
  14.  
  15. declare function mu_body {
  16. return constant():G * (body:mass)
  17. }.
  18.  
  19. declare function mu_ship {
  20. return constant():G * (ship:mass)
  21. }.
  22. //added by capt-crash
  23. declare function v_e { //escape velocity calculation
  24. return sqrt((2 * body:mu)/((ship:altitude + body:radius)))
  25. }.
  26.  
  27. declare function stage_delta_v {
  28. return stage:engine:isp * ln(ship:mass / (ship:mass - (stage:LQDOXYGEN + stage:LQDHYDROGEN + stage:KEROSENE + stage:Aerozine50 + stage:UDMH + stage:NTO + stage:MMH + stage:HTP + stage:IRFNA-III + stage:NitrousOxide + stage:Aniline + stage:Ethanol75 + stage:LQDAMMONIA + stage:LQDMETHANE + stage:CLF3 + stage:CLF5 + stage:DIBORANE + stage:PENTABORANE + stage:ETHANE + stage:ETHYLENE + stage:OF2 + stage:LQDFLUORINE + stage:N2F4 + stage:FurFuryl + stage:UH25 + stage:TONKA250 + stage:TONKA500 + stage:FLOX30 + stage:FLOX70 + stage: + stage:FLOX88 + stage:IWFNA + stage:IRFNA-IV + stage:AK20 + stage:AK27 + stage:CaveaB + stage:MON1 + stage:MON3 + stage:MON10 + stage:MON15 + stage:MON20 + stage:Hydyne + stage:TEATEB)))
  29. }. //for real fuels
  30.  
  31. //declare function stage_delta_v {
  32. // return stage:engine:isp * ln(ship:mass / (ship:mass - (stage:LIQUIDFUEL)))
  33. //}.
  34.  
  35. //uncomment the above if using stock fuels
  36.  
  37. declare function hohmann {
  38. //r1 and a2 will be set manually before launch or in flight via relay
  39. declare parameter
  40. v1, //initial orbital velocity
  41. v1_t, //elliptical orbit transfer r1->2
  42. v2, //orbital velocity in desired orbit
  43. v2_t, //circularizat
  44. r1, //inital radius
  45. a2, //desired orbital altitude, converted to r2 as needed. makes user input simple
  46. a_t,
  47. r2.
  48. set a_t to ( r1 + r2 ) / 2
  49. set r1 to ( ( orbit:apoapsis + orbit:periapsis ) / 2 ) + body:radius.
  50. set r2 to a2 + body:radius.
  51. set v1 to sqrt( body:mu / r1 ).
  52. set v2 to sqrt( body:mu / r2 ).
  53. set v1_t to sqrt( body:mu * ( ( 2 / r1 ) - ( 1 / ( a_t ) ) ) ) - sqrt( v1 ).
  54. set v2_t to sqrt( v2 ) - sqrt( body:mu * ( ( 2 / r2 ) - ( 1 / ( a_t ) ) ) ).
  55. return v1_t + v2_t
  56. }.
  57. //end capt-crash
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement