source: ntrip/trunk/BNC/src/bnctides.cpp@ 4720

Last change on this file since 4720 was 4278, checked in by mervart, 13 years ago
File size: 6.9 KB
RevLine 
[2578]1
2#include <cmath>
3
4#include "bnctides.h"
[2579]5#include "bncutils.h"
[2578]6
7using namespace std;
8
9// Auxiliary Functions
10///////////////////////////////////////////////////////////////////////////
11namespace {
12
13 static const double RHO_DEG = 180.0 / M_PI;
14 static const double RHO_SEC = 3600.0 * RHO_DEG;
15 static const double MJD_J2000 = 51544.5;
16
17 double Frac (double x) { return x-floor(x); };
18 double Modulo (double x, double y) { return y*Frac(x/y); }
19
20 Matrix rotX(double Angle) {
21 const double C = cos(Angle);
22 const double S = sin(Angle);
23 Matrix UU(3,3);
24 UU[0][0] = 1.0; UU[0][1] = 0.0; UU[0][2] = 0.0;
25 UU[1][0] = 0.0; UU[1][1] = +C; UU[1][2] = +S;
26 UU[2][0] = 0.0; UU[2][1] = -S; UU[2][2] = +C;
27 return UU;
28 }
29
30 Matrix rotY(double Angle) {
31 const double C = cos(Angle);
32 const double S = sin(Angle);
33 Matrix UU(3,3);
34 UU[0][0] = +C; UU[0][1] = 0.0; UU[0][2] = -S;
35 UU[1][0] = 0.0; UU[1][1] = 1.0; UU[1][2] = 0.0;
36 UU[2][0] = +S; UU[2][1] = 0.0; UU[2][2] = +C;
37 return UU;
38 }
39
40 Matrix rotZ(double Angle) {
41 const double C = cos(Angle);
42 const double S = sin(Angle);
43 Matrix UU(3,3);
44 UU[0][0] = +C; UU[0][1] = +S; UU[0][2] = 0.0;
45 UU[1][0] = -S; UU[1][1] = +C; UU[1][2] = 0.0;
46 UU[2][0] = 0.0; UU[2][1] = 0.0; UU[2][2] = 1.0;
47 return UU;
48 }
49}
50
51// Greenwich Mean Sidereal Time
52///////////////////////////////////////////////////////////////////////////
53double GMST(double Mjd_UT1) {
54
55 const double Secs = 86400.0;
56
57 double Mjd_0 = floor(Mjd_UT1);
58 double UT1 = Secs*(Mjd_UT1-Mjd_0);
59 double T_0 = (Mjd_0 -MJD_J2000)/36525.0;
60 double T = (Mjd_UT1-MJD_J2000)/36525.0;
61
62 double gmst = 24110.54841 + 8640184.812866*T_0 + 1.002737909350795*UT1
63 + (0.093104-6.2e-6*T)*T*T;
64
65 return 2.0*M_PI*Frac(gmst/Secs);
66}
67
68// Nutation Matrix
69///////////////////////////////////////////////////////////////////////////
70Matrix NutMatrix(double Mjd_TT) {
71
72 const double T = (Mjd_TT-MJD_J2000)/36525.0;
73
74 double ls = 2.0*M_PI*Frac(0.993133+ 99.997306*T);
75 double D = 2.0*M_PI*Frac(0.827362+1236.853087*T);
76 double F = 2.0*M_PI*Frac(0.259089+1342.227826*T);
77 double N = 2.0*M_PI*Frac(0.347346- 5.372447*T);
78
79 double dpsi = ( -17.200*sin(N) - 1.319*sin(2*(F-D+N)) - 0.227*sin(2*(F+N))
80 + 0.206*sin(2*N) + 0.143*sin(ls) ) / RHO_SEC;
81 double deps = ( + 9.203*cos(N) + 0.574*cos(2*(F-D+N)) + 0.098*cos(2*(F+N))
82 - 0.090*cos(2*N) ) / RHO_SEC;
83
84 double eps = 0.4090928-2.2696E-4*T;
85
86 return rotX(-eps-deps)*rotZ(-dpsi)*rotX(+eps);
87}
88
89// Precession Matrix
90///////////////////////////////////////////////////////////////////////////
91Matrix PrecMatrix (double Mjd_1, double Mjd_2) {
92
93 const double T = (Mjd_1-MJD_J2000)/36525.0;
94 const double dT = (Mjd_2-Mjd_1)/36525.0;
95
96 double zeta = ( (2306.2181+(1.39656-0.000139*T)*T)+
97 ((0.30188-0.000344*T)+0.017998*dT)*dT )*dT/RHO_SEC;
98 double z = zeta + ( (0.79280+0.000411*T)+0.000205*dT)*dT*dT/RHO_SEC;
99 double theta = ( (2004.3109-(0.85330+0.000217*T)*T)-
100 ((0.42665+0.000217*T)+0.041833*dT)*dT )*dT/RHO_SEC;
101
102 return rotZ(-z) * rotY(theta) * rotZ(-zeta);
103}
104
105// Sun's position
106///////////////////////////////////////////////////////////////////////////
107ColumnVector Sun(double Mjd_TT) {
108
109 const double eps = 23.43929111/RHO_DEG;
110 const double T = (Mjd_TT-MJD_J2000)/36525.0;
111
112 double M = 2.0*M_PI * Frac ( 0.9931267 + 99.9973583*T);
[2586]113 double L = 2.0*M_PI * Frac ( 0.7859444 + M/2.0/M_PI +
[2578]114 (6892.0*sin(M)+72.0*sin(2.0*M)) / 1296.0e3);
115 double r = 149.619e9 - 2.499e9*cos(M) - 0.021e9*cos(2*M);
116
117 ColumnVector r_Sun(3);
118 r_Sun << r*cos(L) << r*sin(L) << 0.0; r_Sun = rotX(-eps) * r_Sun;
119
120 return rotZ(GMST(Mjd_TT))
121 * NutMatrix(Mjd_TT)
122 * PrecMatrix(MJD_J2000, Mjd_TT)
123 * r_Sun;
124}
125
126// Moon's position
127///////////////////////////////////////////////////////////////////////////
128ColumnVector Moon(double Mjd_TT) {
129
130 const double eps = 23.43929111/RHO_DEG;
131 const double T = (Mjd_TT-MJD_J2000)/36525.0;
132
133 double L_0 = Frac ( 0.606433 + 1336.851344*T );
134 double l = 2.0*M_PI*Frac ( 0.374897 + 1325.552410*T );
135 double lp = 2.0*M_PI*Frac ( 0.993133 + 99.997361*T );
136 double D = 2.0*M_PI*Frac ( 0.827361 + 1236.853086*T );
137 double F = 2.0*M_PI*Frac ( 0.259086 + 1342.227825*T );
138
139 double dL = +22640*sin(l) - 4586*sin(l-2*D) + 2370*sin(2*D) + 769*sin(2*l)
140 -668*sin(lp) - 412*sin(2*F) - 212*sin(2*l-2*D)- 206*sin(l+lp-2*D)
141 +192*sin(l+2*D) - 165*sin(lp-2*D) - 125*sin(D) - 110*sin(l+lp)
142 +148*sin(l-lp) - 55*sin(2*F-2*D);
143
144 double L = 2.0*M_PI * Frac( L_0 + dL/1296.0e3 );
145
146 double S = F + (dL+412*sin(2*F)+541*sin(lp)) / RHO_SEC;
147 double h = F-2*D;
148 double N = -526*sin(h) + 44*sin(l+h) - 31*sin(-l+h) - 23*sin(lp+h)
149 +11*sin(-lp+h) - 25*sin(-2*l+F) + 21*sin(-l+F);
150
151 double B = ( 18520.0*sin(S) + N ) / RHO_SEC;
152
153 double cosB = cos(B);
154
155 double R = 385000e3 - 20905e3*cos(l) - 3699e3*cos(2*D-l) - 2956e3*cos(2*D)
156 -570e3*cos(2*l) + 246e3*cos(2*l-2*D) - 205e3*cos(lp-2*D)
157 -171e3*cos(l+2*D) - 152e3*cos(l+lp-2*D);
158
159 ColumnVector r_Moon(3);
160 r_Moon << R*cos(L)*cosB << R*sin(L)*cosB << R*sin(B);
161 r_Moon = rotX(-eps) * r_Moon;
162
163 return rotZ(GMST(Mjd_TT))
164 * NutMatrix(Mjd_TT)
165 * PrecMatrix(MJD_J2000, Mjd_TT)
166 * r_Moon;
167}
[2579]168
169// Tidal Correction
170////////////////////////////////////////////////////////////////////////////
171void tides(const bncTime& time, ColumnVector& xyz) {
172
173 static double lastMjd = 0.0;
[2581]174 static ColumnVector xSun;
175 static ColumnVector xMoon;
[2579]176 static double rSun;
177 static double rMoon;
178
179 double Mjd = time.mjd() + time.daysec() / 86400.0;
180
181 if (Mjd != lastMjd) {
182 lastMjd = Mjd;
183 xSun = Sun(Mjd);
184 rSun = sqrt(DotProduct(xSun,xSun));
185 xSun /= rSun;
186 xMoon = Moon(Mjd);
187 rMoon = sqrt(DotProduct(xMoon,xMoon));
188 xMoon /= rMoon;
189 }
190
191 double rRec = sqrt(DotProduct(xyz, xyz));
192 ColumnVector xyzUnit = xyz / rRec;
193
194 // Love's Numbers
195 // --------------
[4151]196 const double H2 = 0.6078;
197 const double L2 = 0.0847;
[2579]198
199 // Tidal Displacement
200 // ------------------
201 double scSun = DotProduct(xyzUnit, xSun);
202 double scMoon = DotProduct(xyzUnit, xMoon);
203
204 double p2Sun = 3.0 * (H2/2.0-L2) * scSun * scSun - H2/2.0;
205 double p2Moon = 3.0 * (H2/2.0-L2) * scMoon * scMoon - H2/2.0;
206
207 double x2Sun = 3.0 * L2 * scSun;
208 double x2Moon = 3.0 * L2 * scMoon;
209
210 const double gmWGS = 398.6005e12;
211 const double gms = 1.3271250e20;
212 const double gmm = 4.9027890e12;
213
214 double facSun = gms / gmWGS *
215 (rRec * rRec * rRec * rRec) / (rSun * rSun * rSun);
[2581]216
[2579]217 double facMoon = gmm / gmWGS *
218 (rRec * rRec * rRec * rRec) / (rMoon * rMoon * rMoon);
219
220 ColumnVector dX = facSun * (x2Sun * xSun + p2Sun * xyzUnit) +
[2581]221 facMoon * (x2Moon * xMoon + p2Moon * xyzUnit);
[2579]222
223 xyz += dX;
224}
Note: See TracBrowser for help on using the repository browser.