14# pragma warning (disable: 4127)
24 if (!(isfinite(_a) && _a > 0))
25 throw GeographicErr(
"Equatorial radius is not positive");
28 throw GeographicErr(
"Gravitational constant is not finite");
32 if (!(isfinite(_omega2) && isfinite(_aomega2)))
33 throw GeographicErr(
"Rotation velocity is not finite");
36 if (!(isfinite(_b) && _b > 0))
37 throw GeographicErr(
"Polar semi-axis is not positive");
40 _ep2 = _e2 / (1 - _e2);
41 real ex2 = _f < 0 ? -_e2 : _ep2;
42 _qQ0 = Qf(ex2, _f < 0);
43 _earth = Geocentric(_a, _f);
44 _eE = _a * sqrt(fabs(_e2));
46 _uU0 = _gGM * atanzz(ex2, _f < 0) / _b + _aomega2 / 3;
47 real P = Hf(ex2, _f < 0) / (6 * _qQ0);
49 _gammae = _gGM / (_a * _b) - (1 + P) * _a * _omega2;
51 _gammap = _gGM / (_a * _a) + 2 * P * _b * _omega2;
54 _k = -_e2 * _gGM / (_a * _b) +
55 _omega2 * (P * (_a + 2 * _b * (1 - _f)) + _a);
57 _fstar = (-_f * _gGM / (_a * _b) + _omega2 * (P * (_a + 2 * _b) + _a)) /
63 Initialize(a, GM, omega, f_J2, geometricp);
88 static const real lg2eps_ = -log2(numeric_limits<real>::epsilon() / 2);
97 int n = x == 0 ? 1 : int(ceil(lg2eps_ / e));
109 return 1/
real(5) + x * atan7series(x);
117 real y = alt ? -x / (1 + x) : x;
118 return !(4 * fabs(y) < 1) ?
119 ((1 + 3/y) * atanzz(x, alt) - 3/y) / (2 * y) :
120 (3 * (3 + y) * atan5series(y) - 1) / 6;
129 real y = alt ? -x / (1 + x) : x;
130 return !(4 * fabs(y) < 1) ?
131 (3 * (1 + 1/y) * (1 - atanzz(x, alt)) - 1) / y :
132 1 - 3 * (1 + y) * atan5series(y);
141 real y = alt ? -x / (1 + x) : x;
142 return !(4 * fabs(y) < 1) ?
143 ((9 + 15/y) * atanzz(x, alt) - 4 - 15/y) / (6 *
Math::sq(y)) :
144 ((25 + 15*y) * atan7series(y) + 3)/10;
153 for (
int j = n; j--;)
156 -3 * e2n * ((1 - n) + 5 * n * _jJ2 / _e2) / ((2 * n + 1) * (2 * n + 3));
166 real& GammaX, real& GammaY, real& GammaZ)
const
171 clam = p != 0 ? X/p : 1,
172 slam = p != 0 ? Y/p : 0,
174 if (_f < 0)
swap(p, Z);
181 u = sqrt((Q >= 0 ? (Q + disc) : t2 / (disc - Q)) / 2),
184 sbet = u != 0 ? Z * uE : copysign(sqrt(-Q), Z),
185 cbet = u != 0 ? p * u : p,
186 s = hypot(cbet, sbet);
187 sbet = s != 0 ? sbet/s : 1;
188 cbet = s != 0 ? cbet/s : 0;
192 den = hypot(u, _eE * sbet);
199 bu = _b / (u != 0 || _f < 0 ? u : _eE),
201 q = ((u != 0 || _f < 0 ? Qf(z2, _f < 0) :
Math::pi() / 4) / _qQ0) *
203 qp = _b *
Math::sq(bu) * (u != 0 || _f < 0 ? Hf(z2, _f < 0) : 2) / _qQ0,
204 ang = (
Math::sq(sbet) - 1/real(3)) / 2,
206 Vres = _gGM * (u != 0 || _f < 0 ?
207 atanzz(z2, _f < 0) / u :
208 Math::pi() / (2 * _eE)) + _aomega2 * q * ang,
210 gamu = - (_gGM + (_aomega2 * qp * ang)) * invw /
Math::sq(uE),
211 gamb = _aomega2 * q * sbet * cbet * invw / uE,
213 gamp = t * cbet * gamu - invw * sbet * gamb;
215 GammaX = gamp * clam;
216 GammaY = gamp * slam;
217 GammaZ = invw * sbet * gamu + t * cbet * gamb;
229 real& gammaX, real& gammaY, real& gammaZ)
const {
231 real Ures =
V0(X, Y, Z, gammaX, gammaY, gammaZ) +
Phi(X, Y, fX, fY);
238 real& gammay, real& gammaz)
const {
240 real M[Geocentric::dim2_];
241 _earth.IntForward(lat, 0, h, X, Y, Z, M);
242 real gammaX, gammaY, gammaZ,
243 Ures =
U(X, Y, Z, gammaX, gammaY, gammaZ);
245 gammay = M[1] * gammaX + M[4] * gammaY + M[7] * gammaZ;
246 gammaz = M[2] * gammaX + M[5] * gammaY + M[8] * gammaZ;
251 real omega, real J2) {
255 static const real maxe_ = 1 - numeric_limits<real>::epsilon();
256 static const real eps2_ = sqrt(numeric_limits<real>::epsilon()) / 100;
258 K = 2 *
Math::sq(a * omega) * a / (15 * GM),
260 if (!(GM > 0 && isfinite(K) && K >= 0))
262 if (!(isfinite(J2) && J2 <= J0))
return Math::NaN();
263 if (J2 == J0)
return 1;
271 e2 = fmin(ep2 / (1 + ep2), maxe_);
274 e2a = e2, ep2a = ep2,
277 Q0 = Qf(e2 < 0 ? -e2 : ep2, e2 < 0),
278 h = e2 - f1 * f2 * K / Q0 - 3 * J2,
279 dh = 1 - 3 * f1 * K * QH3f(e2 < 0 ? -e2 : ep2, e2 < 0) /
281 e2 = fmin(e2a - h / dh, maxe_);
282 ep2 = fmax(e2 / (1 - e2), -maxe_);
283 if (fabs(h) < eps2_ || e2 == e2a || ep2 == ep2a)
286 return e2 / (1 + sqrt(1 - e2));
290 real omega, real f) {
292 K = 2 *
Math::sq(a * omega) * a / (15 * GM),
297 return (e2 - K * f1 * f2 / Qf(f < 0 ? -e2 : e2 / f2, f < 0)) / 3;
GeographicLib::Math::real real
#define GEOGRAPHICLIB_PANIC
Header for GeographicLib::NormalGravity class.
The normal gravity of the earth.
Math::real V0(real X, real Y, real Z, real &GammaX, real &GammaY, real &GammaZ) const
static Math::real FlatteningToJ2(real a, real GM, real omega, real f)
Math::real Phi(real X, real Y, real &fX, real &fY) const
static const NormalGravity & WGS84()
static Math::real J2ToFlattening(real a, real GM, real omega, real J2)
Math::real U(real X, real Y, real Z, real &gammaX, real &gammaY, real &gammaZ) const
Math::real SurfaceGravity(real lat) const
static const NormalGravity & GRS80()
Math::real Gravity(real lat, real h, real &gammay, real &gammaz) const
Namespace for GeographicLib.
void swap(GeographicLib::NearestNeighbor< dist_t, pos_t, distfun_t > &a, GeographicLib::NearestNeighbor< dist_t, pos_t, distfun_t > &b)