17 : eps_(numeric_limits<real>::epsilon())
18 , epsx_(
Math::sq(eps_))
19 , epsx2_(
Math::sq(epsx_))
21 , tol0_(tol_ * sqrt(sqrt(eps_)))
28 , _qZ(1 + _e2m * atanhee(real(1)))
29 , _qx(_qZ / ( 2 * _e2m ))
31 if (!(isfinite(_a) && _a > 0))
33 if (!(isfinite(_f) && _f < 1))
35 if (!(isfinite(k0) && k0 > 0))
39 +
"d, " + to_string(
Math::qd) +
"d]");
42 Init(sphi, cphi, sphi, cphi, k0);
47 : eps_(numeric_limits<real>::epsilon())
48 , epsx_(
Math::sq(eps_))
49 , epsx2_(
Math::sq(epsx_))
51 , tol0_(tol_ * sqrt(sqrt(eps_)))
58 , _qZ(1 + _e2m * atanhee(real(1)))
59 , _qx(_qZ / ( 2 * _e2m ))
61 if (!(isfinite(_a) && _a > 0))
63 if (!(isfinite(_f) && _f < 1))
65 if (!(isfinite(k1) && k1 > 0))
75 real sphi1, cphi1, sphi2, cphi2;
78 Init(sphi1, cphi1, sphi2, cphi2, k1);
82 real sinlat1, real coslat1,
83 real sinlat2, real coslat2,
85 : eps_(numeric_limits<real>::epsilon())
86 , epsx_(
Math::sq(eps_))
87 , epsx2_(
Math::sq(epsx_))
89 , tol0_(tol_ * sqrt(sqrt(eps_)))
96 , _qZ(1 + _e2m * atanhee(real(1)))
97 , _qx(_qZ / ( 2 * _e2m ))
99 if (!(isfinite(_a) && _a > 0))
101 if (!(isfinite(_f) && _f < 1))
103 if (!(isfinite(k1) && k1 > 0))
105 if (signbit(coslat1))
109 if (signbit(coslat2))
113 if (!(fabs(sinlat1) <= 1 && coslat1 <= 1) || (coslat1 == 0 && sinlat1 == 0))
114 throw GeographicErr(
"Bad sine/cosine of standard latitude 1");
115 if (!(fabs(sinlat2) <= 1 && coslat2 <= 1) || (coslat2 == 0 && sinlat2 == 0))
116 throw GeographicErr(
"Bad sine/cosine of standard latitude 2");
117 if (coslat1 == 0 && coslat2 == 0 && sinlat1 * sinlat2 <= 0)
119 (
"Standard latitudes cannot be opposite poles");
120 Init(sinlat1, coslat1, sinlat2, coslat2, k1);
123 void AlbersEqualArea::Init(
real sphi1,
real cphi1,
127 r = hypot(sphi1, cphi1);
128 sphi1 /= r; cphi1 /= r;
129 r = hypot(sphi2, cphi2);
130 sphi2 /= r; cphi2 /= r;
132 bool polar = (cphi1 == 0);
133 cphi1 = fmax(epsx_, cphi1);
134 cphi2 = fmax(epsx_, cphi2);
136 _sign = sphi1 + sphi2 >= 0 ? 1 : -1;
138 sphi1 *= _sign; sphi2 *= _sign;
140 swap(sphi1, sphi2); swap(cphi1, cphi2);
143 tphi1 = sphi1/cphi1, tphi2 = sphi2/cphi2;
168 if (polar || tphi1 == tphi2) {
173 tbet1 = _fm * tphi1, scbet12 = 1 +
Math::sq(tbet1),
174 tbet2 = _fm * tphi2, scbet22 = 1 +
Math::sq(tbet2),
175 txi1 = txif(tphi1), cxi1 = 1/hyp(txi1), sxi1 = txi1 * cxi1,
176 txi2 = txif(tphi2), cxi2 = 1/hyp(txi2), sxi2 = txi2 * cxi2,
177 dtbet2 = _fm * (tbet1 + tbet2),
184 dsxi = ( (1 + _e2 * sphi1 * sphi2) / (es2 * es1) +
185 Datanhee(sphi2, sphi1) ) * Dsn(tphi2, tphi1, sphi2, sphi1) /
187 den = (sxi2 + sxi1) * dtbet2 + (scbet22 + scbet12) * dsxi,
189 s = 2 * dtbet2 / den,
194 sm1 = -Dsn(tphi2, tphi1, sphi2, sphi1) *
195 ( -( ((sphi2 <= 0 ? (1 - sxi2) / (1 - sphi2) :
196 Math::sq(cxi2/cphi2) * (1 + sphi2) / (1 + sxi2)) +
197 (sphi1 <= 0 ? (1 - sxi1) / (1 - sphi1) :
198 Math::sq(cxi1/cphi1) * (1 + sphi1) / (1 + sxi1))) ) *
199 (1 + _e2 * (sphi1 + sphi2 + sphi1 * sphi2)) /
200 (1 + (sphi1 + sphi2 + sphi1 * sphi2)) +
201 (scbet22 * (sphi2 <= 0 ? 1 - sphi2 :
202 Math::sq(cphi2) / ( 1 + sphi2)) +
203 scbet12 * (sphi1 <= 0 ? 1 - sphi1 : Math::sq(cphi1) / ( 1 + sphi1)))
204 * (_e2 * (1 + sphi1 + sphi2 + _e2 * sphi1 * sphi2)/(es1 * es2)
205 +_e2m * DDatanhee(sphi1, sphi2) ) / _qZ ) / den;
207 C = den / (2 * scbet12 * scbet22 * dsxi);
208 tphi0 = (tphi2 + tphi1)/2;
209 real stol = tol0_ * fmax(
real(1), fabs(tphi0));
247 scphi02 = 1 +
Math::sq(tphi0), scphi0 = sqrt(scphi02),
249 sphi0 = tphi0 / scphi0, sphi0m = 1/(scphi0 * (tphi0 + scphi0)),
251 g = (1 +
Math::sq( _fm * tphi0 )) * sphi0,
253 dg = _e2m * scphi02 * (1 + 2 *
Math::sq(tphi0)) + _e2,
254 D = sphi0m * (1 - _e2*(1 + 2*sphi0*(1+sphi0))) / (_e2m * (1+sphi0)),
256 dD = -2 * (1 - _e2*
Math::sq(sphi0) * (2*sphi0+3)) /
258 A = -_e2 *
Math::sq(sphi0m) * (2+(1+_e2)*sphi0) /
260 B = (sphi0m * _e2m / (1 - _e2*sphi0) *
262 Math::sq(sphi0m / (1-_e2*sphi0))) - _e2*sphi0m/_e2m)),
264 dAB = (2 * _e2 * (2 - _e2 * (1 +
Math::sq(sphi0))) /
266 u = sm1 * g - s/_qZ * ( D - g * (A + B) ),
268 du = sm1 * dg - s/_qZ * (dD - dg * (A + B) - g * dAB),
269 dtu = -u/du * (scphi0 * scphi02);
271 if (!(fabs(dtu) >= stol))
275 _txi0 = txif(tphi0); _scxi0 = hyp(_txi0); _sxi0 = _txi0 / _scxi0;
276 _n0 = tphi0/hyp(tphi0);
277 _m02 = 1 / (1 +
Math::sq(_fm * tphi0));
278 _nrho0 = polar ? 0 : _a * sqrt(_m02);
279 _k0 = sqrt(tphi1 == tphi2 ? 1 : C / (_m02 + _n0 * _qZ * _sxi0)) * k1;
287 real(0), real(1), real(0), real(1), real(1));
288 return cylindricalequalarea;
294 real(1), real(0), real(1), real(0), real(1));
295 return azimuthalequalareanorth;
301 real(-1), real(0), real(-1), real(0), real(1));
302 return azimuthalequalareasouth;
321 cphi = 1 / sqrt(1 +
Math::sq(tphi)),
324 es2m1 = 1 - es1 * sphi,
325 es2m1a = _e2m * es2m1;
326 return ( tphi / es2m1 + atanhee(sphi) / cphi ) /
327 sqrt( ( (1 + es1) / es2m1a + Datanhee(1, sphi) ) *
328 ( (1 - es1) / es2m1a + Datanhee(1, -sphi) ) );
334 stol = tol_ * fmax(
real(1), fabs(txi));
345 scterm = scphi2/(1 +
Math::sq(txia)),
346 dtphi = (txi - txia) * scterm * sqrt(scterm) *
347 _qx *
Math::sq(1 - _e2 * tphi2 / scphi2);
349 if (!(fabs(dtphi) >= stol))
359 if (fabs(x) <
real(0.5)) {
360 static const real lg2eps_ = -log2(numeric_limits<real>::epsilon() / 2);
369 int n = x == 0 ? 1 : int(ceil(lg2eps_ / e)) + 1;
373 real xs = sqrt(fabs(x));
374 s = (x > 0 ? atanh(xs) : atan(xs)) / xs - 1;
383 if (y < x) swap(x, y);
385 q2 = fabs(2 * _e / _e2m * (1 - x));
387 x <= 0 || !(fmin(q1, q2) <
real(0.75)) ? DDatanhee0(x, y) :
388 (q1 < q2 ? DDatanhee1(x, y) : DDatanhee2(x, y));
394 return (Datanhee(1, y) - Datanhee(x, y))/(1 - x);
413 real z = 1, k = 1, t = 0, c = 0, en = 1;
415 t = y * t + z; c += t; z *= x;
416 t = y * t + z; c += t; z *= x;
422 real ds = en * c / k;
424 if (!(fabs(ds) > fabs(s) * eps_/2))
467 real s, dx = 1 - x, dy = 1 - y, xy = 1, yy = 1, ee = _e2 /
Math::sq(_e2m);
469 for (
int m = 1; ; ++m) {
470 real c = m + 2, t = c;
477 if (m % 2 == 0) ee *= _e2;
480 for (
int k = kmax - 1; k >= 0; --k) {
482 c *= (k + 1) * (2 * (k + m - 2*kmax) + 3);
483 c /= (kmax - k) * (2 * (kmax - k) + 1);
488 real ds = t * ee * xy / (m + 2);
490 if (!(fabs(ds) > fabs(s) * eps_/2))
497 real& x, real& y, real& gamma, real& k)
const {
502 cphi = fmax(epsx_, cphi);
505 tphi = sphi/cphi, txi = txif(tphi), sxi = txi/hyp(txi),
506 dq = _qZ * Dsn(txi, _txi0, sxi, _sxi0) * (txi - _txi0),
507 drho = - _a * dq / (sqrt(_m02 - _n0 * dq) + _nrho0 / _a),
508 theta = _k2 * _n0 * lam, stheta = sin(theta), ctheta = cos(theta),
509 t = _nrho0 + _n0 * drho;
510 x = t * (_n0 != 0 ? stheta / _n0 : _k2 * lam) / _k0;
513 (ctheta < 0 ? 1 - ctheta :
Math::sq(stheta)/(1 + ctheta)) / _n0 :
515 - drho * ctheta) / _k0;
516 k = _k0 * (t != 0 ? t * hyp(_fm * tphi) / _a : 1);
522 real& lat, real& lon,
523 real& gamma, real& k)
const {
526 nx = _k0 * _n0 * x, ny = _k0 * _n0 * y, y1 = _nrho0 - ny,
527 den = hypot(nx, y1) + _nrho0,
528 drho = den != 0 ? (_k0*x*nx - 2*_k0*y*_nrho0 + _k0*y*ny) / den : 0,
530 dsxia = - _scxi0 * (2 * _nrho0 + _n0 * drho) * drho /
532 txi = (_txi0 + dsxia) / sqrt(fmax(1 - dsxia * (2*_txi0 + dsxia), epsx2_)),
534 theta = atan2(nx, y1),
535 lam = _n0 != 0 ? theta / (_k2 * _n0) : x / (y1 * _k0);
540 k = _k0 * (den != 0 ? (_nrho0 + _n0 * drho) * hyp(_fm * tphi) / _a : 1);
544 if (!(isfinite(k) && k > 0))
550 real x, y, gamma, kold;
551 Forward(0, lat, 0, x, y, gamma, kold);
Header for GeographicLib::AlbersEqualArea class.
GeographicLib::Math::real real
#define GEOGRAPHICLIB_PANIC(msg)
Albers equal area conic projection.
void Reverse(real lon0, real x, real y, real &lat, real &lon, real &gamma, real &k) const
AlbersEqualArea(real a, real f, real stdlat, real k0)
void SetScale(real lat, real k=real(1))
static const AlbersEqualArea & CylindricalEqualArea()
static const AlbersEqualArea & AzimuthalEqualAreaNorth()
static const AlbersEqualArea & AzimuthalEqualAreaSouth()
void Forward(real lon0, real lat, real lon, real &x, real &y, real &gamma, real &k) const
Exception handling for GeographicLib.
Mathematical functions needed by GeographicLib.
static void sincosd(T x, T &sinx, T &cosx)
static constexpr int qd
degrees per quarter turn
static T AngNormalize(T x)
static T AngDiff(T x, T y, T &e)
Namespace for GeographicLib.