00001 /** 00002 * \file TransverseMercatorExact.hpp 00003 * \brief Header for GeographicLib::TransverseMercatorExact class 00004 * 00005 * Copyright (c) Charles Karney (2008-2014) <charles@karney.com> and licensed 00006 * under the MIT/X11 License. For more information, see 00007 * http://geographiclib.sourceforge.net/ 00008 **********************************************************************/ 00009 00010 #if !defined(GEOGRAPHICLIB_TRANSVERSEMERCATOREXACT_HPP) 00011 #define GEOGRAPHICLIB_TRANSVERSEMERCATOREXACT_HPP 1 00012 00013 #include <GeographicLib/Constants.hpp> 00014 #include <GeographicLib/EllipticFunction.hpp> 00015 00016 namespace GeographicLib { 00017 00018 /** 00019 * \brief An exact implementation of the transverse Mercator projection 00020 * 00021 * Implementation of the Transverse Mercator Projection given in 00022 * - L. P. Lee, 00023 * <a href="http://dx.doi.org/10.3138/X687-1574-4325-WM62"> Conformal 00024 * Projections Based On Jacobian Elliptic Functions</a>, Part V of 00025 * Conformal Projections Based on Elliptic Functions, 00026 * (B. V. Gutsell, Toronto, 1976), 128pp., 00027 * ISBN: 0919870163 00028 * (also appeared as: 00029 * Monograph 16, Suppl. No. 1 to Canadian Cartographer, Vol 13). 00030 * - C. F. F. Karney, 00031 * <a href="http://dx.doi.org/10.1007/s00190-011-0445-3"> 00032 * Transverse Mercator with an accuracy of a few nanometers,</a> 00033 * J. Geodesy 85(8), 475--485 (Aug. 2011); 00034 * preprint 00035 * <a href="http://arxiv.org/abs/1002.1417">arXiv:1002.1417</a>. 00036 * 00037 * Lee gives the correct results for forward and reverse transformations 00038 * subject to the branch cut rules (see the description of the \e extendp 00039 * argument to the constructor). The maximum error is about 8 nm (8 00040 * nanometers), ground distance, for the forward and reverse transformations. 00041 * The error in the convergence is 2 × 10<sup>−15</sup>", 00042 * the relative error in the scale is 7 × 10<sup>−12</sup>%%. 00043 * See Sec. 3 of 00044 * <a href="http://arxiv.org/abs/1002.1417">arXiv:1002.1417</a> for details. 00045 * The method is "exact" in the sense that the errors are close to the 00046 * round-off limit and that no changes are needed in the algorithms for them 00047 * to be used with reals of a higher precision. Thus the errors using long 00048 * double (with a 64-bit fraction) are about 2000 times smaller than using 00049 * double (with a 53-bit fraction). 00050 * 00051 * This algorithm is about 4.5 times slower than the 6th-order Krüger 00052 * method, TransverseMercator, taking about 11 us for a combined forward and 00053 * reverse projection on a 2.66 GHz Intel machine (g++, version 4.3.0, -O3). 00054 * 00055 * The ellipsoid parameters and the central scale are set in the constructor. 00056 * The central meridian (which is a trivial shift of the longitude) is 00057 * specified as the \e lon0 argument of the TransverseMercatorExact::Forward 00058 * and TransverseMercatorExact::Reverse functions. The latitude of origin is 00059 * taken to be the equator. See the documentation on TransverseMercator for 00060 * how to include a false easting, false northing, or a latitude of origin. 00061 * 00062 * See <a href="http://geographiclib.sourceforge.net/tm-grid.kmz" 00063 * type="application/vnd.google-earth.kmz"> tm-grid.kmz</a>, for an 00064 * illustration of the transverse Mercator grid in Google Earth. 00065 * 00066 * See TransverseMercatorExact.cpp for more information on the 00067 * implementation. 00068 * 00069 * See \ref transversemercator for a discussion of this projection. 00070 * 00071 * Example of use: 00072 * \include example-TransverseMercatorExact.cpp 00073 * 00074 * <a href="TransverseMercatorProj.1.html">TransverseMercatorProj</a> is a 00075 * command-line utility providing access to the functionality of 00076 * TransverseMercator and TransverseMercatorExact. 00077 **********************************************************************/ 00078 00079 class GEOGRAPHICLIB_EXPORT TransverseMercatorExact { 00080 private: 00081 typedef Math::real real; 00082 static const int numit_ = 10; 00083 real tol_, tol1_, tol2_, taytol_; 00084 real _a, _f, _k0, _mu, _mv, _e; 00085 bool _extendp; 00086 EllipticFunction _Eu, _Ev; 00087 static inline real overflow() { 00088 // Overflow value s.t. atan(overflow_) = pi/2 00089 static const real 00090 overflow = 1 / Math::sq(std::numeric_limits<real>::epsilon()); 00091 return overflow; 00092 } 00093 // tan(x) for x in [-pi/2, pi/2] ensuring that the sign is right 00094 static inline real tanx(real x) { 00095 using std::tan; 00096 real t = tan(x); 00097 // Write the tests this way to ensure that tanx(NaN()) is NaN() 00098 return x >= 0 ? 00099 (!(t < 0) ? t : overflow()) : 00100 (!(t >= 0) ? t : -overflow()); 00101 } 00102 00103 real taup(real tau) const; 00104 real taupinv(real taup) const; 00105 00106 void zeta(real u, real snu, real cnu, real dnu, 00107 real v, real snv, real cnv, real dnv, 00108 real& taup, real& lam) const; 00109 00110 void dwdzeta(real u, real snu, real cnu, real dnu, 00111 real v, real snv, real cnv, real dnv, 00112 real& du, real& dv) const; 00113 00114 bool zetainv0(real psi, real lam, real& u, real& v) const; 00115 void zetainv(real taup, real lam, real& u, real& v) const; 00116 00117 void sigma(real u, real snu, real cnu, real dnu, 00118 real v, real snv, real cnv, real dnv, 00119 real& xi, real& eta) const; 00120 00121 void dwdsigma(real u, real snu, real cnu, real dnu, 00122 real v, real snv, real cnv, real dnv, 00123 real& du, real& dv) const; 00124 00125 bool sigmainv0(real xi, real eta, real& u, real& v) const; 00126 void sigmainv(real xi, real eta, real& u, real& v) const; 00127 00128 void Scale(real tau, real lam, 00129 real snu, real cnu, real dnu, 00130 real snv, real cnv, real dnv, 00131 real& gamma, real& k) const; 00132 00133 public: 00134 00135 /** 00136 * Constructor for a ellipsoid with 00137 * 00138 * @param[in] a equatorial radius (meters). 00139 * @param[in] f flattening of ellipsoid. If \e f > 1, set flattening 00140 * to 1/\e f. 00141 * @param[in] k0 central scale factor. 00142 * @param[in] extendp use extended domain. 00143 * @exception GeographicErr if \e a, \e f, or \e k0 is not positive. 00144 * 00145 * The transverse Mercator projection has a branch point singularity at \e 00146 * lat = 0 and \e lon − \e lon0 = 90 (1 − \e e) or (for 00147 * TransverseMercatorExact::UTM) x = 18381 km, y = 0m. The \e extendp 00148 * argument governs where the branch cut is placed. With \e extendp = 00149 * false, the "standard" convention is followed, namely the cut is placed 00150 * along \e x > 18381 km, \e y = 0m. Forward can be called with any \e lat 00151 * and \e lon then produces the transformation shown in Lee, Fig 46. 00152 * Reverse analytically continues this in the ± \e x direction. As 00153 * a consequence, Reverse may map multiple points to the same geographic 00154 * location; for example, for TransverseMercatorExact::UTM, \e x = 00155 * 22051449.037349 m, \e y = −7131237.022729 m and \e x = 00156 * 29735142.378357 m, \e y = 4235043.607933 m both map to \e lat = 00157 * −2°, \e lon = 88°. 00158 * 00159 * With \e extendp = true, the branch cut is moved to the lower left 00160 * quadrant. The various symmetries of the transverse Mercator projection 00161 * can be used to explore the projection on any sheet. In this mode the 00162 * domains of \e lat, \e lon, \e x, and \e y are restricted to 00163 * - the union of 00164 * - \e lat in [0, 90] and \e lon − \e lon0 in [0, 90] 00165 * - \e lat in (-90, 0] and \e lon − \e lon0 in [90 (1 − \e 00166 e), 90] 00167 * - the union of 00168 * - <i>x</i>/(\e k0 \e a) in [0, ∞) and 00169 * <i>y</i>/(\e k0 \e a) in [0, E(<i>e</i><sup>2</sup>)] 00170 * - <i>x</i>/(\e k0 \e a) in [K(1 − <i>e</i><sup>2</sup>) − 00171 * E(1 − <i>e</i><sup>2</sup>), ∞) and <i>y</i>/(\e k0 \e 00172 * a) in (−∞, 0] 00173 * . 00174 * See Sec. 5 of 00175 * <a href="http://arxiv.org/abs/1002.1417">arXiv:1002.1417</a> for a full 00176 * discussion of the treatment of the branch cut. 00177 * 00178 * The method will work for all ellipsoids used in terrestrial geodesy. 00179 * The method cannot be applied directly to the case of a sphere (\e f = 0) 00180 * because some the constants characterizing this method diverge in that 00181 * limit, and in practice, \e f should be larger than about 00182 * numeric_limits<real>::epsilon(). However, TransverseMercator treats the 00183 * sphere exactly. 00184 **********************************************************************/ 00185 TransverseMercatorExact(real a, real f, real k0, bool extendp = false); 00186 00187 /** 00188 * Forward projection, from geographic to transverse Mercator. 00189 * 00190 * @param[in] lon0 central meridian of the projection (degrees). 00191 * @param[in] lat latitude of point (degrees). 00192 * @param[in] lon longitude of point (degrees). 00193 * @param[out] x easting of point (meters). 00194 * @param[out] y northing of point (meters). 00195 * @param[out] gamma meridian convergence at point (degrees). 00196 * @param[out] k scale of projection at point. 00197 * 00198 * No false easting or northing is added. \e lat should be in the range 00199 * [−90°, 90°]; \e lon and \e lon0 should be in the 00200 * range [−540°, 540°). 00201 **********************************************************************/ 00202 void Forward(real lon0, real lat, real lon, 00203 real& x, real& y, real& gamma, real& k) const; 00204 00205 /** 00206 * Reverse projection, from transverse Mercator to geographic. 00207 * 00208 * @param[in] lon0 central meridian of the projection (degrees). 00209 * @param[in] x easting of point (meters). 00210 * @param[in] y northing of point (meters). 00211 * @param[out] lat latitude of point (degrees). 00212 * @param[out] lon longitude of point (degrees). 00213 * @param[out] gamma meridian convergence at point (degrees). 00214 * @param[out] k scale of projection at point. 00215 * 00216 * No false easting or northing is added. \e lon0 should be in the range 00217 * [−540°, 540°). The value of \e lon returned is in 00218 * the range [−180°, 180°). 00219 **********************************************************************/ 00220 void Reverse(real lon0, real x, real y, 00221 real& lat, real& lon, real& gamma, real& k) const; 00222 00223 /** 00224 * TransverseMercatorExact::Forward without returning the convergence and 00225 * scale. 00226 **********************************************************************/ 00227 void Forward(real lon0, real lat, real lon, 00228 real& x, real& y) const { 00229 real gamma, k; 00230 Forward(lon0, lat, lon, x, y, gamma, k); 00231 } 00232 00233 /** 00234 * TransverseMercatorExact::Reverse without returning the convergence and 00235 * scale. 00236 **********************************************************************/ 00237 void Reverse(real lon0, real x, real y, 00238 real& lat, real& lon) const { 00239 real gamma, k; 00240 Reverse(lon0, x, y, lat, lon, gamma, k); 00241 } 00242 00243 /** \name Inspector functions 00244 **********************************************************************/ 00245 ///@{ 00246 /** 00247 * @return \e a the equatorial radius of the ellipsoid (meters). This is 00248 * the value used in the constructor. 00249 **********************************************************************/ 00250 Math::real MajorRadius() const { return _a; } 00251 00252 /** 00253 * @return \e f the flattening of the ellipsoid. This is the value used in 00254 * the constructor. 00255 **********************************************************************/ 00256 Math::real Flattening() const { return _f; } 00257 00258 /// \cond SKIP 00259 /** 00260 * <b>DEPRECATED</b> 00261 * @return \e r the inverse flattening of the ellipsoid. 00262 **********************************************************************/ 00263 Math::real InverseFlattening() const { return 1/_f; } 00264 /// \endcond 00265 00266 /** 00267 * @return \e k0 central scale for the projection. This is the value of \e 00268 * k0 used in the constructor and is the scale on the central meridian. 00269 **********************************************************************/ 00270 Math::real CentralScale() const { return _k0; } 00271 ///@} 00272 00273 /** 00274 * A global instantiation of TransverseMercatorExact with the WGS84 00275 * ellipsoid and the UTM scale factor. However, unlike UTM, no false 00276 * easting or northing is added. 00277 **********************************************************************/ 00278 static const TransverseMercatorExact& UTM(); 00279 }; 00280 00281 } // namespace GeographicLib 00282 00283 #endif // GEOGRAPHICLIB_TRANSVERSEMERCATOREXACT_HPP