GeographicLib  1.38
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TransverseMercatorExact.hpp
Go to the documentation of this file.
1 /**
2  * \file TransverseMercatorExact.hpp
3  * \brief Header for GeographicLib::TransverseMercatorExact class
4  *
5  * Copyright (c) Charles Karney (2008-2014) <charles@karney.com> and licensed
6  * under the MIT/X11 License. For more information, see
7  * http://geographiclib.sourceforge.net/
8  **********************************************************************/
9 
10 #if !defined(GEOGRAPHICLIB_TRANSVERSEMERCATOREXACT_HPP)
11 #define GEOGRAPHICLIB_TRANSVERSEMERCATOREXACT_HPP 1
12 
15 
16 namespace GeographicLib {
17 
18  /**
19  * \brief An exact implementation of the transverse Mercator projection
20  *
21  * Implementation of the Transverse Mercator Projection given in
22  * - L. P. Lee,
23  * <a href="http://dx.doi.org/10.3138/X687-1574-4325-WM62"> Conformal
24  * Projections Based On Jacobian Elliptic Functions</a>, Part V of
25  * Conformal Projections Based on Elliptic Functions,
26  * (B. V. Gutsell, Toronto, 1976), 128pp.,
27  * ISBN: 0919870163
28  * (also appeared as:
29  * Monograph 16, Suppl. No. 1 to Canadian Cartographer, Vol 13).
30  * - C. F. F. Karney,
31  * <a href="http://dx.doi.org/10.1007/s00190-011-0445-3">
32  * Transverse Mercator with an accuracy of a few nanometers,</a>
33  * J. Geodesy 85(8), 475--485 (Aug. 2011);
34  * preprint
35  * <a href="http://arxiv.org/abs/1002.1417">arXiv:1002.1417</a>.
36  *
37  * Lee gives the correct results for forward and reverse transformations
38  * subject to the branch cut rules (see the description of the \e extendp
39  * argument to the constructor). The maximum error is about 8 nm (8
40  * nanometers), ground distance, for the forward and reverse transformations.
41  * The error in the convergence is 2 &times; 10<sup>&minus;15</sup>&quot;,
42  * the relative error in the scale is 7 &times; 10<sup>&minus;12</sup>%%.
43  * See Sec. 3 of
44  * <a href="http://arxiv.org/abs/1002.1417">arXiv:1002.1417</a> for details.
45  * The method is "exact" in the sense that the errors are close to the
46  * round-off limit and that no changes are needed in the algorithms for them
47  * to be used with reals of a higher precision. Thus the errors using long
48  * double (with a 64-bit fraction) are about 2000 times smaller than using
49  * double (with a 53-bit fraction).
50  *
51  * This algorithm is about 4.5 times slower than the 6th-order Kr&uuml;ger
52  * method, TransverseMercator, taking about 11 us for a combined forward and
53  * reverse projection on a 2.66 GHz Intel machine (g++, version 4.3.0, -O3).
54  *
55  * The ellipsoid parameters and the central scale are set in the constructor.
56  * The central meridian (which is a trivial shift of the longitude) is
57  * specified as the \e lon0 argument of the TransverseMercatorExact::Forward
58  * and TransverseMercatorExact::Reverse functions. The latitude of origin is
59  * taken to be the equator. See the documentation on TransverseMercator for
60  * how to include a false easting, false northing, or a latitude of origin.
61  *
62  * See <a href="http://geographiclib.sourceforge.net/tm-grid.kmz"
63  * type="application/vnd.google-earth.kmz"> tm-grid.kmz</a>, for an
64  * illustration of the transverse Mercator grid in Google Earth.
65  *
66  * See TransverseMercatorExact.cpp for more information on the
67  * implementation.
68  *
69  * See \ref transversemercator for a discussion of this projection.
70  *
71  * Example of use:
72  * \include example-TransverseMercatorExact.cpp
73  *
74  * <a href="TransverseMercatorProj.1.html">TransverseMercatorProj</a> is a
75  * command-line utility providing access to the functionality of
76  * TransverseMercator and TransverseMercatorExact.
77  **********************************************************************/
78 
80  private:
81  typedef Math::real real;
82  static const int numit_ = 10;
83  real tol_, tol1_, tol2_, taytol_;
84  real _a, _f, _k0, _mu, _mv, _e;
85  bool _extendp;
86  EllipticFunction _Eu, _Ev;
87  static inline real overflow() {
88  // Overflow value s.t. atan(overflow_) = pi/2
89  static const real
90  overflow = 1 / Math::sq(std::numeric_limits<real>::epsilon());
91  return overflow;
92  }
93  // tan(x) for x in [-pi/2, pi/2] ensuring that the sign is right
94  static inline real tanx(real x) {
95  using std::tan;
96  real t = tan(x);
97  // Write the tests this way to ensure that tanx(NaN()) is NaN()
98  return x >= 0 ?
99  (!(t < 0) ? t : overflow()) :
100  (!(t >= 0) ? t : -overflow());
101  }
102 
103  real taup(real tau) const;
104  real taupinv(real taup) const;
105 
106  void zeta(real u, real snu, real cnu, real dnu,
107  real v, real snv, real cnv, real dnv,
108  real& taup, real& lam) const;
109 
110  void dwdzeta(real u, real snu, real cnu, real dnu,
111  real v, real snv, real cnv, real dnv,
112  real& du, real& dv) const;
113 
114  bool zetainv0(real psi, real lam, real& u, real& v) const;
115  void zetainv(real taup, real lam, real& u, real& v) const;
116 
117  void sigma(real u, real snu, real cnu, real dnu,
118  real v, real snv, real cnv, real dnv,
119  real& xi, real& eta) const;
120 
121  void dwdsigma(real u, real snu, real cnu, real dnu,
122  real v, real snv, real cnv, real dnv,
123  real& du, real& dv) const;
124 
125  bool sigmainv0(real xi, real eta, real& u, real& v) const;
126  void sigmainv(real xi, real eta, real& u, real& v) const;
127 
128  void Scale(real tau, real lam,
129  real snu, real cnu, real dnu,
130  real snv, real cnv, real dnv,
131  real& gamma, real& k) const;
132 
133  public:
134 
135  /**
136  * Constructor for a ellipsoid with
137  *
138  * @param[in] a equatorial radius (meters).
139  * @param[in] f flattening of ellipsoid. If \e f &gt; 1, set flattening
140  * to 1/\e f.
141  * @param[in] k0 central scale factor.
142  * @param[in] extendp use extended domain.
143  * @exception GeographicErr if \e a, \e f, or \e k0 is not positive.
144  *
145  * The transverse Mercator projection has a branch point singularity at \e
146  * lat = 0 and \e lon &minus; \e lon0 = 90 (1 &minus; \e e) or (for
147  * TransverseMercatorExact::UTM) x = 18381 km, y = 0m. The \e extendp
148  * argument governs where the branch cut is placed. With \e extendp =
149  * false, the "standard" convention is followed, namely the cut is placed
150  * along \e x > 18381 km, \e y = 0m. Forward can be called with any \e lat
151  * and \e lon then produces the transformation shown in Lee, Fig 46.
152  * Reverse analytically continues this in the &plusmn; \e x direction. As
153  * a consequence, Reverse may map multiple points to the same geographic
154  * location; for example, for TransverseMercatorExact::UTM, \e x =
155  * 22051449.037349 m, \e y = &minus;7131237.022729 m and \e x =
156  * 29735142.378357 m, \e y = 4235043.607933 m both map to \e lat =
157  * &minus;2&deg;, \e lon = 88&deg;.
158  *
159  * With \e extendp = true, the branch cut is moved to the lower left
160  * quadrant. The various symmetries of the transverse Mercator projection
161  * can be used to explore the projection on any sheet. In this mode the
162  * domains of \e lat, \e lon, \e x, and \e y are restricted to
163  * - the union of
164  * - \e lat in [0, 90] and \e lon &minus; \e lon0 in [0, 90]
165  * - \e lat in (-90, 0] and \e lon &minus; \e lon0 in [90 (1 &minus; \e
166  e), 90]
167  * - the union of
168  * - <i>x</i>/(\e k0 \e a) in [0, &infin;) and
169  * <i>y</i>/(\e k0 \e a) in [0, E(<i>e</i><sup>2</sup>)]
170  * - <i>x</i>/(\e k0 \e a) in [K(1 &minus; <i>e</i><sup>2</sup>) &minus;
171  * E(1 &minus; <i>e</i><sup>2</sup>), &infin;) and <i>y</i>/(\e k0 \e
172  * a) in (&minus;&infin;, 0]
173  * .
174  * See Sec. 5 of
175  * <a href="http://arxiv.org/abs/1002.1417">arXiv:1002.1417</a> for a full
176  * discussion of the treatment of the branch cut.
177  *
178  * The method will work for all ellipsoids used in terrestrial geodesy.
179  * The method cannot be applied directly to the case of a sphere (\e f = 0)
180  * because some the constants characterizing this method diverge in that
181  * limit, and in practice, \e f should be larger than about
182  * numeric_limits<real>::epsilon(). However, TransverseMercator treats the
183  * sphere exactly.
184  **********************************************************************/
185  TransverseMercatorExact(real a, real f, real k0, bool extendp = false);
186 
187  /**
188  * Forward projection, from geographic to transverse Mercator.
189  *
190  * @param[in] lon0 central meridian of the projection (degrees).
191  * @param[in] lat latitude of point (degrees).
192  * @param[in] lon longitude of point (degrees).
193  * @param[out] x easting of point (meters).
194  * @param[out] y northing of point (meters).
195  * @param[out] gamma meridian convergence at point (degrees).
196  * @param[out] k scale of projection at point.
197  *
198  * No false easting or northing is added. \e lat should be in the range
199  * [&minus;90&deg;, 90&deg;]; \e lon and \e lon0 should be in the
200  * range [&minus;540&deg;, 540&deg;).
201  **********************************************************************/
202  void Forward(real lon0, real lat, real lon,
203  real& x, real& y, real& gamma, real& k) const;
204 
205  /**
206  * Reverse projection, from transverse Mercator to geographic.
207  *
208  * @param[in] lon0 central meridian of the projection (degrees).
209  * @param[in] x easting of point (meters).
210  * @param[in] y northing of point (meters).
211  * @param[out] lat latitude of point (degrees).
212  * @param[out] lon longitude of point (degrees).
213  * @param[out] gamma meridian convergence at point (degrees).
214  * @param[out] k scale of projection at point.
215  *
216  * No false easting or northing is added. \e lon0 should be in the range
217  * [&minus;540&deg;, 540&deg;). The value of \e lon returned is in
218  * the range [&minus;180&deg;, 180&deg;).
219  **********************************************************************/
220  void Reverse(real lon0, real x, real y,
221  real& lat, real& lon, real& gamma, real& k) const;
222 
223  /**
224  * TransverseMercatorExact::Forward without returning the convergence and
225  * scale.
226  **********************************************************************/
227  void Forward(real lon0, real lat, real lon,
228  real& x, real& y) const {
229  real gamma, k;
230  Forward(lon0, lat, lon, x, y, gamma, k);
231  }
232 
233  /**
234  * TransverseMercatorExact::Reverse without returning the convergence and
235  * scale.
236  **********************************************************************/
237  void Reverse(real lon0, real x, real y,
238  real& lat, real& lon) const {
239  real gamma, k;
240  Reverse(lon0, x, y, lat, lon, gamma, k);
241  }
242 
243  /** \name Inspector functions
244  **********************************************************************/
245  ///@{
246  /**
247  * @return \e a the equatorial radius of the ellipsoid (meters). This is
248  * the value used in the constructor.
249  **********************************************************************/
250  Math::real MajorRadius() const { return _a; }
251 
252  /**
253  * @return \e f the flattening of the ellipsoid. This is the value used in
254  * the constructor.
255  **********************************************************************/
256  Math::real Flattening() const { return _f; }
257 
258  /// \cond SKIP
259  /**
260  * <b>DEPRECATED</b>
261  * @return \e r the inverse flattening of the ellipsoid.
262  **********************************************************************/
263  Math::real InverseFlattening() const { return 1/_f; }
264  /// \endcond
265 
266  /**
267  * @return \e k0 central scale for the projection. This is the value of \e
268  * k0 used in the constructor and is the scale on the central meridian.
269  **********************************************************************/
270  Math::real CentralScale() const { return _k0; }
271  ///@}
272 
273  /**
274  * A global instantiation of TransverseMercatorExact with the WGS84
275  * ellipsoid and the UTM scale factor. However, unlike UTM, no false
276  * easting or northing is added.
277  **********************************************************************/
278  static const TransverseMercatorExact& UTM();
279  };
280 
281 } // namespace GeographicLib
282 
283 #endif // GEOGRAPHICLIB_TRANSVERSEMERCATOREXACT_HPP
#define GEOGRAPHICLIB_EXPORT
Definition: Constants.hpp:70
An exact implementation of the transverse Mercator projection.
GeographicLib::Math::real real
Definition: GeodSolve.cpp:40
Elliptic integrals and functions.
void Reverse(real lon0, real x, real y, real &lat, real &lon) const
static T sq(T x)
Definition: Math.hpp:243
Namespace for GeographicLib.
Definition: Accumulator.cpp:12
Header for GeographicLib::EllipticFunction class.
void Forward(real lon0, real lat, real lon, real &x, real &y) const
Header for GeographicLib::Constants class.