14# pragma warning (disable: 5055)
23 : eps_(numeric_limits<real>::epsilon())
24 , epsx_(
Math::sq(eps_))
25 , ahypover_(
Math::digits() * log(real(numeric_limits<real>::radix)) + 2)
30 , _es((_f < 0 ? -1 : 1) * sqrt(fabs(_e2)))
32 if (!(isfinite(_a) && _a > 0))
34 if (!(isfinite(_f) && _f < 1))
36 if (!(isfinite(k0) && k0 > 0))
40 +
"d, " + to_string(
Math::qd) +
"d]");
43 Init(sphi, cphi, sphi, cphi, k0);
47 real stdlat1, real stdlat2,
49 : eps_(numeric_limits<real>::epsilon())
50 , epsx_(
Math::sq(eps_))
51 , ahypover_(
Math::digits() * log(real(numeric_limits<real>::radix)) + 2)
56 , _es((_f < 0 ? -1 : 1) * sqrt(fabs(_e2)))
58 if (!(isfinite(_a) && _a > 0))
60 if (!(isfinite(_f) && _f < 1))
62 if (!(isfinite(k1) && k1 > 0))
72 real sphi1, cphi1, sphi2, cphi2;
75 Init(sphi1, cphi1, sphi2, cphi2, k1);
79 real sinlat1, real coslat1,
80 real sinlat2, real coslat2,
82 : eps_(numeric_limits<real>::epsilon())
83 , epsx_(
Math::sq(eps_))
84 , ahypover_(
Math::digits() * log(real(numeric_limits<real>::radix)) + 2)
89 , _es((_f < 0 ? -1 : 1) * sqrt(fabs(_e2)))
91 if (!(isfinite(_a) && _a > 0))
93 if (!(isfinite(_f) && _f < 1))
95 if (!(isfinite(k1) && k1 > 0))
101 if (signbit(coslat2))
105 if (!(fabs(sinlat1) <= 1 && coslat1 <= 1) || (coslat1 == 0 && sinlat1 == 0))
106 throw GeographicErr(
"Bad sine/cosine of standard latitude 1");
107 if (!(fabs(sinlat2) <= 1 && coslat2 <= 1) || (coslat2 == 0 && sinlat2 == 0))
108 throw GeographicErr(
"Bad sine/cosine of standard latitude 2");
109 if (coslat1 == 0 || coslat2 == 0)
110 if (!(coslat1 == coslat2 && sinlat1 == sinlat2))
112 (
"Standard latitudes must be equal is either is a pole");
113 Init(sinlat1, coslat1, sinlat2, coslat2, k1);
116 void LambertConformalConic::Init(
real sphi1,
real cphi1,
120 r = hypot(sphi1, cphi1);
121 sphi1 /= r; cphi1 /= r;
122 r = hypot(sphi2, cphi2);
123 sphi2 /= r; cphi2 /= r;
125 bool polar = (cphi1 == 0);
126 cphi1 = fmax(epsx_, cphi1);
127 cphi2 = fmax(epsx_, cphi2);
129 _sign = sphi1 + sphi2 >= 0 ? 1 : -1;
131 sphi1 *= _sign; sphi2 *= _sign;
133 swap(sphi1, sphi2);
swap(cphi1, cphi2);
136 tphi1 = sphi1/cphi1, tphi2 = sphi2/cphi2, tphi0;
156 tbet1 = _fm * tphi1, scbet1 = hyp(tbet1),
157 tbet2 = _fm * tphi2, scbet2 = hyp(tbet2);
160 xi1 =
Math::eatanhe(sphi1, _es), shxi1 = sinh(xi1), chxi1 = hyp(shxi1),
161 tchi1 = chxi1 * tphi1 - shxi1 * scphi1, scchi1 = hyp(tchi1),
163 xi2 =
Math::eatanhe(sphi2, _es), shxi2 = sinh(xi2), chxi2 = hyp(shxi2),
164 tchi2 = chxi2 * tphi2 - shxi2 * scphi2, scchi2 = hyp(tchi2),
166 if (tphi2 - tphi1 != 0) {
170 * Dhyp(tbet2, tbet1, scbet2, scbet1) * _fm;
172 real den = Dasinh(tphi2, tphi1, scphi2, scphi1)
173 - Deatanhe(sphi2, sphi1) * Dsn(tphi2, tphi1, sphi2, sphi1);
177 _nc = sqrt((1 - _n) * (1 + _n));
199 s1 = (tphi1 * (2 * shxi1 * chxi1 * scphi1 - _e2 * tphi1) -
201 s2 = (tphi2 * (2 * shxi2 * chxi2 * scphi2 - _e2 * tphi2) -
204 t1 = tchi1 < 0 ? scbet1 - tchi1 : (s1 + 1)/(scbet1 + tchi1),
205 t2 = tchi2 < 0 ? scbet2 - tchi2 : (s2 + 1)/(scbet2 + tchi2),
206 a2 = -(s2 / (scbet2 + scchi2) + t2) / (2 * scbet2),
207 a1 = -(s1 / (scbet1 + scchi1) + t1) / (2 * scbet1);
208 t = Dlog1p(a2, a1) / den;
211 t *= ( ( (tchi2 >= 0 ? scchi2 + tchi2 : 1/(scchi2 - tchi2)) +
212 (tchi1 >= 0 ? scchi1 + tchi1 : 1/(scchi1 - tchi1)) ) /
213 (4 * scbet1 * scbet2) ) * _fm;
220 real tbm = ( ((tbet1 > 0 ? 1/(scbet1+tbet1) : scbet1 - tbet1) +
221 (tbet2 > 0 ? 1/(scbet2+tbet2) : scbet2 - tbet2)) /
233 dtchi = den / Dasinh(tchi2, tchi1, scchi2, scchi1),
235 dbet = (_e2/_fm) * ( 1 / (scbet2 + _fm * scphi2) +
236 1 / (scbet1 + _fm * scphi1) );
252 shxiZ = sinh(xiZ), chxiZ = hyp(shxiZ),
255 dxiZ1 = Deatanhe(
real(1), sphi1)/(scphi1*(tphi1+scphi1)),
256 dxiZ2 = Deatanhe(
real(1), sphi2)/(scphi2*(tphi2+scphi2)),
257 dshxiZ1 = Dsinh(xiZ, xi1, shxiZ, shxi1, chxiZ, chxi1) * dxiZ1,
258 dshxiZ2 = Dsinh(xiZ, xi2, shxiZ, shxi2, chxiZ, chxi2) * dxiZ2,
259 dchxiZ1 = Dhyp(shxiZ, shxi1, chxiZ, chxi1) * dshxiZ1,
260 dchxiZ2 = Dhyp(shxiZ, shxi2, chxiZ, chxi2) * dshxiZ2,
262 amu12 = (- scphi1 * dchxiZ1 + tphi1 * dshxiZ1
263 - scphi2 * dchxiZ2 + tphi2 * dshxiZ2),
265 dxi = Deatanhe(sphi1, sphi2) * Dsn(tphi2, tphi1, sphi2, sphi1),
268 ( (_f * 4 * scphi2 * dshxiZ2 > _f * scphi1 * dshxiZ1 ?
270 (dshxiZ1 + dshxiZ2)/2 * Dhyp(tphi1, tphi2, scphi1, scphi2)
271 - ( (scphi1 + scphi2)/2
272 * Dsinh(xi1, xi2, shxi1, shxi2, chxi1, chxi2) * dxi ) :
274 (scphi2 * dshxiZ2 - scphi1 * dshxiZ1)/(tphi2 - tphi1))
275 + ( (tphi1 + tphi2)/2 * Dhyp(shxi1, shxi2, chxi1, chxi2)
276 * Dsinh(xi1, xi2, shxi1, shxi2, chxi1, chxi2) * dxi )
277 - (dchxiZ1 + dchxiZ2)/2 ),
279 dchia = (amu12 - dnu12 * (scphi2 + scphi1)),
280 tam = (dchia - dtchi * dbet) / (scchi1 + scchi2);
282 _nc = sqrt(fmax(
real(0), t) * (1 + _n));
285 real r = hypot(_n, _nc);
298 _scbet0 = hyp(_fm * tphi0);
300 _tchi0 = tphi0 * hyp(shxi0) - shxi0 * hyp(tphi0); _scchi0 = hyp(_tchi0);
301 _psi0 = asinh(_tchi0);
304 _t0nm1 = expm1(- _n * _psi0);
307 _scale = _a * k1 / scbet1 *
310 exp( - (
Math::sq(_nc)/(1 + _n)) * psi1 )
311 * (tchi1 >= 0 ? scchi1 + tchi1 : 1 / (scchi1 - tchi1));
315 _k0 = k1 * (_scbet0/scbet1) *
317 Dasinh(tchi1, _tchi0, scchi1, _scchi0) * (tchi1 - _tchi0))
318 * (tchi1 >= 0 ? scchi1 + tchi1 : 1 / (scchi1 - tchi1)) /
320 _nrho0 = polar ? 0 : _a * _k0 / _scbet0;
324 sphi = -1, cphi = epsx_,
327 tchi = hyp(shxi) * tphi - shxi * scphi, scchi = hyp(tchi),
329 dpsi = Dasinh(tchi, _tchi0, scchi, _scchi0) * (tchi - _tchi0);
330 _drhomax = - _scale * (2 * _nc < 1 && dpsi != 0 ?
331 (exp(
Math::sq(_nc)/(1 + _n) * psi ) *
332 (tchi > 0 ? 1/(scchi + tchi) : (scchi - tchi))
333 - (_t0nm1 + 1))/(-_n) :
334 Dexp(-_n * psi, -_n * _psi0) * dpsi);
347 real& gamma, real& k)
const {
361 cphi = fmax(epsx_, cphi);
364 tphi = sphi/cphi, scbet = hyp(_fm * tphi),
366 tchi = hyp(shxi) * tphi - shxi * scphi, scchi = hyp(tchi),
368 theta = _n * lam, stheta = sin(theta), ctheta = cos(theta),
369 dpsi = Dasinh(tchi, _tchi0, scchi, _scchi0) * (tchi - _tchi0),
370 drho = - _scale * (2 * _nc < 1 && dpsi != 0 ?
371 (exp(
Math::sq(_nc)/(1 + _n) * psi ) *
372 (tchi > 0 ? 1/(scchi + tchi) : (scchi - tchi))
373 - (_t0nm1 + 1))/(-_n) :
374 Dexp(-_n * psi, -_n * _psi0) * dpsi);
375 x = (_nrho0 + _n * drho) * (_n != 0 ? stheta / _n : lam);
378 (ctheta < 0 ? 1 - ctheta :
Math::sq(stheta)/(1 + ctheta)) / _n : 0)
380 k = _k0 * (scbet/_scbet0) /
381 (exp( - (
Math::sq(_nc)/(1 + _n)) * dpsi )
382 * (tchi >= 0 ? scchi + tchi : 1 / (scchi - tchi)) / (_scchi0 + _tchi0));
388 real& lat, real& lon,
389 real& gamma, real& k)
const {
405 nx = _n * x, ny = _n != 0 ? _n * y : 0, y1 = _nrho0 - ny,
406 den = hypot(nx, y1) + _nrho0,
408 drho = ((den != 0 && isfinite(den))
409 ? (x*nx + y * (ny - 2*_nrho0)) / den
411 drho = fmin(drho, _drhomax);
413 drho = fmax(drho, -_drhomax);
415 tnm1 = _t0nm1 + _n * drho/_scale,
416 dpsi = (den == 0 ? 0 :
417 (tnm1 + 1 != 0 ? - Dlog1p(tnm1, _t0nm1) * drho / _scale :
423 psi = _psi0 + dpsi, tchia = sinh(psi), scchi = hyp(tchia),
424 dtchi = Dsinh(psi, _psi0, tchia, _tchi0, scchi, _scchi0) * dpsi;
425 tchi = _tchi0 + dtchi;
434 tn = tnm1 + 1 == 0 ? epsx_ : tnm1 + 1,
435 sh = sinh( -
Math::sq(_nc)/(_n * (1 + _n)) *
436 (2 * tn > 1 ? log1p(tnm1) : log(tn)) );
437 tchi = sh * (tn + 1/tn)/2 - hyp(sh) * (tnm1 * (tn + 1)/tn)/2;
441 gamma = atan2(nx, y1);
444 scbet = hyp(_fm * tphi), scchi = hyp(tchi),
445 lam = _n != 0 ? gamma / _n : x / y1;
449 k = _k0 * (scbet/_scbet0) /
450 (exp(_nc != 0 ? - (
Math::sq(_nc)/(1 + _n)) * dpsi : 0)
451 * (tchi >= 0 ? scchi + tchi : 1 / (scchi - tchi)) / (_scchi0 + _tchi0));
456 if (!(isfinite(k) && k > 0))
462 if (fabs(lat) ==
Math::qd && !(_nc == 0 && lat * _n > 0))
463 throw GeographicErr(
"Incompatible polar latitude in SetScale");
464 real x, y, gamma, kold;
465 Forward(0, lat, 0, x, y, gamma, kold);
GeographicLib::Math::real real
Exception handling for GeographicLib.
Mathematical functions needed by GeographicLib.
static void sincosd(T x, T &sinx, T &cosx)
static T tauf(T taup, T es)
static T AngNormalize(T x)
static T AngDiff(T x, T y, T &e)
static T eatanhe(T x, T es)
@ qd
degrees per quarter turn
Namespace for GeographicLib.
void swap(GeographicLib::NearestNeighbor< dist_t, pos_t, distfun_t > &a, GeographicLib::NearestNeighbor< dist_t, pos_t, distfun_t > &b)