Difference between revisions of "User:TomPN"
From Kerbal Space Program Wiki
(Created page with "Hi! I'm TomPN, and I'm an avid fan of Kerbal Space Program. thumbnail|Orbital calculator") |
|||
Line 1: | Line 1: | ||
− | Hi! I'm TomPN, and I'm an avid fan of Kerbal Space Program. | + | Hi! I'm TomPN, and I'm an avid fan of Kerbal Space Program. I'd like to upload my program for calculating whether you should use a Hohmann transfer or a Bi-elliptical transfer, but it's an exe so I can't. I can post the source code, however, so here goes: |
− | + | ||
+ | #include <math.h> | ||
+ | #include <iostream> | ||
+ | #include <cstdlib> | ||
+ | |||
+ | using namespace std; | ||
+ | |||
+ | double delta_v (double mass, double radius_1, double radius_2, double radius_3) | ||
+ | { | ||
+ | double gravity_constant = 0.0000000000667; | ||
+ | double mu = gravity_constant*mass; | ||
+ | double a_1 = (radius_1 + radius_2)/2; | ||
+ | double a_2 = (radius_2 + radius_3)/2; | ||
+ | double delta_v = sqrt(((2*mu)/radius_1)-(mu/a_1))-sqrt(mu/radius_1)+sqrt(((2*mu)/radius_2)-(mu/a_2))-sqrt(((2*mu)/radius_2)-(mu/a_1))+sqrt(((2*mu)/radius_3)-(mu/a_2))-sqrt(mu/radius_3); | ||
+ | return delta_v; | ||
+ | } | ||
+ | |||
+ | int main () | ||
+ | { | ||
+ | cout << "Orbital transfer calculator v1.1\nWritten by TomPN\n15/12/2015\n" << endl; | ||
+ | double planet_mass; | ||
+ | cout << "Please enter the mass of the body you are in orbit around (in kilograms x10^20): "; | ||
+ | cin >> planet_mass; | ||
+ | double mass_multiplier = 100000000000000000000.0; | ||
+ | planet_mass *= mass_multiplier; | ||
+ | double current_orbit; | ||
+ | cout << "Please enter your current orbital radius (in metres): "; | ||
+ | cin >> current_orbit; | ||
+ | double final_orbit; | ||
+ | cout << "Please enter your desired orbital radius (in metres): "; | ||
+ | cin >> final_orbit; | ||
+ | double sphere_of_influence; | ||
+ | cout << "Please enter the radius of the sphere of influence of the body that you are\n currently in orbit around (in metres): "; | ||
+ | cin >> sphere_of_influence; | ||
+ | double percentage = 0.9; | ||
+ | double bi_elliptical_apoapsis = percentage*sphere_of_influence; | ||
+ | double hohmann_delta_v; | ||
+ | double bi_elliptical_delta_v; | ||
+ | if (current_orbit < final_orbit) | ||
+ | { | ||
+ | hohmann_delta_v = delta_v (planet_mass, current_orbit, final_orbit, final_orbit); | ||
+ | bi_elliptical_delta_v = delta_v (planet_mass, current_orbit, bi_elliptical_apoapsis, final_orbit); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | hohmann_delta_v = delta_v (planet_mass, final_orbit, current_orbit, current_orbit); | ||
+ | bi_elliptical_delta_v = delta_v (planet_mass, final_orbit, bi_elliptical_apoapsis, current_orbit); | ||
+ | } | ||
+ | if (hohmann_delta_v > bi_elliptical_delta_v) | ||
+ | { | ||
+ | cout << "Perform a bi-elliptical transfer with an apoapsis between "<<bi_elliptical_apoapsis<<" and "<<sphere_of_influence<<" metres."<<endl; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | cout << "Perform a Hohmann transfer." << endl; | ||
+ | } | ||
+ | system ("PAUSE"); | ||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | You'll need a C++ emulator (can be found online) or compiler (can be downloaded) to run the code. |
Revision as of 21:42, 15 December 2015
Hi! I'm TomPN, and I'm an avid fan of Kerbal Space Program. I'd like to upload my program for calculating whether you should use a Hohmann transfer or a Bi-elliptical transfer, but it's an exe so I can't. I can post the source code, however, so here goes:
#include <math.h> #include <iostream> #include <cstdlib> using namespace std; double delta_v (double mass, double radius_1, double radius_2, double radius_3) { double gravity_constant = 0.0000000000667; double mu = gravity_constant*mass; double a_1 = (radius_1 + radius_2)/2; double a_2 = (radius_2 + radius_3)/2; double delta_v = sqrt(((2*mu)/radius_1)-(mu/a_1))-sqrt(mu/radius_1)+sqrt(((2*mu)/radius_2)-(mu/a_2))-sqrt(((2*mu)/radius_2)-(mu/a_1))+sqrt(((2*mu)/radius_3)-(mu/a_2))-sqrt(mu/radius_3); return delta_v; } int main () { cout << "Orbital transfer calculator v1.1\nWritten by TomPN\n15/12/2015\n" << endl; double planet_mass; cout << "Please enter the mass of the body you are in orbit around (in kilograms x10^20): "; cin >> planet_mass; double mass_multiplier = 100000000000000000000.0; planet_mass *= mass_multiplier; double current_orbit; cout << "Please enter your current orbital radius (in metres): "; cin >> current_orbit; double final_orbit; cout << "Please enter your desired orbital radius (in metres): "; cin >> final_orbit; double sphere_of_influence; cout << "Please enter the radius of the sphere of influence of the body that you are\n currently in orbit around (in metres): "; cin >> sphere_of_influence; double percentage = 0.9; double bi_elliptical_apoapsis = percentage*sphere_of_influence; double hohmann_delta_v; double bi_elliptical_delta_v; if (current_orbit < final_orbit) { hohmann_delta_v = delta_v (planet_mass, current_orbit, final_orbit, final_orbit); bi_elliptical_delta_v = delta_v (planet_mass, current_orbit, bi_elliptical_apoapsis, final_orbit); } else { hohmann_delta_v = delta_v (planet_mass, final_orbit, current_orbit, current_orbit); bi_elliptical_delta_v = delta_v (planet_mass, final_orbit, bi_elliptical_apoapsis, current_orbit); } if (hohmann_delta_v > bi_elliptical_delta_v) { cout << "Perform a bi-elliptical transfer with an apoapsis between "<<bi_elliptical_apoapsis<<" and "<<sphere_of_influence<<" metres."<<endl; } else { cout << "Perform a Hohmann transfer." << endl; } system ("PAUSE"); return 0; }
You'll need a C++ emulator (can be found online) or compiler (can be downloaded) to run the code.