Commit 0865371a by Brandon Reid

autosave

parent 8325f152
 #include "Algorithm.h" #include #include #include #include #include const bool DEBUG = true; //the main algorithm function converts using namespace std; //const int COl_MAX = 24; //const int ROW_MAX = 180; //converts horizontal coordinates to cartesian coordinates in xyz where alt is the altitude angle and azi is Azimuth angle void horizontalToCart(double alt, double azi, double &x, double &y, double &z){ //convertion of Horizontal coordinates to cartesian coordinates alt = alt * (M_PI / 180); azi = azi * (M_PI / 180); z = sin(alt); x = cos(alt) * cos(azi); y = -1 * cos(alt) * sin(azi); } //converts the latitude to theta double latToTheta(double lat){ double theta; //loat L = lat * (M_PI / 180); theta = (90 - lat); return theta; } //converts the time to phi double timeToPhi(int year, double hours, double longitude){ float phi; float date = GMST(year, hours); //converts the longitude into radians float lam = longitude * (M_PI / 180); //calculates phi; phi = date * ((2 * M_PI) / 24) - lam; return phi; } //convert the date to a julian date; double julian(double year, double hours){ double leap = 0; double notLeap, dayFract, dayWhole; double julian, years, days, seconds, hoursLeft; years = year + 4712;//years is current year (AD or CE) 4713 is the start of the julian calender 1 is 0 AD/CE if(DEBUG){ clog << "DEBUG: years has a value of: " << years << endl; } for(int i = -4713; i <= year; i++){ //counts number of leap years if(i < 1582){//before the switch to gregorian calenders, leap years were every 4 years if(i % 4 == 0){ leap++; /* if(DEBUG){ clog <<"DEBUG: " << i << " is a leap year." << endl; } */ } }else{ //after the switch the gregorian calenders, leap years weren't counted on centries unless it was divisible by 0 if(i % 4 == 0){ if(i % 100 == 0){ if(DEBUG){ clog << "DEBUG: The year is " << i; } if(i % 400 == 0){ leap++; if(DEBUG){ clog << ", and its a leap year." << endl; } } else { if(DEBUG){ clog << endl; } } } else { leap++; /* if(DEBUG){ clog << "DEBUG: " << i << " is a leap year." << endl; } */ } } } } notLeap = years - leap; if(DEBUG){ clog << "DEBUG: There are " << leap << " leap years and " << notLeap << " non leap years totalling " << leap + notLeap << " years." << endl; } days = (leap * 366) + (notLeap * 365) - 10; if(DEBUG){ clog << "DEBUG: days of leap years is: " << leap * 366 << ". Days of non leap years is: " << notLeap * 365 <<"." << endl << "DEBUG: The current value of Days is: " << days << endl; } dayFract = modf((hours / 24), &dayWhole); if(DEBUG){ clog << "DEBUG: The value of dayFract is: " << dayFract << " and the value of dayWhole is: " << dayWhole << endl; } days += dayWhole; hoursLeft = dayFract * 24;//counts the left over hours that aren't days /*if(hoursLeft != 0){ if(hoursLeft >= 12) { //turns the left over hours into seconds since noon (12pm) seconds = (hoursLeft - 12) * 360; } else { seconds = (hoursLeft + 12) * 360; } } else { //seconds = 43200; }*/ if(DEBUG){ clog < JD0){ hoursLeft = (JD - JD0) *24; } else { hoursLeft = (JD0 - JD) *24; }*/ if(DEBUG){ clog << fixed << setprecision(10) << "DEBUG: The GMST in days is: " << D << endl << "DEBUG: The value of JD is: " << JD << endl << "DEBUG: The value of JD0 is: " << JD0 << " and the value of D0 " << D0 << endl; } temp = 6.697374558 + (0.06570982441908*D0) + (1.00273790935*hoursLeft) + (0.000026 * pow(T, 2)); //temp = if(DEBUG){ clog << fixed << "DEBUG: D has a value of: " << D << endl << "DEBUG: temp has a value of: " << temp << endl << "DEBUG: hours left has a value of: " << hoursLeft << endl; } GMST = fmod(temp, 24) ; if(DEBUG){ clog << "DEBUG: GMST has a value of: " << GMST << endl; } return GMST; } //converts geographic coordinates to celestial coooriantes (right ascention and deckination) and retruns a deque with the names of all the constellations //latAndLongpair has lat as the first and long as the second //alt and azi pair has altitude as the first and azimuth as the second pair algorithm(double hours, pair latAndLongPair, pair altAndAziPair, int year){ //declaraton of variables pair raAndDecPair; double phi = latAndLongPair.first * (M_PI / 180); double hourAngle; double alpha, sigma, temp; double a = altAndAziPair.first * (M_PI / 180); // altitude double A = altAndAziPair.second * (M_PI / 180); // azimuth double lat = latAndLongPair.first; // latitude double Long = latAndLongPair.second * (M_PI / 180); // longitude double hoursLeft = modf((hours/24), &temp) * 24; double Time = (GMST(year, hours) * 15) * (M_PI / 180); temp = ((sin(a)*sin(phi)) + (cos(a) * cos(phi) * cos(A))); sigma = asin(temp); hourAngle = -1 * (sin(A) * cos(a)) / cos(sigma); //hourAngle = (sin(a) - (sin(sigma)*sin(phi))) / (cos(sigma) * cos(phi)); alpha = (Time - Long) - asin(hourAngle); if(DEBUG){ clog << fixed << setprecision(10) << "DEBUG: hourAngle has a value of: " << hourAngle << endl << "DEBUG: temp has a value of: " << temp << " and the arcsine of temp is: " << asin(temp) << endl << "DEBUG: sigma then has a value of: " << sigma * (180 / M_PI) << endl << "DEBUG: alpha has a value of: " << alpha << " which means that the LST is: " << (Time - Long) * (180 / M_PI) << " and the hour angle is " << hourAngle << " and the arccos of the hour angle is: " << asin(hourAngle) * (180 / M_PI) << endl; //clog << "DEBUG: alpha has a value of: " << alpha << " and sigma has a value of: " << sigma * (180 / M_PI)<< endl; } raAndDecPair.first = (alpha * (180 / M_PI)) / 15; raAndDecPair.second = sigma * (180 / M_PI); if(DEBUG){ clog << "DEBUG: The final point is: (" << raAndDecPair.first << "," << raAndDecPair.second << ")." << endl; } return raAndDecPair; }
This diff is collapsed.
 #include #include using namespace std; int yearPrompt (); // Prompts and checks year input string monthPrompt (); // Prompts and checks month input int dayPrompt (string month, int year); // Prompts and checks day input int hourPrompt (); // Prompts and checks hour input int minutePrompt (); // Prompts and checks minute input double dateToHour (string month, int year, int day, int hour, int minute); // Converts full date to hour pair altAndAziPair (); // Creates pair of alitutude and azimuth bool isLeap (int year); // Bool check for leap year vector > viewFinder (pair centerPt); // function that returns the coordinates of the viewing window vector > constellationCoordinates (); // function that stores the coordinates of all the constellations void printConstellation (vector > constellationCoordinates, vector > window); // function to print the constellations string constellationNamer (int index); // funciton to name all the constellations void constellationOutputter (int index); // function to output the images of the constellations bool restart(); // function to ask for restart options \ No newline at end of file
 ... ... @@ -542,6 +542,60 @@ vector > constellationCoordinates () { // Function to store coordinates.push_back(make_pair(8.6, 61.0)); coordinates.push_back(make_pair(13.7, 32.0)); coordinates.push_back(make_pair(8.6, 32.0)); //Hercules coordinates.push_back(make_pair(18.1, 57.0)); coordinates.push_back(make_pair(16.0, 57.0)); coordinates.push_back(make_pair(18.1, 12.0)); coordinates.push_back(make_pair(16.0, 12.0)); //Cygnus coordinates.push_back(make_pair(21.1, 53.0)); coordinates.push_back(make_pair(19.1, 53.0)); coordinates.push_back(make_pair(21.1, 29.0)); coordinates.push_back(make_pair(19.1, 29.0)); //Pavo coordinates.push_back(make_pair(21.5, -58.0)); coordinates.push_back(make_pair(17.9, -58.0)); coordinates.push_back(make_pair(21.5, -74.0)); coordinates.push_back(make_pair(17.9, -74.0)); //Centaurus coordinates.push_back(make_pair(14.6, -38.0)); coordinates.push_back(make_pair(11.3, -38.0)); coordinates.push_back(make_pair(14.6, -64.0)); coordinates.push_back(make_pair(11.3, -64.0)); //Canes Venatici coordinates.push_back(make_pair(13.0, 42.0)); coordinates.push_back(make_pair(12.5, 42.0)); coordinates.push_back(make_pair(13.0, 38.0)); coordinates.push_back(make_pair(12.5, 38.0)); //Lynx coordinates.push_back(make_pair(9.4, 60.0)); coordinates.push_back(make_pair(6.4, 60.0)); coordinates.push_back(make_pair(9.4, 37.0)); coordinates.push_back(make_pair(6.4, 37.0)); //Auriga coordinates.push_back(make_pair(6, 46.0)); coordinates.push_back(make_pair(5, 46.0)); coordinates.push_back(make_pair(6, 30.0)); coordinates.push_back(make_pair(5, 30.0)); //Hydra coordinates.push_back(make_pair(14.2, 8.0)); coordinates.push_back(make_pair(8.6, 8.0)); coordinates.push_back(make_pair(14.2, -35.0)); coordinates.push_back(make_pair(8.6, -35.0)); //Vela coordinates.push_back(make_pair(10.8, -42.0)); coordinates.push_back(make_pair(8.3, -42.0)); coordinates.push_back(make_pair(10.8, -55.0)); coordinates.push_back(make_pair(8.3, -55.0)); return coordinates; } ... ... @@ -560,7 +614,7 @@ void printConstellation (vector > constellationCoordinates, inrangeCount = 0; for (int i = 0; i < 4; i++) { coordinateCount++; if((windowLeft > constellationCoordinates.at(coordinateCount).first) && (constellationCoordinates.at(coordinateCount).first < windowRight) if((windowLeft > constellationCoordinates.at(coordinateCount).first) && (constellationCoordinates.at(coordinateCount).first < windowRight) // checks if specific constellation point falls within window boundaries && (windowTop > constellationCoordinates.at(coordinateCount).second) && (constellationCoordinates.at(coordinateCount).second > windowBottom)) { inrangeCount++; } ... ... @@ -618,6 +672,24 @@ string constellationNamer (int index) { return " Ursa Minor "; case 67: return " Ursa Major "; case 71: return " Hercules "; case 75: return " Cygnus "; case 79: return " Pavo "; case 83: return " Centaurus "; case 87: return " Canes Venatici "; case 91: return " Lynx "; case 95: return " Auriga "; case 99: return " Hydra "; case 103: return " Vela "; default: return " Unknown constellation "; } ... ... @@ -694,6 +766,42 @@ void constellationOutputter (int index) { a.UrsaMajor16(); cout << endl; break; case 71: a.Hercules17(); cout << endl; break; case 75: a.Cygnus18(); cout << endl; break; case 79: a.Pavo19(); cout << endl; break; case 83: a.Centaurus20(); cout << endl; break; case 87: a.CanesVenatici21(); cout << endl; break; case 91: a.Lynx22(); cout << endl; break; case 95: a.Auriga23(); cout << endl; break; case 99: a.Hydra24(); cout << endl; break; case 103: a.Vela25(); cout << endl; break; default: cout << endl; } ... ... @@ -706,19 +814,18 @@ bool restart(){ cout << "Would you like to quit? (y/n): " << endl; do{ cin >> input; tolower(input); if(input != 'y' || input != 'n'){ if(input != 'y' && input != 'n'){ goodInput = false; cerr << "Error: Invalid input. Try again." << endl; cin.clear(); } else { goodInput = true; } }while(!goodInput); } while(!goodInput); if(input == 'y'){ if (input == 'y'){ return false; } else { return true; exit(0); } } \ No newline at end of file
 ... ... @@ -13,10 +13,8 @@ int hourPrompt (); // Prompts and checks hour input int minutePrompt (); // Prompts and checks minute input double dateToHour (string month, int year, int day, int hour, int minute); // Converts full date to hour pair altAndAziPair (); // Creates pair of alitutude and azimuth bool isLeap (int year); // Bool check for leap year ... ... @@ -29,4 +27,6 @@ void printConstellation (vector > constellationCoordinates, string constellationNamer (int index); // funciton to name all the constellations void constellationOutputter (int index); // function to output the images of the constellations \ No newline at end of file void constellationOutputter (int index); // function to output the images of the constellations bool restart(); // function to ask for restart options \ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!