diff options
| author | Charles Karney <charles@karney.com> | 2020-11-01 06:53:02 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-01 06:53:02 -0500 |
| commit | cccd65e50d1143a1119afedae97cec5a6b9397e9 (patch) | |
| tree | 4e5af1fb8faab2c049d065a2d6d1e5e473321196 /src/tsfn.cpp | |
| parent | b7bf499b8449a61cdc24dcdaa0bf035f57af1b3c (diff) | |
| parent | 692fc26b6d494aeaa85658314bc020a5cd6da7a1 (diff) | |
| download | PROJ-cccd65e50d1143a1119afedae97cec5a6b9397e9.tar.gz PROJ-cccd65e50d1143a1119afedae97cec5a6b9397e9.zip | |
Merge pull request #2397 from cffk/merc-update
Update Mercator projection, more accurate, faster
Diffstat (limited to 'src/tsfn.cpp')
| -rw-r--r-- | src/tsfn.cpp | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/src/tsfn.cpp b/src/tsfn.cpp index 32da09f2..8ed258d6 100644 --- a/src/tsfn.cpp +++ b/src/tsfn.cpp @@ -4,14 +4,28 @@ #include "proj_internal.h" double pj_tsfn(double phi, double sinphi, double e) { - double denominator; - sinphi *= e; + /**************************************************************************** + * Determine function ts(phi) defined in Snyder (1987), Eq. (7-10) + * Inputs: + * phi = geographic latitude (radians) + * e = eccentricity of the ellipsoid (dimensionless) + * Output: + * ts = exp(-psi) where psi is the isometric latitude (dimensionless) + * = 1 / (tan(chi) + sec(chi)) + * Here isometric latitude is defined by + * psi = log( tan(pi/4 + phi/2) * + * ( (1 - e*sin(phi)) / (1 + e*sin(phi)) )^(e/2) ) + * = asinh(tan(phi)) - e * atanh(e * sin(phi)) + * = asinh(tan(chi)) + * chi = conformal latitude + ***************************************************************************/ - /* avoid zero division, fail gracefully */ - denominator = 1.0 + sinphi; - if (denominator == 0.0) - return HUGE_VAL; - - return (tan (.5 * (M_HALFPI - phi)) / - pow((1. - sinphi) / (denominator), .5 * e)); + double cosphi = cos(phi); + // exp(-asinh(tan(phi))) = 1 / (tan(phi) + sec(phi)) + // = cos(phi) / (1 + sin(phi)) good for phi > 0 + // = (1 - sin(phi)) / cos(phi) good for phi < 0 + return exp(e * atanh(e * sinphi)) * + ( sinphi > 0 ? + cosphi / (1 + sinphi) : + (1 - sinphi) / cosphi ); } |
