fork download
  1. // Please enter the mass of the body you are in orbit around (in kilograms x10^20):
  2. double planet_mass = 37770;
  3.  
  4. // Please enter the radius of the body you are in orbit around (in metres):
  5. double planet_radius = 1392609;
  6.  
  7. // Please enter the radius of the sphere of influence of the body that you are
  8. // currently in orbit around (in metres):
  9. double planet_sphere_of_influence = 571407000;
  10.  
  11. // Please enter your current orbital altitude above sea level (in metres):
  12. double current_orbit = 1010000;
  13.  
  14. // Please enter your desired orbital altitude above sea level (in metres):
  15. double final_orbit = 40888000;
  16.  
  17.  
  18.  
  19. #include <math.h>
  20. #include <iostream>
  21. #include <cstdlib>
  22.  
  23. using namespace std;
  24.  
  25. void bi_elliptical_delta_v (double current_orbit, double bi_elliptical_apoapsis, double final_orbit, double standard_gravitational_parameter, double planet_radius)
  26. {
  27. double delta_v_1, delta_v_2, delta_v_3, delta_v_total;
  28. delta_v_1 = sqrt (((2*standard_gravitational_parameter)/current_orbit)-((2*standard_gravitational_parameter)/(current_orbit + bi_elliptical_apoapsis))) - sqrt (standard_gravitational_parameter/current_orbit);
  29. delta_v_2 = sqrt (((2*standard_gravitational_parameter)/bi_elliptical_apoapsis)-((2*standard_gravitational_parameter)/(final_orbit + bi_elliptical_apoapsis))) - sqrt (((2*standard_gravitational_parameter)/bi_elliptical_apoapsis)-((2*standard_gravitational_parameter)/(current_orbit + bi_elliptical_apoapsis)));
  30. delta_v_3 = sqrt (((2*standard_gravitational_parameter)/final_orbit)-((2*standard_gravitational_parameter)/(final_orbit + bi_elliptical_apoapsis))) - sqrt (standard_gravitational_parameter/final_orbit);
  31. delta_v_total = delta_v_1 + delta_v_2 + delta_v_3;
  32. string fore;
  33. if (current_orbit < final_orbit)
  34. {
  35. fore = "prograde";
  36. }
  37. else if (current_orbit > final_orbit)
  38. {
  39. fore = "retrograde";
  40. }
  41. cout << "Bi-elliptcal transfer stats:" << endl << "Bi-elliptical apoapsis: " << bi_elliptical_apoapsis - planet_radius << "m above sea level" << endl << "Burn 1 = " << delta_v_1 << "m/s prograde" << endl << "Burn 2: " << delta_v_2 << "m/s " << fore << endl << "Burn 3 = " << delta_v_3 << "m/s retrograde" << endl << "Total delta v: " << delta_v_total << "m/s" << endl;
  42. }
  43.  
  44. void hohmann_delta_v (double current_orbit, double final_orbit, double standard_gravitational_parameter)
  45. {
  46. double delta_v_1, delta_v_2, delta_v_total;
  47. delta_v_1 = sqrt (((2*standard_gravitational_parameter)/current_orbit)-((2*standard_gravitational_parameter)/(current_orbit + final_orbit))) - sqrt (standard_gravitational_parameter/current_orbit);
  48. delta_v_2 = sqrt (((standard_gravitational_parameter)/final_orbit)) - sqrt (((2*standard_gravitational_parameter)/final_orbit)-((2*standard_gravitational_parameter)/(current_orbit + final_orbit)));
  49. delta_v_total = delta_v_1 + delta_v_2;
  50. string fore;
  51. if (current_orbit < final_orbit)
  52. {
  53. fore = "prograde";
  54. }
  55. else if (current_orbit > final_orbit)
  56. {
  57. fore = "retrograde";
  58. }
  59. cout << "Hohmann transfer stats:" << endl << "Burn 1 = " << delta_v_1 << "m/s " << fore << endl << "Burn 2: " << delta_v_2 << "m/s " << fore << endl << "Total delta v: " << delta_v_total << "m/s" << endl;
  60. }
  61.  
  62. int main ()
  63. {
  64. double mass_multiplier = 100000000000000000000.0;
  65. planet_mass *= mass_multiplier;
  66. double standard_gravitational_parameter = planet_mass*0.0000000000667;
  67.  
  68. current_orbit += planet_radius;
  69.  
  70. final_orbit += planet_radius;
  71.  
  72. double bi_elliptical_apoapsis = (0.9*(planet_sphere_of_influence - final_orbit)) + final_orbit;
  73. hohmann_delta_v (current_orbit, final_orbit, standard_gravitational_parameter);
  74. cout << endl;
  75. bi_elliptical_delta_v (current_orbit, bi_elliptical_apoapsis, final_orbit, standard_gravitational_parameter, planet_radius);
  76. cout << endl;
  77. system ("PAUSE");
  78. return 0;
  79. }
Success #stdin #stdout #stderr 0.01s 5292KB
stdin
Standard input is empty
stdout
Hohmann transfer stats:
Burn 1 = 3846.79m/s prograde
Burn 2: 1640.51m/s prograde
Total delta v: 5487.3m/s

Bi-elliptcal transfer stats:
Bi-elliptical apoapsis: 5.17102e+08m above sea level
Burn 1 = 4208.06m/s prograde
Burn 2: 203.731m/s prograde
Burn 3 = 878.403m/s retrograde
Total delta v: 5290.19m/s

stderr
sh: 1: PAUSE: not found