GeographicLib  2.6
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-2023) <karney@alum.mit.edu> and licensed
6  * under the MIT/X11 License. For more information, see
7  * https://geographiclib.sourceforge.io/
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="https://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  * <a href="https://archive.org/details/conformalproject0000leel/page/92">
31  * borrow from archive.org</a>.
32  * - C. F. F. Karney,
33  * <a href="https://doi.org/10.1007/s00190-011-0445-3">
34  * Transverse Mercator with an accuracy of a few nanometers,</a>
35  * J. Geodesy 85(8), 475--485 (Aug. 2011);
36  * preprint
37  * <a href="https://arxiv.org/abs/1002.1417">arXiv:1002.1417</a>.
38  *
39  * Lee gives the correct results for forward and reverse transformations
40  * subject to the branch cut rules (see the description of the \e extendp
41  * argument to the constructor). The maximum error is about 8 nm (8
42  * nanometers), ground distance, for the forward and reverse transformations.
43  * The error in the convergence is 2 &times; 10<sup>&minus;15</sup>&quot;,
44  * the relative error in the scale is 7 &times; 10<sup>&minus;12</sup>%%.
45  * See Sec. 3 of
46  * <a href="https://arxiv.org/abs/1002.1417">arXiv:1002.1417</a> for details.
47  * The method is "exact" in the sense that the errors are close to the
48  * round-off limit and that no changes are needed in the algorithms for them
49  * to be used with reals of a higher precision. Thus the errors using long
50  * double (with a 64-bit fraction) are about 2000 times smaller than using
51  * double (with a 53-bit fraction).
52  *
53  * This algorithm is about 4.5 times slower than the 6th-order Kr&uuml;ger
54  * method, TransverseMercator, taking about 11 us for a combined forward and
55  * reverse projection on a 2.66 GHz Intel machine (g++, version 4.3.0, -O3).
56  *
57  * The ellipsoid parameters and the central scale are set in the constructor.
58  * The central meridian (which is a trivial shift of the longitude) is
59  * specified as the \e lon0 argument of the TransverseMercatorExact::Forward
60  * and TransverseMercatorExact::Reverse functions. The latitude of origin is
61  * taken to be the equator. See the documentation on TransverseMercator for
62  * how to include a false easting, false northing, or a latitude of origin.
63  *
64  * See <a href="https://geographiclib.sourceforge.io/tm-grid.kmz"
65  * type="application/vnd.google-earth.kmz"> tm-grid.kmz</a>, for an
66  * illustration of the transverse Mercator grid in Google Earth.
67  *
68  * This class also returns the meridian convergence \e gamma and scale \e k.
69  * The meridian convergence is the bearing of grid north (the \e y axis)
70  * measured clockwise from true north.
71  *
72  * See TransverseMercatorExact.cpp for more information on the
73  * implementation.
74  *
75  * See \ref transversemercator for a discussion of this projection.
76  *
77  * Example of use:
78  * \include example-TransverseMercatorExact.cpp
79  *
80  * <a href="TransverseMercatorProj.1.html">TransverseMercatorProj</a> is a
81  * command-line utility providing access to the functionality of
82  * TransverseMercator and TransverseMercatorExact.
83  **********************************************************************/
84 
86  private:
87  typedef Math::real real;
88  friend class TransverseMercator; // Allow TM to call the default constructor
89  // Private default constructor to support TransverseMercator(a, f, exact)
90  TransverseMercatorExact() {}; // Do nothing; used with exact = false.
91  static const int numit_ = 10;
92  real tol_, tol2_, taytol_;
93  real _a, _f, _k0, _mu, _mv, _e;
94  bool _extendp;
95  EllipticFunction _eEu, _eEv;
96 
97  void zeta(real u, real snu, real cnu, real dnu,
98  real v, real snv, real cnv, real dnv,
99  real& taup, real& lam) const;
100 
101  void dwdzeta(real u, real snu, real cnu, real dnu,
102  real v, real snv, real cnv, real dnv,
103  real& du, real& dv) const;
104 
105  bool zetainv0(real psi, real lam, real& u, real& v) const;
106  void zetainv(real taup, real lam, real& u, real& v) const;
107 
108  void sigma(real u, real snu, real cnu, real dnu,
109  real v, real snv, real cnv, real dnv,
110  real& xi, real& eta) const;
111 
112  void dwdsigma(real u, real snu, real cnu, real dnu,
113  real v, real snv, real cnv, real dnv,
114  real& du, real& dv) const;
115 
116  bool sigmainv0(real xi, real eta, real& u, real& v) const;
117  void sigmainv(real xi, real eta, real& u, real& v) const;
118 
119  void Scale(real tau, real lam,
120  real snu, real cnu, real dnu,
121  real snv, real cnv, real dnv,
122  real& gamma, real& k) const;
123  public:
124 
125  /**
126  * Constructor for an ellipsoid with
127  *
128  * @param[in] a equatorial radius (meters).
129  * @param[in] f flattening of ellipsoid.
130  * @param[in] k0 central scale factor.
131  * @param[in] extendp if true, use extended domain (default false).
132  * @exception GeographicErr if \e a, \e f, or \e k0 is not positive.
133  *
134  * The transverse Mercator projection has a branch point singularity at \e
135  * lat = 0 and \e lon &minus; \e lon0 = 90 (1 &minus; \e e) or (for
136  * TransverseMercatorExact::UTM) x = 18381 km, y = 0m. The \e extendp
137  * argument governs where the branch cut is placed. With \e extendp =
138  * false, the "standard" convention is followed, namely the cut is placed
139  * along \e x > 18381 km, \e y = 0m. Forward can be called with any \e lat
140  * and \e lon then produces the transformation shown in Lee, Fig 46.
141  * Reverse analytically continues this in the &plusmn; \e x direction. As
142  * a consequence, Reverse may map multiple points to the same geographic
143  * location; for example, for TransverseMercatorExact::UTM, \e x =
144  * 22051449.037349 m, \e y = &minus;7131237.022729 m and \e x =
145  * 29735142.378357 m, \e y = 4235043.607933 m both map to \e lat =
146  * &minus;2&deg;, \e lon = 88&deg;.
147  *
148  * With \e extendp = true, the branch cut is moved to the lower left
149  * quadrant. The various symmetries of the transverse Mercator projection
150  * can be used to explore the projection on any sheet. In this mode the
151  * domains of \e lat, \e lon, \e x, and \e y are restricted to
152  * - the union of
153  * - \e lat in [0, 90] and \e lon &minus; \e lon0 in [0, 90]
154  * - \e lat in (-90, 0] and \e lon &minus; \e lon0 in [90 (1 &minus; \e
155  e), 90]
156  * - the union of
157  * - <i>x</i>/(\e k0 \e a) in [0, &infin;) and
158  * <i>y</i>/(\e k0 \e a) in [0, E(<i>e</i><sup>2</sup>)]
159  * - <i>x</i>/(\e k0 \e a) in [K(1 &minus; <i>e</i><sup>2</sup>) &minus;
160  * E(1 &minus; <i>e</i><sup>2</sup>), &infin;) and <i>y</i>/(\e k0 \e
161  * a) in (&minus;&infin;, 0]
162  * .
163  * See Sec. 5 of
164  * <a href="https://arxiv.org/abs/1002.1417">arXiv:1002.1417</a> for a full
165  * discussion of the treatment of the branch cut.
166  *
167  * The method will work for all ellipsoids used in terrestrial geodesy.
168  * The method cannot be applied directly to the case of a sphere (\e f = 0)
169  * because some the constants characterizing this method diverge in that
170  * limit, and in practice, \e f should be larger than about
171  * numeric_limits<real>::epsilon(). However, TransverseMercator treats the
172  * sphere exactly.
173  **********************************************************************/
174  TransverseMercatorExact(real a, real f, real k0, bool extendp = false);
175 
176  /**
177  * Forward projection, from geographic to transverse Mercator.
178  *
179  * @param[in] lon0 central meridian of the projection (degrees).
180  * @param[in] lat latitude of point (degrees).
181  * @param[in] lon longitude of point (degrees).
182  * @param[out] x easting of point (meters).
183  * @param[out] y northing of point (meters).
184  * @param[out] gamma meridian convergence at point (degrees).
185  * @param[out] k scale of projection at point.
186  *
187  * No false easting or northing is added. \e lat should be in the range
188  * [&minus;90&deg;, 90&deg;].
189  **********************************************************************/
190  void Forward(real lon0, real lat, real lon,
191  real& x, real& y, real& gamma, real& k) const;
192 
193  /**
194  * Reverse projection, from transverse Mercator to geographic.
195  *
196  * @param[in] lon0 central meridian of the projection (degrees).
197  * @param[in] x easting of point (meters).
198  * @param[in] y northing of point (meters).
199  * @param[out] lat latitude of point (degrees).
200  * @param[out] lon longitude of point (degrees).
201  * @param[out] gamma meridian convergence at point (degrees).
202  * @param[out] k scale of projection at point.
203  *
204  * No false easting or northing is added. The value of \e lon returned is
205  * in the range [&minus;180&deg;, 180&deg;].
206  **********************************************************************/
207  void Reverse(real lon0, real x, real y,
208  real& lat, real& lon, real& gamma, real& k) const;
209 
210  /**
211  * TransverseMercatorExact::Forward without returning the convergence and
212  * scale.
213  **********************************************************************/
214  void Forward(real lon0, real lat, real lon,
215  real& x, real& y) const {
216  real gamma, k;
217  Forward(lon0, lat, lon, x, y, gamma, k);
218  }
219 
220  /**
221  * TransverseMercatorExact::Reverse without returning the convergence and
222  * scale.
223  **********************************************************************/
224  void Reverse(real lon0, real x, real y,
225  real& lat, real& lon) const {
226  real gamma, k;
227  Reverse(lon0, x, y, lat, lon, gamma, k);
228  }
229 
230  /** \name Inspector functions
231  **********************************************************************/
232  ///@{
233  /**
234  * @return \e a the equatorial radius of the ellipsoid (meters). This is
235  * the value used in the constructor.
236  **********************************************************************/
237  Math::real EquatorialRadius() const { return _a; }
238 
239  /**
240  * @return \e f the flattening of the ellipsoid. This is the value used in
241  * the constructor.
242  **********************************************************************/
243  Math::real Flattening() const { return _f; }
244 
245  /**
246  * @return \e k0 central scale for the projection. This is the value of \e
247  * k0 used in the constructor and is the scale on the central meridian.
248  **********************************************************************/
249  Math::real CentralScale() const { return _k0; }
250  ///@}
251 
252  /**
253  * A global instantiation of TransverseMercatorExact with the WGS84
254  * ellipsoid and the UTM scale factor. However, unlike UTM, no false
255  * easting or northing is added.
256  **********************************************************************/
257  static const TransverseMercatorExact& UTM();
258  };
259 
260 } // namespace GeographicLib
261 
262 #endif // GEOGRAPHICLIB_TRANSVERSEMERCATOREXACT_HPP
#define GEOGRAPHICLIB_EXPORT
Definition: Constants.hpp:59
An exact implementation of the transverse Mercator projection.
Transverse Mercator projection.
Elliptic integrals and functions.
void Forward(real lon0, real lat, real lon, real &x, real &y) const
Namespace for GeographicLib.
Definition: Accumulator.cpp:12
Header for GeographicLib::EllipticFunction class.
GeographicLib::Math::real real
Definition: Geod3Solve.cpp:25
Header for GeographicLib::Constants class.
void Reverse(real lon0, real x, real y, real &lat, real &lon) const