Commit bd8d1f68 by Elon Bontemps

### Merge branch 'master' of gitlab.cs.wallawalla.edu:walser/project-3-star-gazing

parents 7c040dd6 9bb3230f
 ... ... @@ -3,6 +3,7 @@ #include #include #include #include const bool DEBUG = true; //the main algorithm function converts ... ... @@ -45,16 +46,20 @@ double timeToPhi(int year, double hours, double longitude){ //convert the date to a julian date; double julian(double year, double hours){ double leap, notLeap, dayFract, dayWhole; double leap = 0; double notLeap, dayFract, dayWhole; double julian, years, days, seconds, hoursLeft; years = year + 4713 + 1;//years is current year (AD or CE) 4713 is the start of the julian calender 1 is 0 AD/CE 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 < 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){ ... ... @@ -74,7 +79,11 @@ double julian(double year, double hours){ } } else { leap++; /* if(DEBUG){ clog << "DEBUG: " << i << " is a leap year." << endl; } */ } } } } ... ... @@ -82,22 +91,30 @@ double julian(double year, double hours){ 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; 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 >= 12){ //turns the left over hours into seconds since noon (12pm) seconds = (hoursLeft - 12) * 360; 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 = (hoursLeft + 12) * 360; //seconds = 43200; } if(DEBUG){ clog << "DEBUG: Days has a value of " << days << " hoursLeft has a value of " << hoursLeft << " while seconds has value of: " << seconds << endl; } days += seconds / 86400; days += (seconds / 86400); return days; } ... ... @@ -105,15 +122,43 @@ double julian(double year, double hours){ //converts the hours and year to GMST (Greenwich Mean Sidereal Time) double GMST(int year, double hours){ //JD is the julian date (days since jan 1st, 4713 BC) and D is days since Jan 1st 2000 double JD, D, GMST; JD = julian(year, hours); D = JD - 2451545.0; GMST = fmod(D, 24); double D, GMST, temp, JD0; //double hoursLeft = modf((hours/24), &temp) * 24; // hours since the previous midnight //hoursLeft = (hoursLeft + 12); double JD = julian(year, hours); //double JDmin = floor(JD) - 0.5; //double JDmax = floor(JD) + 0.5; JD0 = floor(JD) + 0.5; D = ( JD - 2451545.0); double D0 = JD0 - 2451545.0; double T = D/36525; // centuries since Jan 1st 2000 AD double hoursLeft = (JD -JD0) *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)); 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) ; //GMST = temp; //GMST = modf((temp/24), &D) * 24; /*if(GMST > 24){ GMST -= 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 ... ... @@ -121,23 +166,48 @@ pair algorithm(double hours, pair latAndLongPair, //the map is in celestial coordinates pair raAndDecPair; //char constellationMap[ROW_MAX][COl_MAX]; double theta = latToTheta(latAndLongPair.first); double phi = timeToPhi(year, hours, latAndLongPair.second); double x, y, z; double xPrime, yPrime, zPrime, alpha, sigma; //double theta = latToTheta(latAndLongPair.first); //double phi = timeToPhi(year, hours, latAndLongPair.second); 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; // longitude double hoursLeft = modf((hours/24), &temp) * 24; //double x, y, z; //double xPrime, yPrime, zPrime, alpha, sigma; //converting the horizontal coordinates to cartesian coordinates horizontalToCart(altAndAziPair.first, altAndAziPair.second, x, y , z); xPrime = (x*cos(phi)*cos(theta)) + y*sin(phi) + (z*cos(phi)*sin(theta)); yPrime = (-1*x*sin(phi)*cos(theta)) + y*cos(theta) + (-1*z*sin(phi)*sin(theta)); zPrime = (-1*x*sin(theta)) + z*cos(theta); //horizontalToCart(altAndAziPair.first, altAndAziPair.second, x, y , z); //xPrime = (x*cos(phi)*cos(theta)) + y*sin(phi) + (z*cos(phi)*sin(theta)); //yPrime = (-1*x*sin(phi)*cos(theta)) + y*cos(theta) + (-1*z*sin(phi)*sin(theta)); //zPrime = (-1*x*sin(theta)) + z*cos(theta); 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)); //cartesian to celestial alpha = atan2(yPrime, xPrime); sigma = asin(zPrime); //alpha = atan2(yPrime, xPrime) * (180 / M_PI); //sigma = asin(zPrime) * (180 / M_PI); alpha = (GMST(year, hours) * 15 - Long) - (acos(hourAngle) * (180 / M_PI)); 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: " << (GMST(year, hours)*15 - Long) << " and the hour angle is " << hourAngle << " and the arccos of the hour angle is: " << acos(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; raAndDecPair.second = sigma; raAndDecPair.second = sigma * (180 / M_PI); return raAndDecPair; }
 the algorithm function is sourced from "Trasforming Geographic to Celestial Coordinates" by Michael McEllis \ No newline at end of file
 ... ... @@ -11,7 +11,7 @@ int main(){ //declaration of variables double x, y, z; //testing horizontal to cart conversion function horizontalToCart(24, 46, x, y, z); /* horizontalToCart(24, 46, x, y, z); cout << "When the altitude is 24 and the azimuth is 46 (in degrees):" << endl << "X = " << x << endl << "Y = " << y << endl ... ... @@ -20,18 +20,33 @@ int main(){ cout << "The values should be: " << endl << "X = 0.634601998946" << endl << "Y = -0.657149607101" << endl << "Z = 0.406736643076" << endl; << "Z = 0.406736643076" << endl;*/ //converting latitude to theta cout << "if th latitude is -46, then the latToTheta function should return 136." << endl << "It actually returns: " << latToTheta(-46) << endl; /* cout << "if th latitude is -46, then the latToTheta function should return 136." << endl << "It actually returns: " << latToTheta(-46) << endl;*/ //calculating the julian date cout << "if the date is January 27, 2034 at 5:45:54.6 pm, the julian date function should return 2463990.240215." << endl << "It actually returns: " << julian(2034, 641.765166667) << endl; cout << "if the date is January 27, 2017 at 5:45:54.6 pm, the julian date function should return 2457781.240208." << endl << "It actually returns: " << julian(2017, 641.9) << endl; cout << "if the date is January 1, 2000 at 00:00:00, the GMST date function should return: 6.79519916667." << endl << "It actually returns: " << GMST(2000, 0) << endl; //converting time and longitude to phi // cout << "if its January 27, 2034, 5:45 pm at a longitude of 49 the, phi should equal 13.24." << endl // << "Phi actually equals: " << timeToPhi(2034, 648.45, 49) << endl; /*cout << "if its January 27, 2034, 5:45 pm at a longitude of 49 the, phi should equal 4.65147698949." << endl << "Phi actually equals: " << timeToPhi(2034, 641.765166667, 49) << endl;*/ //test the algorithm as a whole pair test; test.first = -46; test.second = 89; pair horizontal; horizontal.first = 20; horizontal.second = 270; pair returnValue; returnValue = algorithm(641.9, test, horizontal, 2017); cout << "The algorithm function, when its January 27, 2017, at 5:45:54 pm, at a lat and long of -46,89 and when looking at the sky at 20, 270 (in horizontal coordinates), gives: " << endl << "Right ascention of: " << returnValue.first << " and a declination of: " << returnValue.second << endl; }
 #include "Functions.h" #include "Stars.h" #include "Constellation.h" #include #include #include ... ... @@ -136,7 +138,7 @@ pair altAndAziPair () { } } while (true); do { do { // Prompt and check for cardinal direction cout << "Enter a cardinal direction (North, South, East, West, Northeast, Southeast, Southwest, or Northwest): "; cin >> direction; ... ... @@ -174,7 +176,6 @@ pair altAndAziPair () { return aziPair; } double dateToHour (string month, int year, int day, int hour, int minute) { // Converts the date into hours //variables double totHours = 0; ... ... @@ -221,7 +222,7 @@ double dateToHour (string month, int year, int day, int hour, int minute) { // C return totHours; } bool isLeap (int year) { // bool check for leap year bool isLeap (int year) { // bool check for leap years if ((year % 4) == 0) { return true; } else { ... ... @@ -238,26 +239,26 @@ vector > viewFinder (pair centerPt) { // f pair pair4; if (centerPt.second > 0) { if (centerPt.first > 20.125 && centerPt.second < 51) { // done if (centerPt.first > 20.125 && centerPt.second < 51) { for(int i = 0; i < 4; i++) { if (i == 0) { // top left point pair1 = make_pair((centerPt.first + 3.875) - 24, centerPt.second + 39); corners.push_back(pair1); } else if (i == 1) { // top right point pair2 = make_pair(centerPt.first - 3.875), centerPt.second + 39); pair2 = make_pair((centerPt.first - 3.875), centerPt.second + 39); corners.push_back(pair2); } else if (i == 2) { // bottom left point pair3 = make_pair((centerPt.first + 3.875) - 24, centerPt.second - 39); corners.push_back(pair3); } else if (i == 3) { // bottom right point pair4 = make_pair(centerPt.first - 3.875), centerPt.second - 39); pair4 = make_pair((centerPt.first - 3.875), centerPt.second - 39); corners.push_back(pair4); } } } else if (centerPt.first < 3.875 && centerPt.second < 51) { // done } else if (centerPt.first < 3.875 && centerPt.second < 51) { for(int i = 0; i < 4; i++) { if (i == 0) { // top left point pair1 = make_pair(centerPt.first + 3.875), centerPt.second + 39); pair1 = make_pair((centerPt.first + 3.875), centerPt.second + 39); corners.push_back(pair1); } else if (i == 1) { // top right point pair2 = make_pair(24 - (3.875 - centerPt.first), centerPt.second + 39); ... ... @@ -270,7 +271,7 @@ vector > viewFinder (pair centerPt) { // f corners.push_back(pair4); } } } else if (centerPt.first > 20.125 && centerPt.second > 51) { // done } else if (centerPt.first > 20.125 && centerPt.second > 51) { for(int i = 0; i < 4; i++) { if (i == 0) { // top left point pair1 = make_pair((centerPt.first + 3.875) - 24, -90 + (centerPt.second - 51)); ... ... @@ -286,7 +287,7 @@ vector > viewFinder (pair centerPt) { // f corners.push_back(pair4); } } } else if (centerPt.first < 3.875 && centerPt.second > 51) { // done } else if (centerPt.first < 3.875 && centerPt.second > 51) { for(int i = 0; i < 4; i++) { if (i == 0) { // top left point pair1 = make_pair(centerPt.first + 3.875, -90 + (centerPt.second - 51)); ... ... @@ -302,7 +303,7 @@ vector > viewFinder (pair centerPt) { // f corners.push_back(pair4); } } } else if ((centerPt.first < 20.125 && centerPt.first > 3.875) && centerPt.second > 51) { // done } else if ((centerPt.first < 20.125 && centerPt.first > 3.875) && centerPt.second > 51) { for(int i = 0; i < 4; i++) { if (i == 0) { // top left point pair1 = make_pair(centerPt.first + 3.875, -90 + (centerPt.second - 51)); ... ... @@ -318,7 +319,7 @@ vector > viewFinder (pair centerPt) { // f corners.push_back(pair4); } } } else if ((centerPt.first < 20.125 && centerPt.first > 3.875) && centerPt.second < 51) { // done } else if ((centerPt.first < 20.125 && centerPt.first > 3.875) && centerPt.second < 51) { for(int i = 0; i < 4; i++) { if (i == 0) { // top left point pair1 = make_pair(centerPt.first + 3.875, centerPt.second + 39); ... ... @@ -336,26 +337,26 @@ vector > viewFinder (pair centerPt) { // f } } } else if (centerPt.second < 0) { if (centerPt.first > 20.125 && centerPt.second > -51) { // done if (centerPt.first > 20.125 && centerPt.second > -51) { for(int i = 0; i < 4; i++) { if (i == 0) { // top left point pair1 = make_pair((centerPt.first + 3.875) - 24, centerPt.second + 39); corners.push_back(pair1); } else if (i == 1) { // top right point pair2 = make_pair(centerPt.first - 3.875), centerPt.second + 39); pair2 = make_pair((centerPt.first - 3.875), centerPt.second + 39); corners.push_back(pair2); } else if (i == 2) { // bottom left point pair3 = make_pair((centerPt.first + 3.875) - 24, centerPt.second - 39); corners.push_back(pair3); } else if (i == 3) { // bottom right point pair4 = make_pair(centerPt.first - 3.875), centerPt.second - 39); pair4 = make_pair((centerPt.first - 3.875), centerPt.second - 39); corners.push_back(pair4); } } } else if (centerPt.first < 3.875 && centerPt.second > -51) { // done } else if (centerPt.first < 3.875 && centerPt.second > -51) { for(int i = 0; i < 4; i++) { if (i == 0) { // top left point pair1 = make_pair(centerPt.first + 3.875), centerPt.second + 39); pair1 = make_pair((centerPt.first + 3.875), centerPt.second + 39); corners.push_back(pair1); } else if (i == 1) { // top right point pair2 = make_pair(24 - (3.875 - centerPt.first), centerPt.second + 39); ... ... @@ -368,7 +369,7 @@ vector > viewFinder (pair centerPt) { // f corners.push_back(pair4); } } } else if (centerPt.first > 20.125 && centerPt.second < -51) { // done } else if (centerPt.first > 20.125 && centerPt.second < -51) { for(int i = 0; i < 4; i++) { if (i == 0) { // top left point pair1 = make_pair((centerPt.first + 3.875) - 24, centerPt.second + 39); ... ... @@ -438,7 +439,7 @@ vector > viewFinder (pair centerPt) { // f return corners; } vector > constellationCoordinates () { vector > constellationCoordinates () { // Function to store the coordinates of the constellations vector > coordinates; // Canis Major pair pair1a; ... ... @@ -604,7 +605,7 @@ vector > constellationCoordinates () { pair pair12c; pair12c = make_pair(18.0, -42.0); coordinates.push_back(pair12c); pair pair1d; pair pair12d; pair12d = make_pair(16.0, -42.0); coordinates.push_back(pair12d); ... ... @@ -615,7 +616,7 @@ vector > constellationCoordinates () { pair pair13b; pair13b = make_pair(20.3, -12.0); coordinates.push_back(pair13b); pair pair1c; pair pair13c; pair13c = make_pair(21.8, -28.0); coordinates.push_back(pair13c); pair pair13d; ... ... @@ -629,7 +630,7 @@ vector > constellationCoordinates () { pair pair14b; pair14b = make_pair(21.2, 30.0); coordinates.push_back(pair14b); pair pair1c; pair pair14c; pair14c = make_pair(.2, 6.0); coordinates.push_back(pair14c); pair pair14d; ... ... @@ -671,32 +672,118 @@ vector > constellationCoordinates () { pair pair17b; pair17b = make_pair(8.6, 61.0); coordinates.push_back(pair17b); pair pair1c; pair pair17c; pair17c = make_pair(13.7, 32.0); coordinates.push_back(pair17c); pair pair1d; pair pair17d; pair17d = make_pair(8.6, 32.0); coordinates.push_back(pair17d); } void viewWindow (vector > corners, pair constellationCoord) { pair coordinates1; pair coordinates2; pair coordinates3; pair coordinates4; void printConstellation (vector > constellationCoordinates, vector > window) { int inrangeCount = 0; int coordinateCount = 0; if(corners.coordinates1.first > constellationCoord.first && corners.coordinates1.second > constellationCoord.second && corners.coordinates2.first < constellationCoord.first && corners.coordinates2.second > constellationCoord.second && corners.coordinates3.first > constellationCoord.first && corners.coordinates3.second < constellationCoord.second && corners.coordinates4.first < constellationCoord.first && corners.coordinates4.second < constellationCoord.second) { cout << "Constellation is fully in view" << endl; } else if (corners.coordinates1.first > constellationCoord.first || corners.coordinates1.second > constellationCoord.second || corners.coordinates2.first < constellationCoord.first || corners.coordinates2.second > constellationCoord.second || corners.coordinates3.first > constellationCoord.first || corners.coordinates3.second < constellationCoord.second || corners.coordinates4.first < constellationCoord.first || corners.coordinates4.second < constellationCoord.second) { cout << "Constellation is partially in view" << endl; } else { cout << "Constellation is not in view" << endl; for(int j = 0; j < (constellationCoordinates.size() / 4); j++) { inrangeCount = 0; for (int i = 0; i < 4; i++) { coordinateCount++; if(((window.at(0).first) > (constellationCoordinates.at(coordinateCount).first)) && ((window.at(1).first) < (constellationCoordinates.at(coordinateCount).first)) && ((window.at(2).first) > (constellationCoordinates.at(coordinateCount).first)) && ((window.at(3).first) < (constellationCoordinates.at(coordinateCount).first)) && ((window.at(0).second) > (constellationCoordinates.at(coordinateCount).second)) && ((window.at(1).second) < (constellationCoordinates.at(coordinateCount).second)) && ((window.at(2).second) > (constellationCoordinates.at(coordinateCount).second)) && ((window.at(3).second) < (constellationCoordinates.at(coordinateCount).second))) { inrangeCount++; } } if (inrangeCount == 4) { cout << "Constellation" << constellationNamer(coordinateCount) << "is fully in view." << endl << "Here is an image." << endl; constellationOutputter(coordinateCount); } else if (inrangeCount < 4 && inrangeCount > 0) { cout << "Constellation" << constellationNamer(coordinateCount) << "is partially in view." << endl << "Here is an image." << endl; constellationOutputter(coordinateCount); } else { cout << endl; } } } string constellationNamer (int index) { if (index == 3) { return " Canis Major "; } else if (index == 7) { return " Eridanius "; } else if (index == 11) { return " Gemini "; } else if (index == 15) { return " Orion "; } else if (index == 19) { return " Tarus "; } else if (index == 23) { return " Bootes "; } else if (index == 27) { return " Cancer"; } else if (index == 31) { return " Leo "; } else if (index == 35) { return " Virgo "; } else if (index == 39) { return " Aquila "; } else if (index == 43) { return " Sagitarius "; } else if (index == 47) { return " Scorpius "; } else if (index == 51) { return " Capricornus "; } else if (index == 55) { return " Pegasus "; } else if (index == 59) { return " Pisces "; } else if (index == 63) { return " Ursa Minor "; } else if (index == 67) { return " Ursa Major "; } } void constellationOutputter (int index) { Stars a; if (index == 3) { a.CanisMajor0(); } else if (index == 7) { a.Eridanius1(); } else if (index == 11) { a.Gemini2(); } else if (index == 15) { a.Orion3(); } else if (index == 19) { a.Tarus4(); } else if (index == 23) { a.Bootes5(); } else if (index == 27) { a.Cancer6(); } else if (index == 31) { a.Leo7(); } else if (index == 35) { a.Virgo8(); } else if (index == 39) { a.Aquila9(); } else if (index == 43) { a.Sagistarius10(); } else if (index == 47) { a.Scorpius11(); } else if (index == 51) { a.Capricornus12(); } else if (index == 55) { a.Pegasus13(); } else if (index == 59) { a.Pisces14(); } else if (index == 63) { a.UrsaMinor15(); } else if (index == 67) { a.UrsaMajor16(); } }
 #include #include using namespace std; ... ... @@ -16,4 +17,14 @@ double dateToHour (string month, int day, int hour, int minute); // Converts ful pair altAndAziPair (); // Creates pair of alitutude and azimuth bool isLeap (int year); // Bool check for leap year \ No newline at end of file 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 \ No newline at end of file
 ... ... @@ -442,12 +442,8 @@ void Stars::Capricornus12() { } } <<<<<<< HEAD void Stars::Pegasus13() { //done ======= void Stars::Pegasus() { //done: coordinates based on pic 11:02pm at 24 degrees >>>>>>> 4e1ad8624316617b8f087e4405e4375a485173e0 void Stars::Pegasus13() { //done: coordinates based on pic 11:02pm at 24 degrees for(int row = 0; row < 24; row++) { for(int col = 0; col < 40; col++) { ... ...
 ... ... @@ -15,23 +15,23 @@ class Stars { public: void CanisMajor(); void Eridanius(); void Gemini();