48# pragma warning (disable: 4127 5055)
57 : tol_(numeric_limits<real>::epsilon())
58 , tol2_(real(0.1) * tol_)
59 , taytol_(pow(tol_, real(0.6)))
70 if (!(isfinite(_a) && _a > 0))
76 if (!(isfinite(_k0) && _k0 > 0))
96 overflow = 1 /
Math::sq(numeric_limits<real>::epsilon());
100 t1 = (d1 != 0 ? snu * dnv / d1 : (signbit(snu) ? -overflow : overflow)),
101 t2 = (d2 != 0 ? sinh( _e * asinh(_e * snu / d2) ) :
102 (signbit(snu) ? -overflow : overflow));
105 taup = t1 * hypot(
real(1), t2) - t2 * hypot(
real(1), t1);
106 lam = (d1 != 0 && d2 != 0) ?
107 atan2(dnu * snv, cnu * cnv) - _e * atan2(_e * cnu * snv, dnu * cnv) :
111 void TransverseMercatorExact::dwdzeta(
real ,
124 bool TransverseMercatorExact::zetainv0(
real psi,
real lam,
128 lam > (1 - 2 * _e) *
Math::pi()/2 &&
129 psi < lam - (1 - _e) *
Math::pi()/2) {
142 u = asinh(sin(lamx) / hypot(cos(lamx), sinh(psix))) *
144 v = atan2(cos(lamx), sinh(psix)) * (1 + _mu/2);
147 }
else if (psi < _e *
Math::pi()/2 &&
148 lam > (1 - 2 * _e) *
Math::pi()/2) {
161 dlam = lam - (1 - _e) *
Math::pi()/2,
162 rad = hypot(psi, dlam),
168 ang = atan2(dlam-psi, psi+dlam) -
real(0.75) *
Math::pi();
170 retval = rad < _e * taytol_;
171 rad = cbrt(3 / (_mv * _e) * rad);
174 v = rad * sin(ang) + _eEv.
K();
179 v = asinh(sin(lam) / hypot(cos(lam), sinh(psi)));
180 u = atan2(sinh(psi), cos(lam));
189 void TransverseMercatorExact::zetainv(
real taup,
real lam,
193 scal = 1/hypot(
real(1), taup);
194 if (zetainv0(psi, lam, u, v))
199 real snu, cnu, dnu, snv, cnv, dnv;
200 _eEu.
sncndn(u, snu, cnu, dnu);
201 _eEv.
sncndn(v, snv, cnv, dnv);
202 real tau1, lam1, du1, dv1;
203 zeta(u, snu, cnu, dnu, v, snv, cnv, dnv, tau1, lam1);
204 dwdzeta(u, snu, cnu, dnu, v, snv, cnv, dnv, du1, dv1);
209 delu = tau1 * du1 - lam1 * dv1,
210 delv = tau1 * dv1 + lam1 * du1;
216 if (!(delw2 >= stol2))
227 xi = _eEu.
E(snu, cnu, dnu) - _mu * snu * cnu * dnu / d;
228 eta = v - _eEv.
E(snv, cnv, dnv) + _mv * snv * cnv * dnv / d;
231 void TransverseMercatorExact::dwdsigma(
real ,
240 dnr = dnu * cnv * dnv,
241 dni = - _mu * snu * cnu * snv;
243 dv = 2 * dnr * dni / d;
247 bool TransverseMercatorExact::sigmainv0(
real xi,
real eta,
250 if (eta >
real(1.25) * _eEv.
KE() ||
251 (xi < -
real(0.25) * _eEu.
E() && xi < eta - _eEv.
KE())) {
262 }
else if ((eta >
real(0.75) * _eEv.
KE() && xi <
real(0.25) * _eEu.
E())
263 || eta > _eEv.
KE()) {
277 deta = eta - _eEv.
KE(),
278 rad = hypot(xi, deta),
281 ang = atan2(deta-xi, xi+deta) -
real(0.75) *
Math::pi();
283 retval = rad < 2 * taytol_;
284 rad = cbrt(3 / _mv * rad);
287 v = rad * sin(ang) + _eEv.
K();
290 u = xi * _eEu.
K()/_eEu.
E();
291 v = eta * _eEu.
K()/_eEu.
E();
297 void TransverseMercatorExact::sigmainv(
real xi,
real eta,
299 if (sigmainv0(xi, eta, u, v))
303 real snu, cnu, dnu, snv, cnv, dnv;
304 _eEu.
sncndn(u, snu, cnu, dnu);
305 _eEv.
sncndn(v, snv, cnv, dnv);
306 real xi1, eta1, du1, dv1;
307 sigma(u, snu, cnu, dnu, v, snv, cnv, dnv, xi1, eta1);
308 dwdsigma(u, snu, cnu, dnu, v, snv, cnv, dnv, du1, dv1);
312 delu = xi1 * du1 - eta1 * dv1,
313 delv = xi1 * dv1 + eta1 * du1;
319 if (!(delw2 >= tol2_))
324 void TransverseMercatorExact::Scale(
real tau,
real ,
331 gamma = atan2(_mv * snu * snv * cnv, cnu * dnu * dnv);
345 k = sqrt(_mv + _mu / sec2) * sqrt(sec2) *
352 real& gamma, real& k)
const {
357 latsign = (!_extendp && signbit(lat)) ? -1 : 1,
358 lonsign = (!_extendp && signbit(lon)) ? -1 : 1;
361 bool backside = !_extendp && lon >
Math::qd;
376 }
else if (lat == 0 && lon ==
Math::qd * (1 - _e)) {
383 real snu, cnu, dnu, snv, cnv, dnv;
384 _eEu.
sncndn(u, snu, cnu, dnu);
385 _eEv.
sncndn(v, snv, cnv, dnv);
388 sigma(u, snu, cnu, dnu, v, snv, cnv, dnv, xi, eta);
390 xi = 2 * _eEu.
E() - xi;
391 y = xi * _a * _k0 * latsign;
392 x = eta * _a * _k0 * lonsign;
399 zeta(u, snu, cnu, dnu, v, snv, cnv, dnv, tau, lam);
401 Scale(tau, lam, snu, cnu, dnu, snv, cnv, dnv, gamma, k);
406 gamma *= latsign * lonsign;
411 real& lat, real& lon,
412 real& gamma, real& k)
const {
416 eta = x / (_a * _k0);
419 xisign = (!_extendp && signbit(xi)) ? -1 : 1,
420 etasign = (!_extendp && signbit(eta)) ? -1 : 1;
423 bool backside = !_extendp && xi > _eEu.
E();
425 xi = 2 * _eEu.
E()- xi;
429 if (xi == 0 && eta == _eEv.
KE()) {
433 sigmainv(xi, eta, u, v);
435 real snu, cnu, dnu, snv, cnv, dnv;
436 _eEu.
sncndn(u, snu, cnu, dnu);
437 _eEv.
sncndn(v, snv, cnv, dnv);
439 if (v != 0 || u != _eEu.
K()) {
440 zeta(u, snu, cnu, dnu, v, snv, cnv, dnv, tau, lam);
445 Scale(tau, lam, snu, cnu, dnu, snv, cnv, dnv, gamma, k);
449 lon = lam = gamma = 0;
460 gamma *= xisign * etasign;
GeographicLib::Math::real real
#define GEOGRAPHICLIB_PANIC
Header for GeographicLib::TransverseMercatorExact class.
void sncndn(real x, real &sn, real &cn, real &dn) const
Exception handling for GeographicLib.
static T tauf(T taup, T es)
static T AngNormalize(T x)
static T taupf(T tau, T es)
static T AngDiff(T x, T y, T &e)
@ hd
degrees per half turn
@ qd
degrees per quarter turn
An exact implementation of the transverse Mercator projection.
void Forward(real lon0, real lat, real lon, real &x, real &y, real &gamma, real &k) const
TransverseMercatorExact(real a, real f, real k0, bool extendp=false)
static const TransverseMercatorExact & UTM()
void Reverse(real lon0, real x, real y, real &lat, real &lon, real &gamma, real &k) const
Namespace for GeographicLib.