summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWe-unite <3205135446@qq.com>2024-03-08 21:24:55 +0800
committerWe-unite <3205135446@qq.com>2024-03-08 21:24:55 +0800
commit6fd843db21af18be0634bac770c6b74ad4e78bb7 (patch)
tree85afec2f24965c69042a25a8eb5fb3008cad05aa
parent505d07a7abccfc707e2d27c2deb2fe460854e751 (diff)
downloadcalendar-6fd843db21af18be0634bac770c6b74ad4e78bb7.tar.gz
calendar-6fd843db21af18be0634bac770c6b74ad4e78bb7.zip
HourAngle Fixed, and sun pos right
-rw-r--r--src/.clang-format121
-rw-r--r--src/calendar.cpp77
-rw-r--r--src/calendar.h20
-rw-r--r--src/parameters.cpp45
4 files changed, 80 insertions, 183 deletions
diff --git a/src/.clang-format b/src/.clang-format
deleted file mode 100644
index a1054a5..0000000
--- a/src/.clang-format
+++ /dev/null
@@ -1,121 +0,0 @@
1---
2Language: Cpp
3# BasedOnStyle: LLVM
4AccessModifierOffset: -2
5AlignAfterOpenBracket: Align
6AlignConsecutiveAssignments: false
7AlignConsecutiveDeclarations: false
8AlignEscapedNewlines: Right
9AlignOperands: true
10AlignTrailingComments: true
11AllowAllParametersOfDeclarationOnNextLine: true
12AllowShortBlocksOnASingleLine: false
13AllowShortCaseLabelsOnASingleLine: false
14AllowShortFunctionsOnASingleLine: All
15AllowShortIfStatementsOnASingleLine: false
16AllowShortLoopsOnASingleLine: false
17AlwaysBreakAfterDefinitionReturnType: None
18AlwaysBreakAfterReturnType: None
19AlwaysBreakBeforeMultilineStrings: false
20AlwaysBreakTemplateDeclarations: MultiLine
21BinPackArguments: true
22BinPackParameters: true
23BraceWrapping:
24 AfterClass: false
25 AfterControlStatement: false
26 AfterEnum: false
27 AfterFunction: false
28 AfterNamespace: false
29 AfterObjCDeclaration: false
30 AfterStruct: false
31 AfterUnion: false
32 AfterExternBlock: false
33 BeforeCatch: false
34 BeforeElse: false
35 IndentBraces: false
36 SplitEmptyFunction: true
37 SplitEmptyRecord: true
38 SplitEmptyNamespace: true
39BreakBeforeBinaryOperators: None
40BreakBeforeBraces: Attach
41BreakBeforeInheritanceComma: false
42BreakInheritanceList: BeforeColon
43BreakBeforeTernaryOperators: true
44BreakConstructorInitializersBeforeComma: false
45BreakConstructorInitializers: BeforeColon
46BreakAfterJavaFieldAnnotations: false
47BreakStringLiterals: true
48ColumnLimit: 80
49CommentPragmas: '^ IWYU pragma:'
50CompactNamespaces: false
51ConstructorInitializerAllOnOneLineOrOnePerLine: false
52ConstructorInitializerIndentWidth: 4
53ContinuationIndentWidth: 4
54Cpp11BracedListStyle: true
55DerivePointerAlignment: false
56DisableFormat: false
57ExperimentalAutoDetectBinPacking: false
58FixNamespaceComments: true
59ForEachMacros:
60 - foreach
61 - Q_FOREACH
62 - BOOST_FOREACH
63IncludeBlocks: Preserve
64IncludeCategories:
65 - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
66 Priority: 2
67 - Regex: '^(<|"(gtest|gmock|isl|json)/)'
68 Priority: 3
69 - Regex: '.*'
70 Priority: 1
71IncludeIsMainRegex: '(Test)?$'
72IndentCaseLabels: false
73IndentPPDirectives: None
74IndentWidth: 4
75IndentWrappedFunctionNames: false
76JavaScriptQuotes: Leave
77JavaScriptWrapImports: true
78KeepEmptyLinesAtTheStartOfBlocks: true
79MacroBlockBegin: ''
80MacroBlockEnd: ''
81MaxEmptyLinesToKeep: 1
82NamespaceIndentation: None
83ObjCBinPackProtocolList: Auto
84ObjCBlockIndentWidth: 2
85ObjCSpaceAfterProperty: false
86ObjCSpaceBeforeProtocolList: true
87PenaltyBreakAssignment: 2
88PenaltyBreakBeforeFirstCallParameter: 19
89PenaltyBreakComment: 300
90PenaltyBreakFirstLessLess: 120
91PenaltyBreakString: 1000
92PenaltyBreakTemplateDeclaration: 10
93PenaltyExcessCharacter: 1000000
94PenaltyReturnTypeOnItsOwnLine: 60
95PointerAlignment: Right
96ReflowComments: true
97SortIncludes: true
98SortUsingDeclarations: true
99SpaceAfterCStyleCast: false
100SpaceAfterTemplateKeyword: true
101SpaceBeforeAssignmentOperators: true
102SpaceBeforeCpp11BracedList: false
103SpaceBeforeCtorInitializerColon: true
104SpaceBeforeInheritanceColon: true
105SpaceBeforeParens: ControlStatements
106SpaceBeforeRangeBasedForLoopColon: true
107SpaceInEmptyParentheses: false
108SpacesBeforeTrailingComments: 1
109SpacesInAngles: false
110SpacesInContainerLiterals: true
111SpacesInCStyleCastParentheses: false
112SpacesInParentheses: false
113SpacesInSquareBrackets: false
114Standard: Cpp11
115StatementMacros:
116 - Q_UNUSED
117 - QT_REQUIRE_VERSION
118TabWidth: 8
119UseTab: Never
120...
121
diff --git a/src/calendar.cpp b/src/calendar.cpp
index 8af1851..6731692 100644
--- a/src/calendar.cpp
+++ b/src/calendar.cpp
@@ -7,36 +7,47 @@
7/*以下为"calendar.h规定之量*/ 7/*以下为"calendar.h规定之量*/
8double day = 86400; 8double day = 86400;
9double delta = 1e-11; 9double delta = 1e-11;
10
11/*计算需要用的类的实例化*/
12Julian julian; 10Julian julian;
13parameter p; 11parameter p;
14 12
15void radToDMS(const char *message, int lowerBound, int upperBound, 13pair<double, double> getSunPos(time_t time) {
16 double radians) { 14 double t = julian.getJulianKiloYear(time);
17 // Convert radians to degrees
18 double degrees = radians * 180.0 / M_PI;
19 15
20 while (degrees < lowerBound) 16 pair<double, double> sun = p.sun_longitude(t);
21 degrees += (upperBound - lowerBound); 17 radToDMS("Sun longitude:\t\t", 0, 360, sun.first);
22 while (degrees >= upperBound) 18 radToDMS("Sun latitude:\t\t", -90, 90, sun.second);
23 degrees -= (upperBound - lowerBound);
24 19
25 // Calculate degrees, minutes, and seconds 20 double alpha, delta; // 太阳赤经赤纬
26 int deg = static_cast<int>(degrees); 21 double lambda = sun.first, beta = sun.second; // 太阳黄经黄纬
27 double min_sec = (degrees - deg) * 60.0; 22 // 黄赤交角epsilon
28 int min = static_cast<int>(min_sec); 23 double epsilon = p.get_epsilon(t);
29 double sec = (min_sec - min) * 60.0; 24 radToDMS("Ecliptic Obliquity:\t\t", 0, 90, epsilon);
30 25
31 // Output the result 26 delta =
32 printf("%s: %d°%d'%06.3f''\n", message, deg, min, sec); 27 asin(sin(epsilon) * sin(lambda) * cos(beta) + cos(epsilon) * sin(beta));
28 alpha = atan2(
29 (cos(epsilon) * sin(lambda) * cos(beta) - sin(epsilon) * sin(beta)),
30 (cos(lambda) * cos(beta)));
31 radToDMS("Sun right ascension:\t\t", 0, 360, alpha);
32 radToDMS("Sun declination:\t\t", -90, 90, delta);
33 // 时角
34 double H = p.getHourAngle(t, LONGITUDE, LATITUDE, alpha);
35 double A, h; //方位角和高度角
36 h = asin(sin(LATITUDE) * sin(delta) + cos(LATITUDE) * cos(delta) * cos(H));
37 A = atan2(-cos(delta) * sin(H),
38 cos(LATITUDE) * sin(delta) - sin(LATITUDE) * cos(delta) * cos(H));
39 A += M_PI;
40 // 转换为角度制输出
41 radToDMS("Hour angle:\t\t", 0, 360, H);
42 radToDMS("Azimuth:\t\t", 0, 360, A);
43 radToDMS("Elevation:\t\t", -90, 90, h);
33} 44}
34 45
35int main(int argc, char *argv[]) { 46int main(int argc, char *argv[]) {
36 Date date; 47 Date date;
37 if (argc != 2) { 48 if (argc != 2) {
38 printf("Input the time you want to calculate in <YYYY-MM-DD,HH:MM:SS> " 49 printf("Input the time you want to calculate in <YYYY-MM-DD,HH:MM:SS> "
39 "format: "); 50 "format:\t\t");
40 scanf("%d-%d-%d,%d:%d:%d", &date.tm_year, &date.tm_mon, &date.tm_mday, 51 scanf("%d-%d-%d,%d:%d:%d", &date.tm_year, &date.tm_mon, &date.tm_mday,
41 &date.tm_hour, &date.tm_min, &date.tm_sec); 52 &date.tm_hour, &date.tm_min, &date.tm_sec);
42 } else { 53 } else {
@@ -48,34 +59,6 @@ int main(int argc, char *argv[]) {
48 date.tm_isdst = -1; 59 date.tm_isdst = -1;
49 60
50 time_t time = mktime(&date); 61 time_t time = mktime(&date);
51 double t = julian.getJulianKiloYear(time); 62 getSunPos(time);
52
53 pair<double, double> sun = p.sun_longitude(t);
54 radToDMS("Sun longitude: ", 0, 360, sun.first);
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);
80 return 0; 63 return 0;
81} 64}
diff --git a/src/calendar.h b/src/calendar.h
index 810fa0c..248026f 100644
--- a/src/calendar.h
+++ b/src/calendar.h
@@ -10,8 +10,8 @@
10using namespace std; 10using namespace std;
11 11
12// 哈尔滨南岗地方经纬度 12// 哈尔滨南岗地方经纬度
13#define LONGITUDE 126.68 * M_PI / 180 13#define LONGITUDE 126.533 * M_PI / 180
14#define LATITUDE 45.75 * M_PI / 180 14#define LATITUDE 45.800 * M_PI / 180
15 15
16extern double delta; 16extern double delta;
17extern char jieqi[25][10]; 17extern char jieqi[25][10];
@@ -45,15 +45,15 @@ struct point {
45 } 45 }
46}; 46};
47 47
48void radToDMS(const char *message, int lowerBound, int upperBound,
49 double radians);
50
48class Julian { 51class Julian {
49 private: 52 private:
50 static double d[23][5]; 53 static double d[23][5];
51 54
52 double dt_ext(int y, double jsd); 55 double dt_ext(int y, double jsd);
53 56
54 //计算力学时与世界时之差,传入年份
55 double delta_t(int y);
56
57 public: 57 public:
58 // 计算儒略日 58 // 计算儒略日
59 double getJulianDay(time_t time); 59 double getJulianDay(time_t time);
@@ -63,6 +63,9 @@ class Julian {
63 63
64 //儒略千年数转时间戳 64 //儒略千年数转时间戳
65 time_t kiloYearToTime(double t, int year); 65 time_t kiloYearToTime(double t, int year);
66
67 //计算力学时与世界时之差,传入年份
68 double delta_t(int y);
66}; 69};
67 70
68class parameter { 71class parameter {
@@ -95,8 +98,13 @@ class parameter {
95 98
96 double moon_longitude(double t); 99 double moon_longitude(double t);
97 100
98 double getHourAngle(double julianKiloTime, double longitude, 101 double get_epsilon(double T);
102
103 // 计算时角,返回弧度制
104 double getHourAngle(double julianKiloYear, double longitude,
99 double latitude, double alpha); 105 double latitude, double alpha);
100}; 106};
101 107
108extern Julian julian;
109extern parameter p;
102#endif \ No newline at end of file 110#endif \ No newline at end of file
diff --git a/src/parameters.cpp b/src/parameters.cpp
index f08736b..fdcefd1 100644
--- a/src/parameters.cpp
+++ b/src/parameters.cpp
@@ -1,9 +1,32 @@
1// 凡无特殊说明的函数,全部返回弧度制
2
1#include "parameters.h" 3#include "parameters.h"
2#include "calendar.h" 4#include "calendar.h"
3#include <utility> 5#include <utility>
4using namespace std; 6using namespace std;
5 7
6//凡无特殊说明的函数,全部返回弧度制 8void radToDMS(const char *message, int lowerBound, int upperBound,
9 double radians) {
10 // Convert radians to degrees
11 double degrees = radians * 180.0 / M_PI;
12
13 while (degrees < lowerBound)
14 degrees += (upperBound - lowerBound);
15 while (degrees >= upperBound)
16 degrees -= (upperBound - lowerBound);
17
18 bool flag = degrees < 0;
19 if (flag)
20 degrees = -degrees;
21 // Calculate degrees, minutes, and seconds
22 int deg = static_cast<int>(degrees);
23 double min_sec = (degrees - deg) * 60.0;
24 int min = static_cast<int>(min_sec);
25 double sec = (min_sec - min) * 60.0;
26
27 // Output the result
28 printf("%s: %c%d°%d'%06.3f''\n", message, flag ? '-' : ' ', deg, min, sec);
29}
7 30
8// 计算地球日心黄经 31// 计算地球日心黄经
9double parameter::get_longitude(vector<double> l, double t) { 32double parameter::get_longitude(vector<double> l, double t) {
@@ -222,13 +245,17 @@ double parameter::moon_longitude(double t) {
222 return L; 245 return L;
223} 246}
224 247
225double parameter::getHourAngle(double julianKiloTime, double longitude, 248double parameter::getHourAngle(double julianKiloYear, double longitude,
226 double latitude, double alpha) { 249 double latitude, double alpha) {
227 double t = 100 * 365.25 * julianKiloTime; 250 double T = julianKiloYear * 10;
228 // 该时刻的格林尼治恒星时 251 double GST = 280.46061837 + 360.98564736629 * 36525 * T +
229 double GST = 6.697374558 + 2400.051336 * t + 0.000025862333 * t * t - 252 0.000387933 * T * T - T * T * T / 38710000;
230 0.000000001722222 * t * t * t; 253 GST *= M_PI / 180;
231 return GST * M_PI / 12 + longitude - alpha; 254 return GST + longitude - alpha; // 返回弧度制
232 // double GST = 241.654320 + 360.9856473840 * t * 1000 * 36525; 255}
233 // return GST * M_PI / 180 + longitude - alpha; 256
257double parameter::get_epsilon(double T) {
258 double epsilon = 23.439291111 - 0.01300416667 * T -
259 (1.638888889e-7) * T * T + (5.036111111e-7) * T * T * T;
260 return epsilon * M_PI / 180;
234} \ No newline at end of file 261} \ No newline at end of file