-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolarPositionCalculation.cpp
More file actions
83 lines (66 loc) · 1.93 KB
/
Copy pathSolarPositionCalculation.cpp
File metadata and controls
83 lines (66 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "SolarPositionCalculation.h"
SolarPositionCalculation::SolarPositionCalculation() {
}
SolarPositionCalculation::SolarPositionCalculation(int year, int month, int day) {
this->year = year;
this->day = day;
this->month = month;
}
double SolarPositionCalculation::calcTimeJulianCent(double jd) {
double T = (jd - 2451545.0)/36525.0;
return T;
}
double SolarPositionCalculation::calcJDFromJulianCent(double t) {
double JD = t * 36525.0 + 2451545.0;
return JD;
}
bool SolarPositionCalculation::isLeapYear(int year) {
return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0);
}
Date SolarPositionCalculation::calcDateFromJD(double jd) {
double z = floor(jd + 0.5);
double f = (jd + 0.5) - z;
double A;
if (z < 2299161) {
A = z;
} else {
double alpha = floor((z - 1867216.25)/36524.25);
A = z + 1 + alpha - floor(alpha/4);
}
double B = A + 1524;
double C = floor((B - 122.1)/365.25);
double D = floor(365.25 * C);
double E = floor((B - D)/30.6001);
this->day = B - D - floor(30.6001 * E) + f;
this->month = (E < 14) ? E - 1 : E - 13;
this->year = (this->month > 2) ? C - 4716 : C - 4715;
std::cout << "\n" << this->year;
Date date(this->year, this->month, this->day);
return date;
}
double SolarPositionCalculation::calcDoyFromJD(double jd) {
Date date = calcDateFromJD(jd);
std::cout << "\n" << date.getYear();
int k = (isLeapYear(date.getYear()) ? 1 : 2);
double doy = floor((275 * date.getMonth())/9.0) - k * floor((date.getMonth() + 9)/12.0) + date.getDay() -30;
return doy;
}
double SolarPositionCalculation::getJD() {
if (month <= 2) {
year -= 1;
month += 12;
}
double A = floor(year/100);
double B = 2 - A + floor(A/4);
double JD = floor(365.25*(year + 4716)) + floor(30.6001*(month+1)) + day + B - 1524.5;
return JD;
}
int SolarPositionCalculation::getYear(){
return year;
}
int SolarPositionCalculation::getMonth(){
return month;
}
int SolarPositionCalculation::getDay() {
return day;
}