Commit 91bde0d0 authored by Brandon Reid's avatar Brandon Reid

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

parents a1f6f308 bd43800b
......@@ -3,6 +3,7 @@
#include <utility>
#include <cmath>
#include <iostream>
#include <iomanip>
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,7 +91,11 @@ 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;
......@@ -97,7 +110,7 @@ double julian(double year, double hours){
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 +118,40 @@ 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;
double hoursLeft = modf((hours/24), &temp) * 24;
/*if(hoursLeft >= 12){ //turns the left over hours into hours since noon (12pm)
hoursLeft = (hoursLeft - 12);
} else {
hoursLeft = (hoursLeft + 12);
}*/
D = ((julian(year, hours) - (hoursLeft / 24)) - 2451545.0);
double T = D/36525; // centuries since Jan 1st 2000 AD
if(DEBUG){
clog << "DEBUG: The GMST in days is: " << D << endl;
}
//temp = 67310.5481 + (876600* hoursLeft + 8640184.812866)*T + (0.09314 * pow(T, 2)) - ((6.2 * pow(10, -6)) * pow(T, 3));
temp = 6.697374558 + (0.06570982441908*D) + (1.00273790935*hoursLeft) + (0.000026 * pow(T, 2));
//temp = 18.697374558 + 24.06570982441908*D;
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.0);
//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 +159,48 @@ pair<double,double> algorithm(double hours, pair<double, double> latAndLongPair,
//the map is in celestial coordinates
pair<double,double> 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) - 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) + 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 27, 2017 at 5:45:54.6 pm, the GMST date function should return: 2.34623833333." << endl
<< "It actually returns: " << GMST(2017, 641.9) << 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<double, double> test;
test.first = -46;
test.second = 89;
pair<double,double> horizontal;
horizontal.first = 20;
horizontal.second = 270;
pair<double,double> 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;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment