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