Programming Question Launch Azimuth program

Sar

New member
Joined
Oct 31, 2009
Messages
109
Reaction score
0
Points
0
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.

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.
 
A related astrodynamics problem that hasn't been yet put into an add-on: where will a given multistage rocket be (in planeto-centric frame) at MECO given launch site, time, pitch profile, azimouth and (possibly) initial roll maneuver?
 
So practically where in long/lat the ship is at MECO?

I think I managed to wrap my head around it enough to know how insanely hard that would be to code. Even if I'd go with simple way and assume constant acceleration, single stage and a quarter of a circle as a pitch curve.

I might actually manage to do something that would tell me how fast at a given time a rocket is going. After that stuffing the pitch profile somewhere and calculating the horizontal velocity with the vertical one and figuring out how to change the long/lat values according to the launch azimuth.

The amount of values that'd need to be put in by the person using it would be potentially enormous. (The pitch values and possibly acceleration at a given time unless assuming constant acceleration in both stages)
 
I'm looking into it (with the atmospheric complications) :) You can have a glimpse of various simulations like that here: http://www.aiaa.org/content.cfm?pageid=403&ID=1592

Off the top of my head, there is simpler stuff - e.g. the same problem, but now with a single-stage vehicle starting from a body without atmosphere. It may get you going. And, you could also read the source code in KOST and AeroBrake MFD (all downloadable through Orbit Hangar), it's pretty well documented.
 
Back
Top