Commit e49a15ef authored by Elon Bontemps's avatar Elon Bontemps
Browse files

autosave

parent 307da63f
#include "Algorithm.h"
#include <deque>
#include <utility>
#include <cmath>
#include <iostream>
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, 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
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++;
}
}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++;
}
}
}
}
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;
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;
} else {
seconds = (hoursLeft + 12) * 360;
}
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;
return days;
}
//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);
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<double,double> algorithm(double hours, pair<double, double> latAndLongPair, pair<double, double> altAndAziPair, int year){
//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;
//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);
//cartesian to celestial
alpha = atan2(yPrime, xPrime);
sigma = asin(zPrime);
raAndDecPair.first = alpha;
raAndDecPair.second = sigma;
return raAndDecPair;
}
#ifndef ALGORITHM_H
#define ALGORITHM_H
#include <deque>
#include <string>
#include <vector>
#include <utility>
using namespace std;
//converts horizontal coordinates to cartesian coordinates in xyz
void horizontalToCart(double alt, double azi, double &x, double &y, double &z);
//converts the latitude to theta
double latToTheta(double lat);
//converts the time to phi
double timeToPhi(int year, double hours, double longitude);
//converts the hours and year to GMST
double GMST(int year, double hours);
//convert the date to a julian date;
double julian(double year, double hours);
//converts geographic coordinates to celestial coooriantes
pair<double,double> algorithm(double hours, pair<double, double> latAndLongPair, pair<double, double> altAndAziPair, int year);
#endif
\ No newline at end of file
#include "Algorithm.h"
#include <deque>
#include <utility>
#include <cmath>
#include <cassert>
#include <iostream>
using namespace std;
int main(){
//declaration of variables
double x, y, z;
//testing horizontal to cart conversion function
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
<< "Z = " << z << endl;
cout << "The values should be: " << endl
<< "X = 0.634601998946" << endl
<< "Y = -0.657149607101" << 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;
//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;
//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;
}
//North America
1. Seattle, Washington
2. Boise, Idaho
3. Helena, Montana
4. St. Paul, Minessota
5. Madison, Wisconson
New York, New York,
Augusta, Maine
Los-Angeles, California
Salt Lake City, Utah
Topeka, Kansas
Raleigh, North Carolina
Austin, Texas
Miami, Florida
//South America
Bogota, Columbia
Brasilia, Brazil
Buenos Aires, Argentina
//Africa
En Nahud, Sudan
Agadez, Niger
Kiffa, Mauritana
Fes, Morocco
Gamba, Gabon
Kindu, Democratic Republic of the Congo
Namacunde, Angola
Lugela, Mozambique
Camarvan, South Africa
Ihosy, Madagascar
//Europe
Afif, Saudi Arabia
Buky, Ukraine
Paris, France
Bor, Russia
Nagpur, India
Naggu, Tibet
//Asia
Golong, China
Bogd, Mongolia
Quanzhou, Fujian
Busan, South Korea
Nagoya, Japan
//Australia
//
/****************************************************************************
*
* Proj.03: A project that projects the star constellations depending on your
* geographical location on Earth.
*
*
* Name: Worked on project: Eric Walsh, Elon Bontemps, Brandon Reid, Moses Montanez
* and Elizabeth
* Course: CPTR 142
* Date: Due: March something 2019
*
*/
#include <iostream>
#include <vector>
using namespace std;
int main {
//Welcomeing the user
cout << "Welcome to the Star Gazer Application!" << endl;
}
\ No newline at end of file
Here is a link the basic flow chart for the project.
https://www.draw.io/#Wb!guP8I1MO6ky9qAikuFEYdLh_2q1TOJhAkB3FyycKJcm_QH70etj2ToguSQZ86C9_%2F01NFLHWNY56BBBXZXNWBGYLOZJAG3KN7Z7
#include "Functions.h"
#include <string>
#include <iostream>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;
// Input checking functions
int yearPrompt (int year) {
do {
cout << "Enter year: ";
if (!(cin >> year)) { // validates that numbers were entered and checks input
cerr << "Error! Please enter a valid integar." << endl;
cin.clear();
cin.ignore(1000, '\n');
continue;
}
if (year > 0 && year < 9099) {
return year;
} else {
cerr << "Error! Invalid year. Please enter a year between 1 and 9099" << endl;
}
} while (true);
}
string monthPrompt (string month) {
do {
cout << "Enter month: ";
cin >> month;
if (month == "January" || month == "February" || month == "March" || month == "April" || month == "May" || month == "June" || month == "July" || month == "August" || month == "September" || month == "October" || month == "November" || month == "December") {
return month;
} else {
cerr << "Error! Please enter a valid month." << endl;
}
} while (true);
}
int dayPrompt (string month, int day) {
do {
cout << "Enter day: ";
if (!(cin >> day)) { // validates that numbers were entered and checks input
cerr << "Error! Please enter a valid integar." << endl;
cin.clear();
cin.ignore(1000, '\n');
continue;
}
if (month == "January" || month == "March" || month == "May" || month == "July" || month == "August" || month == "October" || month == "December") {
if (day > 0 && day <= 31) {
return day;
}
}
if (month == "April" || month == "June" || month == "September" || month == "November") {
if (day > 0 && day <= 30) {
return day;
}
}
if (month == "February") {
if (day > 0 && day <= 28) {
return day;
}
}
cerr << "Error! Please enter a valid date." << endl;
} while (true);
}
int hourPrompt (int hour) {
do {
cout << "Enter hour (0 - 24): ";
if (!(cin >> hour)) { // validates that numbers were entered and checks input
cerr << "Error! Please enter a valid integer." << endl;
cin.clear();
cin.ignore(1000, '\n');
continue;
}
if (hour > 0 && hour <= 24) {
return hour;
} else {
cerr << "Error! Please enter a valid hour." << endl;
}
} while (true);
}
int minutePrompt (int minute) {
do {
cout << "Enter minute: ";
if (!(cin >> minute)) { // validates that numbers were entered and checks input
cerr << "Error! Please enter a valid integer." << endl;
cin.clear();
cin.ignore(1000, '\n');
continue;
}
if (minute >= 0 && minute < 60) {
return minute;
} else {
cerr << "Error! Please enter a valid minute." << endl;
}
} while (true);
}
double dateToHour (string month, int day, int hour, int minute) { // Converts the date into hours
//variables
double totHours = 0;
int monthNum = 0;
if(month == "January") {
monthNum = 1;
} else if (month == "February") {
monthNum = 2;
} else if (month == "March") {
monthNum = 3;
} else if (month == "April") {
monthNum = 4;
} else if (month == "May") {
monthNum = 5;
} else if (month == "June") {
monthNum = 6;
} else if (month == "July") {
monthNum = 7;
} else if (month == "August") {
monthNum = 8;
} else if (month == "September") {
monthNum = 9;
} else if (month == "October") {
monthNum = 10;
} else if (month == "November") {
monthNum = 11;
} else {
monthNum = 12;
}
totHours += (monthNum * 730) + (day * 24) + (minute / 60);
return totHours;
}
bool isLeap (int year) {
}
pair<double,double> altAndAziPair (double altitude, string Direction) {
double Azi;
pair<double,double> aziPair;
do {
cout << "Enter the altitude at which you are looking (0-90): ";
if (!(cin >> altitude)) { // validates that numbers were entered and checks input
cerr << "Error! Please enter a valid integer." << endl;
cin.clear();
cin.ignore(1000, '\n');
continue;
} else if (altitude < 0 || altitude >= 90) {
cout << "Please put in a valid value." << endl;
}
} while (false)
do {
cout << "Enter a cardinal direction (North, South, East, West, Northeast, Southeast, Southwest, or Northwest): ";
cin >> Direction;
if (Direction != "North" || Direction != "South" || Direction != "East" || Direction != "West" || Direction != "Northeast" || Direction != "Southeast" || Direction != "Southwest" || Direction != "Northwest") {
cout << "Error! Please input a valid direction";
}
} while (Direction != "North" || Direction != "South" || Direction != "East" || Direction != "West" || Direction != "Northeast" || Direction != "Southeast" || Direction != "Southwest" || Direction != "Northwest")
if (Direction == "North") {
Azi = 0;
} else if (Direction == "South") {
Azi = 180;
} else if (Direction == "East") {
Azi = 90;
} else if (Direction == "West") {
Azi = 270;
} else if (Direction == "Northeast") {
Azi = 45;
} else if (Direction == "Southeast") {
Azi = 135;
} else if (Direction == "Southwest") {
Azi = 225;
} else if (Direction == "Northwest") {
Azi = 315;
}
aziPair = make_pair(altitude,Azi);
return aziPair;
}
#include "Functions.h"
#include <string>
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
// Input checking functions
int yearPrompt (int year) {
do {
cout << "Enter year: ";
if (!(cin >> year)) { // validates that numbers were entered and checks input
cerr << "Error! Please enter a valid integar." << endl;
cin.clear();
cin.ignore(1000, '\n');
continue;
}
if (isLeap(year)) { // Tells user if it is a leap year of not
cout << "This is a leap year." << endl;
} else if (!isLeap(year)) {
cout << "This is not a leap yar." << endl;
}
if (year > 0 && year < 9099) {
return year;
} else {
cerr << "Error! Invalid year. Please enter a year between 1 and 9099" << endl;
}
} while (true);
}
string monthPrompt (string month) {
do {
cout << "Enter month: ";
cin >> month;
if (month == "January" || month == "February" || month == "March" || month == "April" || month == "May" || month == "June" || month == "July" || month == "August" || month == "September" || month == "October" || month == "November" || month == "December") {
return month;
} else {
cerr << "Error! Please enter a valid month." << endl;
}
} while (true);
}
int dayPrompt (string month, int day, int year) {
do {
cout << "Enter day: ";
if (!(cin >> day)) { // validates that numbers were entered and checks input
cerr << "Error! Please enter a valid integar." << endl;
cin.clear();
cin.ignore(1000, '\n');
continue;
}
if (month == "January" || month == "March" || month == "May" || month == "July" || month == "August" || month == "October" || month == "December") {
if (day > 0 && day <= 31) {
return day;
}
}
if (month == "April" || month == "June" || month == "September" || month == "November") {
if (day > 0 && day <= 30) {
return day;
}
}
if (month == "February") {
if (isLeap(year)) {
if (day > 0 && day <= 29) {
return day;
}
} else if (!isLeap(year)) {
if (day > 0 && day <= 28) {
return day;
}
}
}
cerr << "Error! Please enter a valid date." << endl;
} while (true);
}
int hourPrompt (int hour) {
do {
cout << "Enter hour (0 - 23): ";
if (!(cin >> hour)) { // validates that numbers were entered and checks input
cerr << "Error! Please enter a valid integar." << endl;
cin.clear();
cin.ignore(1000, '\n');
continue;
}
if (hour >= 0 && hour < 24) {
return hour;
} else {
cerr << "Error! Please enter a valid hour." << endl;
}
} while (true);
}
int minutePrompt (int minute) {
do {
cout << "Enter minute: ";
if (!(cin >> minute)) { // validates that numbers were entered and checks input
cerr << "Error! Please enter a valid integar." << endl;
cin.clear();
cin.ignore(1000, '\n');
continue;
}
if (minute >= 0 && minute < 60) {
return minute;
} else {
cerr << "Error! Please enter a valid minute." << endl;
}
} while (true);
}
pair<double,double> altAndAziPair (double altitude, string Direction) {
double Azi;
pair<double,double> aziPair;
do {
cout << "Enter the altitude at which you are looking (0-90): ";
if (!(cin >> altitude)) {