I'm doing a combined math and c++ lesson just for the sake of being bored and wanting to be better at both. This is mainly for use with orbiter which lead to a slight headache due to my numbers being different than orbiters and after cross checking every value and dividing by zero I'm scared to go to the bathroom, but I'm rather happy with the results.
The thing I'm wondering is what to do next... I could somewhat easily make it work with all the planets or at least few of those and I could change the way this calculates the orbital speed into kepler's third law which would allow elliptical orbits as well.
Or I could just say I've accomplished my mission and move on to something different like a rocket equation or something. (The actual goal here was to just make a program to calculate the crude azimuth, but that proved to be a bit too simple.)
So feedback, ideas, corrections about the math or the code are all welcome.
Code:
#include <iostream>
using namespace std;
int main() {
//Declaring constants
const double Pi = 4.0*atan(1.0);
const double GravitationalConstant = 6.6730 * pow(10.0, -11.0); // Universal Gravitational constant
const double EarthMass = 5.9736 * pow(10.0, 24.0); // mass of earth in kg
const double EarthRadius = 6371;//165 ; // Earth radius in m
const double EquatorialVelocity = 40075160 / 86164.10132; // Circumference of equator (in meters) divided by sidereal day of earth (in seconds)
//Declaring variables
double CurrentLatitude;
double CurrentVelocity;
double OrbitalVelocity;
double Vxrot;
double Vyrot;
double RotationalAzimuth;
//Ask these from the user
double DesiredAltitude;
double LaunchLatitude;
double DesiredInclination;
//coutcin
cout << "Insert desired orbital inclination: ";
cin >> DesiredInclination;
cout << "Insert launch latitude: ";
cin >> LaunchLatitude;
cout << "Insert orbital altitude in km: ";
cin >> DesiredAltitude;
//Crude azimuth math
double CrudeLaunchAzimuth = asin(cos(DesiredInclination * (Pi / 180)) / cos(LaunchLatitude * (Pi / 180))) * ( 180 / Pi );
DesiredAltitude = 1000* (EarthRadius + DesiredAltitude) ; // converting tha altitude from the center of the world to orbit into meters.
CurrentLatitude = LaunchLatitude * (Pi / 180); // CurrentLatitude is LaunchLatitude in radians.
CurrentVelocity = cos(CurrentLatitude) * EquatorialVelocity; // cosine of launch latitude times the equatorial surface velocity
OrbitalVelocity = sqrt(GravitationalConstant * (EarthMass / DesiredAltitude));
//Calculating Rotational Azimuth
Vxrot = OrbitalVelocity * (sin(DesiredInclination * (Pi / 180))) - EquatorialVelocity * (cos(LaunchLatitude * (Pi / 180)));
Vyrot = OrbitalVelocity * (cos(DesiredInclination * (Pi / 180)));
RotationalAzimuth = atan(Vxrot / Vyrot);
RotationalAzimuth = RotationalAzimuth * (180 / Pi);
cout << "Launch heading is ";
cout << RotationalAzimuth ;
cout << " North-east or South-east at heading ";
cout << 180 - RotationalAzimuth ;
cout << "\n\n\t";
cout << "OrbitalVelocity\t\t" << OrbitalVelocity << " m/s \n\t";
cout << "SurfaceVelocity\t\t" << CurrentVelocity << " m/s \n\t";
cout << "Crude Azimuth\t\t" << CrudeLaunchAzimuth << " or " << 180 - CrudeLaunchAzimuth << "\n\t" ;
cout << "Required Delta_V\t" << OrbitalVelocity - CurrentVelocity;
cin >> RotationalAzimuth;
cin.get();
}
The thing I'm wondering is what to do next... I could somewhat easily make it work with all the planets or at least few of those and I could change the way this calculates the orbital speed into kepler's third law which would allow elliptical orbits as well.
Or I could just say I've accomplished my mission and move on to something different like a rocket equation or something. (The actual goal here was to just make a program to calculate the crude azimuth, but that proved to be a bit too simple.)
So feedback, ideas, corrections about the math or the code are all welcome.