GeographicLib  1.41
Constants.hpp
Go to the documentation of this file.
1 /**
2  * \file Constants.hpp
3  * \brief Header for GeographicLib::Constants class
4  *
5  * Copyright (c) Charles Karney (2008-2011) <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_CONSTANTS_HPP)
11 #define GEOGRAPHICLIB_CONSTANTS_HPP 1
12 
13 #include <GeographicLib/Config.h>
14 
15 /**
16  * @relates GeographicLib::Constants
17  * Pack the version components into a single integer.
18  **********************************************************************/
19 #define GEOGRAPHICLIB_VERSION_NUM(a,b,c) ((((a) * 10000 + (b)) * 100) + (c))
20 
21 /**
22  * @relates GeographicLib::Constants
23  * The version of GeographicLib as a single integer, packed as MMmmmmpp where
24  * MM is the major version, mmmm is the minor version, and pp is the patch
25  * level.
26  **********************************************************************/
27 #define GEOGRAPHICLIB_VERSION \
28  GEOGRAPHICLIB_VERSION_NUM(GEOGRAPHICLIB_VERSION_MAJOR, \
29  GEOGRAPHICLIB_VERSION_MINOR, \
30  GEOGRAPHICLIB_VERSION_PATCH)
31 
32 /**
33  * @relates GeographicLib::Constants
34  * A compile-time assert. Use C++11 static_assert, if available.
35  **********************************************************************/
36 #if !defined(GEOGRAPHICLIB_STATIC_ASSERT)
37 # if __cplusplus >= 201103 || defined(__GXX_EXPERIMENTAL_CXX0X__)
38 # define GEOGRAPHICLIB_STATIC_ASSERT static_assert
39 # elif defined(_MSC_VER) && _MSC_VER >= 1600
40 // For reference, here is a table of Visual Studio and _MSC_VER
41 // correspondences:
42 //
43 // _MSC_VER Visual Studio
44 // 1100 vc5
45 // 1200 vc6
46 // 1300 vc7
47 // 1310 vc7.1 (2003)
48 // 1400 vc8 (2005)
49 // 1500 vc9 (2008)
50 // 1600 vc10 (2010)
51 // 1700 vc11 (2012)
52 // 1800 vc12 (2013)
53 // 1900 vc14 (2015)
54 # define GEOGRAPHICLIB_STATIC_ASSERT static_assert
55 # else
56 # define GEOGRAPHICLIB_STATIC_ASSERT(cond,reason) \
57  { enum{ GEOGRAPHICLIB_STATIC_ASSERT_ENUM = 1/int(cond) }; }
58 # endif
59 #endif
60 
61 #if defined(_MSC_VER) && defined(GEOGRAPHICLIB_SHARED_LIB) && \
62  GEOGRAPHICLIB_SHARED_LIB
63 # if GEOGRAPHICLIB_SHARED_LIB > 1
64 # error GEOGRAPHICLIB_SHARED_LIB must be 0 or 1
65 # elif defined(GeographicLib_EXPORTS)
66 # define GEOGRAPHICLIB_EXPORT __declspec(dllexport)
67 # else
68 # define GEOGRAPHICLIB_EXPORT __declspec(dllimport)
69 # endif
70 #else
71 # define GEOGRAPHICLIB_EXPORT
72 #endif
73 
74 #include <stdexcept>
75 #include <string>
76 #include <GeographicLib/Math.hpp>
77 
78 /**
79  * \brief Namespace for %GeographicLib
80  *
81  * All of %GeographicLib is defined within the GeographicLib namespace. In
82  * addition all the header files are included via %GeographicLib/Class.hpp.
83  * This minimizes the likelihood of conflicts with other packages.
84  **********************************************************************/
85 namespace GeographicLib {
86 
87  /**
88  * \brief %Constants needed by %GeographicLib
89  *
90  * Define constants specifying the WGS84 ellipsoid, the UTM and UPS
91  * projections, and various unit conversions.
92  *
93  * Example of use:
94  * \include example-Constants.cpp
95  **********************************************************************/
97  private:
98  typedef Math::real real;
99  Constants(); // Disable constructor
100 
101  public:
102  /**
103  * A synonym for Math::degree<real>().
104  **********************************************************************/
105  static inline Math::real degree() { return Math::degree(); }
106  /**
107  * @return the number of radians in an arcminute.
108  **********************************************************************/
109  static inline Math::real arcminute()
110  { return Math::degree() / 60; }
111  /**
112  * @return the number of radians in an arcsecond.
113  **********************************************************************/
114  static inline Math::real arcsecond()
115  { return Math::degree() / 3600; }
116 
117  /** \name Ellipsoid parameters
118  **********************************************************************/
119  ///@{
120  /**
121  * @tparam T the type of the returned value.
122  * @return the equatorial radius of WGS84 ellipsoid (6378137 m).
123  **********************************************************************/
124  template<typename T> static inline T WGS84_a()
125  { return 6378137 * meter<T>(); }
126  /**
127  * A synonym for WGS84_a<real>().
128  **********************************************************************/
129  static inline Math::real WGS84_a() { return WGS84_a<real>(); }
130  /**
131  * @tparam T the type of the returned value.
132  * @return the flattening of WGS84 ellipsoid (1/298.257223563).
133  **********************************************************************/
134  template<typename T> static inline T WGS84_f()
135  { return 1 / ( T(298257223563LL) / 1000000000 ); }
136  /**
137  * A synonym for WGS84_f<real>().
138  **********************************************************************/
139  static inline Math::real WGS84_f() { return WGS84_f<real>(); }
140  /**
141  * @tparam T the type of the returned value.
142  * @return the gravitational constant of the WGS84 ellipsoid, \e GM, in
143  * m<sup>3</sup> s<sup>&minus;2</sup>.
144  **********************************************************************/
145  template<typename T> static inline T WGS84_GM()
146  { return T(3986004) * 100000000 + 41800000; }
147  /**
148  * A synonym for WGS84_GM<real>().
149  **********************************************************************/
150  static inline Math::real WGS84_GM() { return WGS84_GM<real>(); }
151  /**
152  * @tparam T the type of the returned value.
153  * @return the angular velocity of the WGS84 ellipsoid, &omega;, in rad
154  * s<sup>&minus;1</sup>.
155  **********************************************************************/
156  template<typename T> static inline T WGS84_omega()
157  { return 7292115 / (T(1000000) * 100000); }
158  /**
159  * A synonym for WGS84_omega<real>().
160  **********************************************************************/
161  static inline Math::real WGS84_omega() { return WGS84_omega<real>(); }
162  /// \cond SKIP
163  /**
164  * <b>DEPRECATED</b>
165  * @return the reciprocal flattening of WGS84 ellipsoid.
166  **********************************************************************/
167  template<typename T> static inline T WGS84_r()
168  { return 1/WGS84_f<T>(); }
169  /**
170  * <b>DEPRECATED</b>
171  * A synonym for WGS84_r<real>().
172  **********************************************************************/
173  static inline Math::real WGS84_r() { return WGS84_r<real>(); }
174  /// \endcond
175  /**
176  * @tparam T the type of the returned value.
177  * @return the equatorial radius of GRS80 ellipsoid, \e a, in m.
178  **********************************************************************/
179  template<typename T> static inline T GRS80_a()
180  { return 6378137 * meter<T>(); }
181  /**
182  * A synonym for GRS80_a<real>().
183  **********************************************************************/
184  static inline Math::real GRS80_a() { return GRS80_a<real>(); }
185  /**
186  * @tparam T the type of the returned value.
187  * @return the gravitational constant of the GRS80 ellipsoid, \e GM, in
188  * m<sup>3</sup> s<sup>&minus;2</sup>.
189  **********************************************************************/
190  template<typename T> static inline T GRS80_GM()
191  { return T(3986005) * 100000000; }
192  /**
193  * A synonym for GRS80_GM<real>().
194  **********************************************************************/
195  static inline Math::real GRS80_GM() { return GRS80_GM<real>(); }
196  /**
197  * @tparam T the type of the returned value.
198  * @return the angular velocity of the GRS80 ellipsoid, &omega;, in rad
199  * s<sup>&minus;1</sup>.
200  *
201  * This is about 2 &pi; 366.25 / (365.25 &times; 24 &times; 3600) rad
202  * s<sup>&minus;1</sup>. 365.25 is the number of days in a Julian year and
203  * 365.35/366.25 converts from solar days to sidereal days. Using the
204  * number of days in a Gregorian year (365.2425) results in a worse
205  * approximation (because the Gregorian year includes the precession of the
206  * earth's axis).
207  **********************************************************************/
208  template<typename T> static inline T GRS80_omega()
209  { return 7292115 / (T(1000000) * 100000); }
210  /**
211  * A synonym for GRS80_omega<real>().
212  **********************************************************************/
213  static inline Math::real GRS80_omega() { return GRS80_omega<real>(); }
214  /**
215  * @tparam T the type of the returned value.
216  * @return the dynamical form factor of the GRS80 ellipsoid,
217  * <i>J</i><sub>2</sub>.
218  **********************************************************************/
219  template<typename T> static inline T GRS80_J2()
220  { return T(108263) / 100000000; }
221  /**
222  * A synonym for GRS80_J2<real>().
223  **********************************************************************/
224  static inline Math::real GRS80_J2() { return GRS80_J2<real>(); }
225  /**
226  * @tparam T the type of the returned value.
227  * @return the central scale factor for UTM (0.9996).
228  **********************************************************************/
229  template<typename T> static inline T UTM_k0()
230  {return T(9996) / 10000; }
231  /**
232  * A synonym for UTM_k0<real>().
233  **********************************************************************/
234  static inline Math::real UTM_k0() { return UTM_k0<real>(); }
235  /**
236  * @tparam T the type of the returned value.
237  * @return the central scale factor for UPS (0.994).
238  **********************************************************************/
239  template<typename T> static inline T UPS_k0()
240  { return T(994) / 1000; }
241  /**
242  * A synonym for UPS_k0<real>().
243  **********************************************************************/
244  static inline Math::real UPS_k0() { return UPS_k0<real>(); }
245  ///@}
246 
247  /** \name SI units
248  **********************************************************************/
249  ///@{
250  /**
251  * @tparam T the type of the returned value.
252  * @return the number of meters in a meter.
253  *
254  * This is unity, but this lets the internal system of units be changed if
255  * necessary.
256  **********************************************************************/
257  template<typename T> static inline T meter() { return T(1); }
258  /**
259  * A synonym for meter<real>().
260  **********************************************************************/
261  static inline Math::real meter() { return meter<real>(); }
262  /**
263  * @return the number of meters in a kilometer.
264  **********************************************************************/
265  static inline Math::real kilometer()
266  { return 1000 * meter<real>(); }
267  /**
268  * @return the number of meters in a nautical mile (approximately 1 arc
269  * minute)
270  **********************************************************************/
271  static inline Math::real nauticalmile()
272  { return 1852 * meter<real>(); }
273 
274  /**
275  * @tparam T the type of the returned value.
276  * @return the number of square meters in a square meter.
277  *
278  * This is unity, but this lets the internal system of units be changed if
279  * necessary.
280  **********************************************************************/
281  template<typename T> static inline T square_meter()
282  { return meter<real>() * meter<real>(); }
283  /**
284  * A synonym for square_meter<real>().
285  **********************************************************************/
286  static inline Math::real square_meter()
287  { return square_meter<real>(); }
288  /**
289  * @return the number of square meters in a hectare.
290  **********************************************************************/
291  static inline Math::real hectare()
292  { return 10000 * square_meter<real>(); }
293  /**
294  * @return the number of square meters in a square kilometer.
295  **********************************************************************/
296  static inline Math::real square_kilometer()
297  { return kilometer() * kilometer(); }
298  /**
299  * @return the number of square meters in a square nautical mile.
300  **********************************************************************/
302  { return nauticalmile() * nauticalmile(); }
303  ///@}
304 
305  /** \name Anachronistic British units
306  **********************************************************************/
307  ///@{
308  /**
309  * @return the number of meters in an international foot.
310  **********************************************************************/
311  static inline Math::real foot()
312  { return real(254 * 12) / 10000 * meter<real>(); }
313  /**
314  * @return the number of meters in a yard.
315  **********************************************************************/
316  static inline Math::real yard() { return 3 * foot(); }
317  /**
318  * @return the number of meters in a fathom.
319  **********************************************************************/
320  static inline Math::real fathom() { return 2 * yard(); }
321  /**
322  * @return the number of meters in a chain.
323  **********************************************************************/
324  static inline Math::real chain() { return 22 * yard(); }
325  /**
326  * @return the number of meters in a furlong.
327  **********************************************************************/
328  static inline Math::real furlong() { return 10 * chain(); }
329  /**
330  * @return the number of meters in a statute mile.
331  **********************************************************************/
332  static inline Math::real mile() { return 8 * furlong(); }
333  /**
334  * @return the number of square meters in an acre.
335  **********************************************************************/
336  static inline Math::real acre() { return chain() * furlong(); }
337  /**
338  * @return the number of square meters in a square statute mile.
339  **********************************************************************/
340  static inline Math::real square_mile() { return mile() * mile(); }
341  ///@}
342 
343  /** \name Anachronistic US units
344  **********************************************************************/
345  ///@{
346  /**
347  * @return the number of meters in a US survey foot.
348  **********************************************************************/
349  static inline Math::real surveyfoot()
350  { return real(1200) / 3937 * meter<real>(); }
351  ///@}
352  };
353 
354  /**
355  * \brief Exception handling for %GeographicLib
356  *
357  * A class to handle exceptions. It's derived from std::runtime_error so it
358  * can be caught by the usual catch clauses.
359  *
360  * Example of use:
361  * \include example-GeographicErr.cpp
362  **********************************************************************/
363  class GeographicErr : public std::runtime_error {
364  public:
365 
366  /**
367  * Constructor
368  *
369  * @param[in] msg a string message, which is accessible in the catch
370  * clause via what().
371  **********************************************************************/
372  GeographicErr(const std::string& msg) : std::runtime_error(msg) {}
373  };
374 
375 } // namespace GeographicLib
376 
377 #endif // GEOGRAPHICLIB_CONSTANTS_HPP
static Math::real arcminute()
Definition: Constants.hpp:109
static Math::real mile()
Definition: Constants.hpp:332
static Math::real kilometer()
Definition: Constants.hpp:265
static Math::real yard()
Definition: Constants.hpp:316
#define GEOGRAPHICLIB_EXPORT
Definition: Constants.hpp:71
static Math::real UPS_k0()
Definition: Constants.hpp:244
static Math::real square_nauticalmile()
Definition: Constants.hpp:301
static Math::real WGS84_omega()
Definition: Constants.hpp:161
GeographicLib::Math::real real
Definition: GeodSolve.cpp:32
static Math::real nauticalmile()
Definition: Constants.hpp:271
static Math::real arcsecond()
Definition: Constants.hpp:114
static Math::real foot()
Definition: Constants.hpp:311
static Math::real surveyfoot()
Definition: Constants.hpp:349
static Math::real furlong()
Definition: Constants.hpp:328
static Math::real hectare()
Definition: Constants.hpp:291
static Math::real GRS80_omega()
Definition: Constants.hpp:213
static Math::real meter()
Definition: Constants.hpp:261
static Math::real degree()
Definition: Constants.hpp:105
static Math::real fathom()
Definition: Constants.hpp:320
static Math::real UTM_k0()
Definition: Constants.hpp:234
static Math::real acre()
Definition: Constants.hpp:336
Header for GeographicLib::Math class.
static Math::real chain()
Definition: Constants.hpp:324
Namespace for GeographicLib.
Definition: Accumulator.cpp:12
static T degree()
Definition: Math.hpp:228
static Math::real WGS84_GM()
Definition: Constants.hpp:150
static Math::real square_meter()
Definition: Constants.hpp:286
Constants needed by GeographicLib
Definition: Constants.hpp:96
static Math::real WGS84_a()
Definition: Constants.hpp:129
Exception handling for GeographicLib.
Definition: Constants.hpp:363
static Math::real square_kilometer()
Definition: Constants.hpp:296
static Math::real GRS80_a()
Definition: Constants.hpp:184
static Math::real square_mile()
Definition: Constants.hpp:340
static Math::real GRS80_GM()
Definition: Constants.hpp:195
static Math::real GRS80_J2()
Definition: Constants.hpp:224
static Math::real WGS84_f()
Definition: Constants.hpp:139
GeographicErr(const std::string &msg)
Definition: Constants.hpp:372