14# pragma warning (disable: 4127 5055)
31 static const real tolRF =
32 pow(3 * numeric_limits<real>::epsilon() * real(0.01), 1/real(8));
36 Q = fmax(fmax(fabs(A0-x), fabs(A0-y)), fabs(A0-z)) / tolRF,
41 while (Q >= mul * fabs(An)) {
43 real lam = sqrt(x0)*sqrt(y0) + sqrt(y0)*sqrt(z0) + sqrt(z0)*sqrt(x0);
51 X = (A0 - x) / (mul * An),
52 Y = (A0 - y) / (mul * An),
61 return (E3 * (6930 * E3 + E2 * (15015 * E2 - 16380) + 17160) +
62 E2 * ((10010 - 5775 * E2) * E2 - 24024) + 240240) /
68 static const real tolRG0 =
69 real(2.7) * sqrt((numeric_limits<real>::epsilon() * real(0.01)));
70 real xn = sqrt(x), yn = sqrt(y);
71 if (xn < yn)
swap(xn, yn);
72 while (fabs(xn-yn) > tolRG0 * xn) {
74 real t = (xn + yn) /2;
85 atan(sqrt((y - x) / x)) / sqrt(y - x) :
86 ( x == y ? 1 / sqrt(y) :
93 sqrt(-x / y) ) / sqrt(x - y) ) );
97 return (x == 0 ?
RG(y, z) :
101 (z *
RF(x, y, z) - (x-z) * (y-z) *
RD(x, y, z) / 3
102 + sqrt(x * y / z)) / 2 )));
107 static const real tolRG0 =
108 real(2.7) * sqrt((numeric_limits<real>::epsilon() * real(0.01)));
110 x0 = sqrt(fmax(x, y)),
111 y0 = sqrt(fmin(x, y)),
116 while (fabs(xn-yn) > tolRG0 * xn) {
118 real t = (xn + yn) /2;
131 tolRD = pow(real(0.2) * (numeric_limits<real>::epsilon() * real(0.01)),
134 A0 = (x + y + z + 2*p)/5,
136 delta = (p-x) * (p-y) * (p-z),
137 Q = fmax(fmax(fabs(A0-x), fabs(A0-y)),
138 fmax(fabs(A0-z), fabs(A0-p))) / tolRD,
146 while (Q >= mul * fabs(An)) {
149 lam = sqrt(x0)*sqrt(y0) + sqrt(y0)*sqrt(z0) + sqrt(z0)*sqrt(x0),
150 d0 = (sqrt(p0)+sqrt(x0)) * (sqrt(p0)+sqrt(y0)) * (sqrt(p0)+sqrt(z0)),
152 s +=
RC(1, 1 + e0)/(mul * d0);
162 X = (A0 - x) / (mul * An),
163 Y = (A0 - y) / (mul * An),
164 Z = (A0 - z) / (mul * An),
165 P = -(X + Y + Z) / 2,
166 E2 = X*Y + X*Z + Y*Z - 3*P*P,
167 E3 = X*Y*Z + 2*P * (E2 + 2*P*P),
168 E4 = (2*X*Y*Z + P * (E2 + 3*P*P)) * P,
175 return ((471240 - 540540 * E2) * E5 +
176 (612612 * E2 - 540540 * E3 - 556920) * E4 +
177 E3 * (306306 * E3 + E2 * (675675 * E2 - 706860) + 680680) +
178 E2 * ((417690 - 255255 * E2) * E2 - 875160) + 4084080) /
179 (4084080 * mul * An * sqrt(An)) + 6 * s;
185 tolRD = pow(real(0.2) * (numeric_limits<real>::epsilon() * real(0.01)),
188 A0 = (x + y + 3*z)/5,
190 Q = fmax(fmax(fabs(A0-x), fabs(A0-y)), fabs(A0-z)) / tolRD,
196 while (Q >= mul * fabs(An)) {
198 real lam = sqrt(x0)*sqrt(y0) + sqrt(y0)*sqrt(z0) + sqrt(z0)*sqrt(x0);
199 s += 1/(mul * sqrt(z0) * (z0 + lam));
207 X = (A0 - x) / (mul * An),
208 Y = (A0 - y) / (mul * An),
211 E3 = (3*X*Y - 8*Z*Z)*Z,
212 E4 = 3 * (X*Y - Z*Z) * Z*Z,
219 return ((471240 - 540540 * E2) * E5 +
220 (612612 * E2 - 540540 * E3 - 556920) * E4 +
221 E3 * (306306 * E3 + E2 * (675675 * E2 - 706860) + 680680) +
222 E2 * ((417690 - 255255 * E2) * E2 - 875160) + 4084080) /
223 (4084080 * mul * An * sqrt(An)) + 3 * s;
227 real kp2, real alphap2) {
241 _eps = _k2/
Math::sq(sqrt(_kp2) + 1);
270 _eEc = _kp2 != 0 ? 2 *
RG(_kp2, 1) : 1;
275 _kKc = _eEc =
Math::pi()/2; _dDc = _kKc/2;
279 real rj = (_kp2 != 0 && _alphap2 != 0) ?
RJ(0, _kp2, 1, _alphap2) :
287 _gGc = _kp2 != 0 ? _kKc + (_alpha2 - _k2) * rj / 3 : rc;
289 _hHc = _kp2 != 0 ? _kKc - (_alphap2 != 0 ? _alphap2 * rj : 0) / 3 : rc;
291 _pPic = _kKc; _gGc = _eEc;
305 _hHc = _kp2 != 0 ? _kp2 *
RD(0, 1, _kp2) / 3 : 1;
319 static const real tolJAC =
320 sqrt(numeric_limits<real>::epsilon() * real(0.01));
322 real mc = _kp2, d = 0;
330 real m[num_], n[num_];
335 n[l] = mc = sqrt(mc);
337 if (!(fabs(a - mc) > tolJAC * a)) {
355 dn = (n[l] + a) / (b + a);
358 a = 1 / sqrt(c*c + 1);
359 sn = signbit(sn) ? -a : a;
368 dn = cn = 1 / cosh(x);
375 real cn2 = cn*cn, dn2 = dn*dn,
376 fi = cn2 != 0 ? fabs(sn) *
RF(cn2, dn2, 1) :
K();
380 return copysign(fi, sn);
385 cn2 = cn*cn, dn2 = dn*dn, sn2 = sn*sn,
387 fabs(sn) * ( _k2 <= 0 ?
390 RF(cn2, dn2, 1) - _k2 * sn2 *
RD(cn2, dn2, 1) / 3 :
393 _kp2 *
RF(cn2, dn2, 1) +
394 _k2 * _kp2 * sn2 *
RD(cn2, 1, dn2) / 3 +
395 _k2 * fabs(cn) / dn :
397 - _kp2 * sn2 *
RD(dn2, 1, cn2) / 3 +
403 return copysign(ei, sn);
410 cn2 = cn*cn, dn2 = dn*dn, sn2 = sn*sn,
411 di = cn2 != 0 ? fabs(sn) * sn2 *
RD(cn2, dn2, 1) / 3 :
D();
415 return copysign(di, sn);
422 cn2 = cn*cn, dn2 = dn*dn, sn2 = sn*sn,
423 pii = cn2 != 0 ? fabs(sn) * (
RF(cn2, dn2, 1) +
425 RJ(cn2, dn2, 1, cn2 + _alphap2 * sn2) / 3) :
429 pii = 2 *
Pi() - pii;
430 return copysign(pii, sn);
435 cn2 = cn*cn, dn2 = dn*dn, sn2 = sn*sn,
436 gi = cn2 != 0 ? fabs(sn) * (
RF(cn2, dn2, 1) +
437 (_alpha2 - _k2) * sn2 *
438 RJ(cn2, dn2, 1, cn2 + _alphap2 * sn2) / 3) :
443 return copysign(gi, sn);
448 cn2 = cn*cn, dn2 = dn*dn, sn2 = sn*sn,
450 hi = cn2 != 0 ? fabs(sn) * (
RF(cn2, dn2, 1) -
452 RJ(cn2, dn2, 1, cn2 + _alphap2 * sn2) / 3) :
457 return copysign(hi, sn);
462 if (signbit(cn)) { cn = -cn; sn = -sn; }
463 return F(sn, cn, dn) * (
Math::pi()/2) /
K() - atan2(sn, cn);
468 if (signbit(cn)) { cn = -cn; sn = -sn; }
469 return E(sn, cn, dn) * (
Math::pi()/2) /
E() - atan2(sn, cn);
474 if (signbit(cn)) { cn = -cn; sn = -sn; }
475 return Pi(sn, cn, dn) * (
Math::pi()/2) /
Pi() - atan2(sn, cn);
480 if (signbit(cn)) { cn = -cn; sn = -sn; }
481 return D(sn, cn, dn) * (
Math::pi()/2) /
D() - atan2(sn, cn);
486 if (signbit(cn)) { cn = -cn; sn = -sn; }
487 return G(sn, cn, dn) * (
Math::pi()/2) /
G() - atan2(sn, cn);
492 if (signbit(cn)) { cn = -cn; sn = -sn; }
493 return H(sn, cn, dn) * (
Math::pi()/2) /
H() - atan2(sn, cn);
497 real sn = sin(phi), cn = cos(phi), dn =
Delta(sn, cn);
498 return fabs(phi) <
Math::pi() ?
F(sn, cn, dn) :
503 real sn = sin(phi), cn = cos(phi), dn =
Delta(sn, cn);
504 return fabs(phi) <
Math::pi() ?
E(sn, cn, dn) :
513 return E(sn, cn,
Delta(sn, cn)) + 4 *
E() * n;
517 real sn = sin(phi), cn = cos(phi), dn =
Delta(sn, cn);
518 return fabs(phi) <
Math::pi() ?
Pi(sn, cn, dn) :
523 real sn = sin(phi), cn = cos(phi), dn =
Delta(sn, cn);
524 return fabs(phi) <
Math::pi() ?
D(sn, cn, dn) :
529 real sn = sin(phi), cn = cos(phi), dn =
Delta(sn, cn);
530 return fabs(phi) <
Math::pi() ?
G(sn, cn, dn) :
535 real sn = sin(phi), cn = cos(phi), dn =
Delta(sn, cn);
536 return fabs(phi) <
Math::pi() ?
H(sn, cn, dn) :
541 static const real tolJAC =
542 sqrt(numeric_limits<real>::epsilon() * real(0.01));
543 real n = floor(x / (2 * _eEc) + real(0.5));
546 real phi =
Math::pi() * x / (2 * _eEc);
548 phi -= _eps * sin(2 * phi) / 2;
557 err = (
E(sn, cn, dn) - x)/dn;
559 if (!(fabs(err) > tolJAC))
567 if (signbit(ctau)) { ctau = -ctau; stau = -stau; }
568 real tau = atan2(stau, ctau);
Header for GeographicLib::EllipticFunction class.
#define GEOGRAPHICLIB_PANIC
void sncndn(real x, real &sn, real &cn, real &dn) const
static real RJ(real x, real y, real z, real p)
Math::real deltaG(real sn, real cn, real dn) const
static real RG(real x, real y, real z)
Math::real deltaE(real sn, real cn, real dn) const
Math::real F(real phi) const
static real RC(real x, real y)
Math::real Einv(real x) const
static real RD(real x, real y, real z)
Math::real alphap2() const
void Reset(real k2=0, real alpha2=0)
Math::real Delta(real sn, real cn) const
Math::real deltaD(real sn, real cn, real dn) const
Math::real Ed(real ang) const
Math::real deltaH(real sn, real cn, real dn) const
Math::real deltaF(real sn, real cn, real dn) const
static real RF(real x, real y, real z)
Math::real deltaPi(real sn, real cn, real dn) const
Math::real deltaEinv(real stau, real ctau) const
Math::real alpha2() const
Exception handling for GeographicLib.
static void sincosd(T x, T &sinx, T &cosx)
static T AngNormalize(T x)
Namespace for GeographicLib.
void swap(GeographicLib::NearestNeighbor< dist_t, pos_t, distfun_t > &a, GeographicLib::NearestNeighbor< dist_t, pos_t, distfun_t > &b)