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