summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWe-unite <3205135446@qq.com>2024-03-07 21:50:22 +0800
committerWe-unite <3205135446@qq.com>2024-03-07 21:50:22 +0800
commit505d07a7abccfc707e2d27c2deb2fe460854e751 (patch)
treed1bd801021deaa99dd18b9027c39d11076d74a46
parent9b3951efb56b3e1cf3b115c0a2fbfc3b90e28330 (diff)
downloadcalendar-505d07a7abccfc707e2d27c2deb2fe460854e751.tar.gz
calendar-505d07a7abccfc707e2d27c2deb2fe460854e751.zip
Confused about hourAngle
-rw-r--r--src/calendar.cpp24
-rw-r--r--src/calendar.h9
-rw-r--r--src/parameters.cpp13
3 files changed, 44 insertions, 2 deletions
diff --git a/src/calendar.cpp b/src/calendar.cpp
index 9ad8413..8af1851 100644
--- a/src/calendar.cpp
+++ b/src/calendar.cpp
@@ -53,5 +53,29 @@ int main(int argc, char *argv[]) {
53 pair<double, double> sun = p.sun_longitude(t); 53 pair<double, double> sun = p.sun_longitude(t);
54 radToDMS("Sun longitude: ", 0, 360, sun.first); 54 radToDMS("Sun longitude: ", 0, 360, sun.first);
55 radToDMS("Sun latitude: ", -90, 90, sun.second); 55 radToDMS("Sun latitude: ", -90, 90, sun.second);
56
57 double alpha, delta; // 太阳赤经赤纬
58 double lambda = sun.first, beta = sun.second; // 太阳黄经黄纬
59 // 黄赤交角epsilon,23°26'21.448''转换为弧度
60 double epsilon = (23.0 + 26.0 / 60.0 + 21.448 / 3600.0) * M_PI / 180.0;
61
62 delta =
63 asin(sin(epsilon) * sin(lambda) * cos(beta) + cos(epsilon) * sin(beta));
64 alpha = atan2(
65 (cos(epsilon) * sin(lambda) * cos(beta) - sin(epsilon) * sin(beta)),
66 (cos(epsilon) * cos(beta)));
67 radToDMS("Sun right ascension: ", 0, 360, alpha);
68 radToDMS("Sun declination: ", -90, 90, delta);
69 // 时角
70 double H = p.getHourAngle(t, LONGITUDE, LATITUDE, alpha);
71 double A, h; //方位角和高度角
72 h = asin(sin(LATITUDE) * sin(delta) + cos(LATITUDE) * cos(delta) * cos(H));
73 A = atan2(-cos(delta) * sin(H),
74 cos(LATITUDE) * sin(delta) - sin(LATITUDE) * cos(delta) * cos(H));
75 A += M_PI;
76 // 转换为角度制输出
77 radToDMS("Hour angle: ", 0, 360, H);
78 radToDMS("Azimuth: ", 0, 360, A);
79 radToDMS("Elevation: ", 0, 90, h);
56 return 0; 80 return 0;
57} 81}
diff --git a/src/calendar.h b/src/calendar.h
index ef785c0..810fa0c 100644
--- a/src/calendar.h
+++ b/src/calendar.h
@@ -9,6 +9,10 @@
9#include <vector> 9#include <vector>
10using namespace std; 10using namespace std;
11 11
12// 哈尔滨南岗地方经纬度
13#define LONGITUDE 126.68 * M_PI / 180
14#define LATITUDE 45.75 * M_PI / 180
15
12extern double delta; 16extern double delta;
13extern char jieqi[25][10]; 17extern char jieqi[25][10];
14 18
@@ -90,6 +94,9 @@ class parameter {
90 pair<double, double> sun_longitude(double t); 94 pair<double, double> sun_longitude(double t);
91 95
92 double moon_longitude(double t); 96 double moon_longitude(double t);
97
98 double getHourAngle(double julianKiloTime, double longitude,
99 double latitude, double alpha);
93}; 100};
94 101
95#endif 102#endif \ No newline at end of file
diff --git a/src/parameters.cpp b/src/parameters.cpp
index 2e2758a..f08736b 100644
--- a/src/parameters.cpp
+++ b/src/parameters.cpp
@@ -1,5 +1,5 @@
1#include "calendar.h"
2#include "parameters.h" 1#include "parameters.h"
2#include "calendar.h"
3#include <utility> 3#include <utility>
4using namespace std; 4using namespace std;
5 5
@@ -221,3 +221,14 @@ double parameter::moon_longitude(double t) {
221 L -= 360; 221 L -= 360;
222 return L; 222 return L;
223} 223}
224
225double parameter::getHourAngle(double julianKiloTime, double longitude,
226 double latitude, double alpha) {
227 double t = 100 * 365.25 * julianKiloTime;
228 // 该时刻的格林尼治恒星时
229 double GST = 6.697374558 + 2400.051336 * t + 0.000025862333 * t * t -
230 0.000000001722222 * t * t * t;
231 return GST * M_PI / 12 + longitude - alpha;
232 // double GST = 241.654320 + 360.9856473840 * t * 1000 * 36525;
233 // return GST * M_PI / 180 + longitude - alpha;
234} \ No newline at end of file