// File: functions.cxx 01/26/2010 // Written by: Byron Samaripa // This program is used to derive various numbers related to Kepler's Solution. //----------------------------------------------------------------------------- // Directives: #include #include using namespace std; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // Constants: const double EPSILON = 0.001; const double PI = 3.14159265; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // Function Prototypes double kepler_solution(double ma, double ecc); double orbit_angle(double ecc, double period, double t); double orbit_dist(double a, double ecc, double theta); int pixel(double v, double v0, double v1, int pmax); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // Main Function: int main() { double x, y, z = 0; int p = 0; cout << "Please type ma and ecc for testing kepler_solution: "; cin >> x >> y; cout << "kepler_solution is " << kepler_solution(x, y) << endl; cout << "Please type ecc, period and t for testing orbit_angle: "; cin >> x >> y >> z; cout << "orbit_angle is " << orbit_angle(x, y, z) << endl; cout << "Please type a, ecc and theta for testing orbit_dist: "; cin >> x >> y >> z; cout << "orbit_distance is " << orbit_dist(x, y, z) << endl; cout << "Please type v, v0, v1 and pmax for testing pixel: "; cin >> x >> y >> z >> p; cout << "pixel is " << pixel(x, y, z, p) << endl; cout << "Thank you, Mr. Kepler" << endl; return EXIT_SUCCESS; } //----------------------------------------------------------------------------- //---------------------------------------------------------------------------- double kepler_solution(double ma, double ecc) { double x; double error; x = 0; error = abs( x - (ma + ecc*sin(x)) ); while (error >= EPSILON) { x = ma + ecc*sin(x); error = abs( x - (ma + ecc*sin(x)) ); } return x; } //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- double orbit_angle(double ecc, double period, double t) { double ma = 0; double x = 0; ma = (2*PI*t) / period; x = kepler_solution(ma, ecc); cout << x << endl; return 2*atan(sqrt((1 + ecc)/(1 - ecc))*tan(x/2)); } //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- double orbit_dist(double a, double ecc, double theta) { double distance = 0; distance = (a*(1-ecc*ecc)) / (1+ecc*cos(theta)); return distance; } //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- // I could not figure out what the problem was asking me to do in this function int pixel(double v, double v0, double v1, int pmax) { double b =0; b = (v-v0)*(double)pmax / (v1-v0); cout << b << endl; return (int)b; } //----------------------------------------------------------------------------