GeographicLib  1.43
Geodesic.hpp
Go to the documentation of this file.
1 /**
2  * \file Geodesic.hpp
3  * \brief Header for GeographicLib::Geodesic class
4  *
5  * Copyright (c) Charles Karney (2009-2015) <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_GEODESIC_HPP)
11 #define GEOGRAPHICLIB_GEODESIC_HPP 1
12 
14 
15 #if !defined(GEOGRAPHICLIB_GEODESIC_ORDER)
16 /**
17  * The order of the expansions used by Geodesic.
18  * GEOGRAPHICLIB_GEODESIC_ORDER can be set to any integer in [3, 8].
19  **********************************************************************/
20 # define GEOGRAPHICLIB_GEODESIC_ORDER \
21  (GEOGRAPHICLIB_PRECISION == 2 ? 6 : \
22  (GEOGRAPHICLIB_PRECISION == 1 ? 3 : \
23  (GEOGRAPHICLIB_PRECISION == 3 ? 7 : 8)))
24 #endif
25 
26 namespace GeographicLib {
27 
28  class GeodesicLine;
29 
30  /**
31  * \brief %Geodesic calculations
32  *
33  * The shortest path between two points on a ellipsoid at (\e lat1, \e lon1)
34  * and (\e lat2, \e lon2) is called the geodesic. Its length is \e s12 and
35  * the geodesic from point 1 to point 2 has azimuths \e azi1 and \e azi2 at
36  * the two end points. (The azimuth is the heading measured clockwise from
37  * north. \e azi2 is the "forward" azimuth, i.e., the heading that takes you
38  * beyond point 2 not back to point 1.) In the figure below, latitude if
39  * labeled &phi;, longitude &lambda; (with &lambda;<sub>12</sub> =
40  * &lambda;<sub>2</sub> &minus; &lambda;<sub>1</sub>), and azimuth &alpha;.
41  *
42  * <img src="http://upload.wikimedia.org/wikipedia/commons/c/cb/Geodesic_problem_on_an_ellipsoid.svg" width=250 alt="spheroidal triangle">
43  *
44  * Given \e lat1, \e lon1, \e azi1, and \e s12, we can determine \e lat2, \e
45  * lon2, and \e azi2. This is the \e direct geodesic problem and its
46  * solution is given by the function Geodesic::Direct. (If \e s12 is
47  * sufficiently large that the geodesic wraps more than halfway around the
48  * earth, there will be another geodesic between the points with a smaller \e
49  * s12.)
50  *
51  * Given \e lat1, \e lon1, \e lat2, and \e lon2, we can determine \e azi1, \e
52  * azi2, and \e s12. This is the \e inverse geodesic problem, whose solution
53  * is given by Geodesic::Inverse. Usually, the solution to the inverse
54  * problem is unique. In cases where there are multiple solutions (all with
55  * the same \e s12, of course), all the solutions can be easily generated
56  * once a particular solution is provided.
57  *
58  * The standard way of specifying the direct problem is the specify the
59  * distance \e s12 to the second point. However it is sometimes useful
60  * instead to specify the arc length \e a12 (in degrees) on the auxiliary
61  * sphere. This is a mathematical construct used in solving the geodesic
62  * problems. The solution of the direct problem in this form is provided by
63  * Geodesic::ArcDirect. An arc length in excess of 180&deg; indicates that
64  * the geodesic is not a shortest path. In addition, the arc length between
65  * an equatorial crossing and the next extremum of latitude for a geodesic is
66  * 90&deg;.
67  *
68  * This class can also calculate several other quantities related to
69  * geodesics. These are:
70  * - <i>reduced length</i>. If we fix the first point and increase \e azi1
71  * by \e dazi1 (radians), the second point is displaced \e m12 \e dazi1 in
72  * the direction \e azi2 + 90&deg;. The quantity \e m12 is called
73  * the "reduced length" and is symmetric under interchange of the two
74  * points. On a curved surface the reduced length obeys a symmetry
75  * relation, \e m12 + \e m21 = 0. On a flat surface, we have \e m12 = \e
76  * s12. The ratio <i>s12</i>/\e m12 gives the azimuthal scale for an
77  * azimuthal equidistant projection.
78  * - <i>geodesic scale</i>. Consider a reference geodesic and a second
79  * geodesic parallel to this one at point 1 and separated by a small
80  * distance \e dt. The separation of the two geodesics at point 2 is \e
81  * M12 \e dt where \e M12 is called the "geodesic scale". \e M21 is
82  * defined similarly (with the geodesics being parallel at point 2). On a
83  * flat surface, we have \e M12 = \e M21 = 1. The quantity 1/\e M12 gives
84  * the scale of the Cassini-Soldner projection.
85  * - <i>area</i>. The area between the geodesic from point 1 to point 2 and
86  * the equation is represented by \e S12; it is the area, measured
87  * counter-clockwise, of the geodesic quadrilateral with corners
88  * (<i>lat1</i>,<i>lon1</i>), (0,<i>lon1</i>), (0,<i>lon2</i>), and
89  * (<i>lat2</i>,<i>lon2</i>). It can be used to compute the area of any
90  * simple geodesic polygon.
91  *
92  * Overloaded versions of Geodesic::Direct, Geodesic::ArcDirect, and
93  * Geodesic::Inverse allow these quantities to be returned. In addition
94  * there are general functions Geodesic::GenDirect, and Geodesic::GenInverse
95  * which allow an arbitrary set of results to be computed. The quantities \e
96  * m12, \e M12, \e M21 which all specify the behavior of nearby geodesics
97  * obey addition rules. If points 1, 2, and 3 all lie on a single geodesic,
98  * then the following rules hold:
99  * - \e s13 = \e s12 + \e s23
100  * - \e a13 = \e a12 + \e a23
101  * - \e S13 = \e S12 + \e S23
102  * - \e m13 = \e m12 \e M23 + \e m23 \e M21
103  * - \e M13 = \e M12 \e M23 &minus; (1 &minus; \e M12 \e M21) \e m23 / \e m12
104  * - \e M31 = \e M32 \e M21 &minus; (1 &minus; \e M23 \e M32) \e m12 / \e m23
105  *
106  * Additional functionality is provided by the GeodesicLine class, which
107  * allows a sequence of points along a geodesic to be computed.
108  *
109  * The shortest distance returned by the solution of the inverse problem is
110  * (obviously) uniquely defined. However, in a few special cases there are
111  * multiple azimuths which yield the same shortest distance. Here is a
112  * catalog of those cases:
113  * - \e lat1 = &minus;\e lat2 (with neither point at a pole). If \e azi1 =
114  * \e azi2, the geodesic is unique. Otherwise there are two geodesics and
115  * the second one is obtained by setting [\e azi1, \e azi2] = [\e azi2, \e
116  * azi1], [\e M12, \e M21] = [\e M21, \e M12], \e S12 = &minus;\e S12.
117  * (This occurs when the longitude difference is near &plusmn;180&deg; for
118  * oblate ellipsoids.)
119  * - \e lon2 = \e lon1 &plusmn; 180&deg; (with neither point at a pole). If
120  * \e azi1 = 0&deg; or &plusmn;180&deg;, the geodesic is unique. Otherwise
121  * there are two geodesics and the second one is obtained by setting [\e
122  * azi1, \e azi2] = [&minus;\e azi1, &minus;\e azi2], \e S12 = &minus;\e
123  * S12. (This occurs when \e lat2 is near &minus;\e lat1 for prolate
124  * ellipsoids.)
125  * - Points 1 and 2 at opposite poles. There are infinitely many geodesics
126  * which can be generated by setting [\e azi1, \e azi2] = [\e azi1, \e
127  * azi2] + [\e d, &minus;\e d], for arbitrary \e d. (For spheres, this
128  * prescription applies when points 1 and 2 are antipodal.)
129  * - s12 = 0 (coincident points). There are infinitely many geodesics which
130  * can be generated by setting [\e azi1, \e azi2] = [\e azi1, \e azi2] +
131  * [\e d, \e d], for arbitrary \e d.
132  *
133  * The calculations are accurate to better than 15 nm (15 nanometers) for the
134  * WGS84 ellipsoid. See Sec. 9 of
135  * <a href="http://arxiv.org/abs/1102.1215v1">arXiv:1102.1215v1</a> for
136  * details. The algorithms used by this class are based on series expansions
137  * using the flattening \e f as a small parameter. These are only accurate
138  * for |<i>f</i>| &lt; 0.02; however reasonably accurate results will be
139  * obtained for |<i>f</i>| &lt; 0.2. Here is a table of the approximate
140  * maximum error (expressed as a distance) for an ellipsoid with the same
141  * major radius as the WGS84 ellipsoid and different values of the
142  * flattening.<pre>
143  * |f| error
144  * 0.01 25 nm
145  * 0.02 30 nm
146  * 0.05 10 um
147  * 0.1 1.5 mm
148  * 0.2 300 mm
149  * </pre>
150  * For very eccentric ellipsoids, use GeodesicExact instead.
151  *
152  * The algorithms are described in
153  * - C. F. F. Karney,
154  * <a href="https://dx.doi.org/10.1007/s00190-012-0578-z">
155  * Algorithms for geodesics</a>,
156  * J. Geodesy <b>87</b>, 43--55 (2013);
157  * DOI: <a href="https://dx.doi.org/10.1007/s00190-012-0578-z">
158  * 10.1007/s00190-012-0578-z</a>;
159  * addenda: <a href="http://geographiclib.sf.net/geod-addenda.html">
160  * geod-addenda.html</a>.
161  * .
162  * For more information on geodesics see \ref geodesic.
163  *
164  * Example of use:
165  * \include example-Geodesic.cpp
166  *
167  * <a href="GeodSolve.1.html">GeodSolve</a> is a command-line utility
168  * providing access to the functionality of Geodesic and GeodesicLine.
169  **********************************************************************/
170 
172  private:
173  typedef Math::real real;
174  friend class GeodesicLine;
175  static const int nA1_ = GEOGRAPHICLIB_GEODESIC_ORDER;
176  static const int nC1_ = GEOGRAPHICLIB_GEODESIC_ORDER;
177  static const int nC1p_ = GEOGRAPHICLIB_GEODESIC_ORDER;
178  static const int nA2_ = GEOGRAPHICLIB_GEODESIC_ORDER;
179  static const int nC2_ = GEOGRAPHICLIB_GEODESIC_ORDER;
180  static const int nA3_ = GEOGRAPHICLIB_GEODESIC_ORDER;
181  static const int nA3x_ = nA3_;
182  static const int nC3_ = GEOGRAPHICLIB_GEODESIC_ORDER;
183  static const int nC3x_ = (nC3_ * (nC3_ - 1)) / 2;
184  static const int nC4_ = GEOGRAPHICLIB_GEODESIC_ORDER;
185  static const int nC4x_ = (nC4_ * (nC4_ + 1)) / 2;
186  static const unsigned maxit1_ = 20;
187  unsigned maxit2_;
188  real tiny_, tol0_, tol1_, tol2_, tolb_, xthresh_;
189 
190  enum captype {
191  CAP_NONE = 0U,
192  CAP_C1 = 1U<<0,
193  CAP_C1p = 1U<<1,
194  CAP_C2 = 1U<<2,
195  CAP_C3 = 1U<<3,
196  CAP_C4 = 1U<<4,
197  CAP_ALL = 0x1FU,
198  CAP_MASK = CAP_ALL,
199  OUT_ALL = 0x7F80U,
200  OUT_MASK = 0xFF80U, // Includes LONG_UNROLL
201  };
202 
203  static real SinCosSeries(bool sinp,
204  real sinx, real cosx, const real c[], int n);
205  static real Astroid(real x, real y);
206 
207  real _a, _f, _f1, _e2, _ep2, _n, _b, _c2, _etol2;
208  real _A3x[nA3x_], _C3x[nC3x_], _C4x[nC4x_];
209 
210  void Lengths(real eps, real sig12,
211  real ssig1, real csig1, real dn1,
212  real ssig2, real csig2, real dn2,
213  real cbet1, real cbet2,
214  real& s12s, real& m12a, real& m0,
215  bool scalep, real& M12, real& M21,
216  real C1a[], real C2a[]) const;
217  real InverseStart(real sbet1, real cbet1, real dn1,
218  real sbet2, real cbet2, real dn2,
219  real lam12,
220  real& salp1, real& calp1,
221  real& salp2, real& calp2, real& dnm,
222  real C1a[], real C2a[]) const;
223  real Lambda12(real sbet1, real cbet1, real dn1,
224  real sbet2, real cbet2, real dn2,
225  real salp1, real calp1,
226  real& salp2, real& calp2, real& sig12,
227  real& ssig1, real& csig1, real& ssig2, real& csig2,
228  real& eps, real& domg12, bool diffp, real& dlam12,
229  real C1a[], real C2a[], real C3a[])
230  const;
231 
232  // These are Maxima generated functions to provide series approximations to
233  // the integrals for the ellipsoidal geodesic.
234  static real A1m1f(real eps);
235  static void C1f(real eps, real c[]);
236  static void C1pf(real eps, real c[]);
237  static real A2m1f(real eps);
238  static void C2f(real eps, real c[]);
239 
240  void A3coeff();
241  real A3f(real eps) const;
242  void C3coeff();
243  void C3f(real eps, real c[]) const;
244  void C4coeff();
245  void C4f(real k2, real c[]) const;
246 
247  public:
248 
249  /**
250  * Bit masks for what calculations to do. These masks do double duty.
251  * They signify to the GeodesicLine::GeodesicLine constructor and to
252  * Geodesic::Line what capabilities should be included in the GeodesicLine
253  * object. They also specify which results to return in the general
254  * routines Geodesic::GenDirect and Geodesic::GenInverse routines.
255  * GeodesicLine::mask is a duplication of this enum.
256  **********************************************************************/
257  enum mask {
258  /**
259  * No capabilities, no output.
260  * @hideinitializer
261  **********************************************************************/
262  NONE = 0U,
263  /**
264  * Calculate latitude \e lat2. (It's not necessary to include this as a
265  * capability to GeodesicLine because this is included by default.)
266  * @hideinitializer
267  **********************************************************************/
268  LATITUDE = 1U<<7 | CAP_NONE,
269  /**
270  * Calculate longitude \e lon2.
271  * @hideinitializer
272  **********************************************************************/
273  LONGITUDE = 1U<<8 | CAP_C3,
274  /**
275  * Calculate azimuths \e azi1 and \e azi2. (It's not necessary to
276  * include this as a capability to GeodesicLine because this is included
277  * by default.)
278  * @hideinitializer
279  **********************************************************************/
280  AZIMUTH = 1U<<9 | CAP_NONE,
281  /**
282  * Calculate distance \e s12.
283  * @hideinitializer
284  **********************************************************************/
285  DISTANCE = 1U<<10 | CAP_C1,
286  /**
287  * Allow distance \e s12 to be used as input in the direct geodesic
288  * problem.
289  * @hideinitializer
290  **********************************************************************/
291  DISTANCE_IN = 1U<<11 | CAP_C1 | CAP_C1p,
292  /**
293  * Calculate reduced length \e m12.
294  * @hideinitializer
295  **********************************************************************/
296  REDUCEDLENGTH = 1U<<12 | CAP_C1 | CAP_C2,
297  /**
298  * Calculate geodesic scales \e M12 and \e M21.
299  * @hideinitializer
300  **********************************************************************/
301  GEODESICSCALE = 1U<<13 | CAP_C1 | CAP_C2,
302  /**
303  * Calculate area \e S12.
304  * @hideinitializer
305  **********************************************************************/
306  AREA = 1U<<14 | CAP_C4,
307  /**
308  * Unroll \e lon2 in the direct calculation. (This flag used to be
309  * called LONG_NOWRAP.)
310  * @hideinitializer
311  **********************************************************************/
312  LONG_UNROLL = 1U<<15,
313  /// \cond SKIP
314  LONG_NOWRAP = LONG_UNROLL,
315  /// \endcond
316  /**
317  * All capabilities, calculate everything. (LONG_UNROLL is not
318  * included in this mask.)
319  * @hideinitializer
320  **********************************************************************/
321  ALL = OUT_ALL| CAP_ALL,
322  };
323 
324  /** \name Constructor
325  **********************************************************************/
326  ///@{
327  /**
328  * Constructor for a ellipsoid with
329  *
330  * @param[in] a equatorial radius (meters).
331  * @param[in] f flattening of ellipsoid. Setting \e f = 0 gives a sphere.
332  * Negative \e f gives a prolate ellipsoid. If \e f &gt; 1, set
333  * flattening to 1/\e f.
334  * @exception GeographicErr if \e a or (1 &minus; \e f) \e a is not
335  * positive.
336  **********************************************************************/
337  Geodesic(real a, real f);
338  ///@}
339 
340  /** \name Direct geodesic problem specified in terms of distance.
341  **********************************************************************/
342  ///@{
343  /**
344  * Solve the direct geodesic problem where the length of the geodesic
345  * is specified in terms of distance.
346  *
347  * @param[in] lat1 latitude of point 1 (degrees).
348  * @param[in] lon1 longitude of point 1 (degrees).
349  * @param[in] azi1 azimuth at point 1 (degrees).
350  * @param[in] s12 distance between point 1 and point 2 (meters); it can be
351  * negative.
352  * @param[out] lat2 latitude of point 2 (degrees).
353  * @param[out] lon2 longitude of point 2 (degrees).
354  * @param[out] azi2 (forward) azimuth at point 2 (degrees).
355  * @param[out] m12 reduced length of geodesic (meters).
356  * @param[out] M12 geodesic scale of point 2 relative to point 1
357  * (dimensionless).
358  * @param[out] M21 geodesic scale of point 1 relative to point 2
359  * (dimensionless).
360  * @param[out] S12 area under the geodesic (meters<sup>2</sup>).
361  * @return \e a12 arc length of between point 1 and point 2 (degrees).
362  *
363  * \e lat1 should be in the range [&minus;90&deg;, 90&deg;]; \e lon1 and \e
364  * azi1 should be in the range [&minus;540&deg;, 540&deg;). The values of
365  * \e lon2 and \e azi2 returned are in the range [&minus;180&deg;,
366  * 180&deg;).
367  *
368  * If either point is at a pole, the azimuth is defined by keeping the
369  * longitude fixed, writing \e lat = &plusmn;(90&deg; &minus; &epsilon;),
370  * and taking the limit &epsilon; &rarr; 0+. An arc length greater that
371  * 180&deg; signifies a geodesic which is not a shortest path. (For a
372  * prolate ellipsoid, an additional condition is necessary for a shortest
373  * path: the longitudinal extent must not exceed of 180&deg;.)
374  *
375  * The following functions are overloaded versions of Geodesic::Direct
376  * which omit some of the output parameters. Note, however, that the arc
377  * length is always computed and returned as the function value.
378  **********************************************************************/
379  Math::real Direct(real lat1, real lon1, real azi1, real s12,
380  real& lat2, real& lon2, real& azi2,
381  real& m12, real& M12, real& M21, real& S12)
382  const {
383  real t;
384  return GenDirect(lat1, lon1, azi1, false, s12,
385  LATITUDE | LONGITUDE | AZIMUTH |
386  REDUCEDLENGTH | GEODESICSCALE | AREA,
387  lat2, lon2, azi2, t, m12, M12, M21, S12);
388  }
389 
390  /**
391  * See the documentation for Geodesic::Direct.
392  **********************************************************************/
393  Math::real Direct(real lat1, real lon1, real azi1, real s12,
394  real& lat2, real& lon2)
395  const {
396  real t;
397  return GenDirect(lat1, lon1, azi1, false, s12,
398  LATITUDE | LONGITUDE,
399  lat2, lon2, t, t, t, t, t, t);
400  }
401 
402  /**
403  * See the documentation for Geodesic::Direct.
404  **********************************************************************/
405  Math::real Direct(real lat1, real lon1, real azi1, real s12,
406  real& lat2, real& lon2, real& azi2)
407  const {
408  real t;
409  return GenDirect(lat1, lon1, azi1, false, s12,
410  LATITUDE | LONGITUDE | AZIMUTH,
411  lat2, lon2, azi2, t, t, t, t, t);
412  }
413 
414  /**
415  * See the documentation for Geodesic::Direct.
416  **********************************************************************/
417  Math::real Direct(real lat1, real lon1, real azi1, real s12,
418  real& lat2, real& lon2, real& azi2, real& m12)
419  const {
420  real t;
421  return GenDirect(lat1, lon1, azi1, false, s12,
422  LATITUDE | LONGITUDE | AZIMUTH | REDUCEDLENGTH,
423  lat2, lon2, azi2, t, m12, t, t, t);
424  }
425 
426  /**
427  * See the documentation for Geodesic::Direct.
428  **********************************************************************/
429  Math::real Direct(real lat1, real lon1, real azi1, real s12,
430  real& lat2, real& lon2, real& azi2,
431  real& M12, real& M21)
432  const {
433  real t;
434  return GenDirect(lat1, lon1, azi1, false, s12,
435  LATITUDE | LONGITUDE | AZIMUTH | GEODESICSCALE,
436  lat2, lon2, azi2, t, t, M12, M21, t);
437  }
438 
439  /**
440  * See the documentation for Geodesic::Direct.
441  **********************************************************************/
442  Math::real Direct(real lat1, real lon1, real azi1, real s12,
443  real& lat2, real& lon2, real& azi2,
444  real& m12, real& M12, real& M21)
445  const {
446  real t;
447  return GenDirect(lat1, lon1, azi1, false, s12,
448  LATITUDE | LONGITUDE | AZIMUTH |
449  REDUCEDLENGTH | GEODESICSCALE,
450  lat2, lon2, azi2, t, m12, M12, M21, t);
451  }
452  ///@}
453 
454  /** \name Direct geodesic problem specified in terms of arc length.
455  **********************************************************************/
456  ///@{
457  /**
458  * Solve the direct geodesic problem where the length of the geodesic
459  * is specified in terms of arc length.
460  *
461  * @param[in] lat1 latitude of point 1 (degrees).
462  * @param[in] lon1 longitude of point 1 (degrees).
463  * @param[in] azi1 azimuth at point 1 (degrees).
464  * @param[in] a12 arc length between point 1 and point 2 (degrees); it can
465  * be negative.
466  * @param[out] lat2 latitude of point 2 (degrees).
467  * @param[out] lon2 longitude of point 2 (degrees).
468  * @param[out] azi2 (forward) azimuth at point 2 (degrees).
469  * @param[out] s12 distance between point 1 and point 2 (meters).
470  * @param[out] m12 reduced length of geodesic (meters).
471  * @param[out] M12 geodesic scale of point 2 relative to point 1
472  * (dimensionless).
473  * @param[out] M21 geodesic scale of point 1 relative to point 2
474  * (dimensionless).
475  * @param[out] S12 area under the geodesic (meters<sup>2</sup>).
476  *
477  * \e lat1 should be in the range [&minus;90&deg;, 90&deg;]; \e lon1 and \e
478  * azi1 should be in the range [&minus;540&deg;, 540&deg;). The values of
479  * \e lon2 and \e azi2 returned are in the range [&minus;180&deg;,
480  * 180&deg;).
481  *
482  * If either point is at a pole, the azimuth is defined by keeping the
483  * longitude fixed, writing \e lat = &plusmn;(90&deg; &minus; &epsilon;),
484  * and taking the limit &epsilon; &rarr; 0+. An arc length greater that
485  * 180&deg; signifies a geodesic which is not a shortest path. (For a
486  * prolate ellipsoid, an additional condition is necessary for a shortest
487  * path: the longitudinal extent must not exceed of 180&deg;.)
488  *
489  * The following functions are overloaded versions of Geodesic::Direct
490  * which omit some of the output parameters.
491  **********************************************************************/
492  void ArcDirect(real lat1, real lon1, real azi1, real a12,
493  real& lat2, real& lon2, real& azi2, real& s12,
494  real& m12, real& M12, real& M21, real& S12)
495  const {
496  GenDirect(lat1, lon1, azi1, true, a12,
497  LATITUDE | LONGITUDE | AZIMUTH | DISTANCE |
498  REDUCEDLENGTH | GEODESICSCALE | AREA,
499  lat2, lon2, azi2, s12, m12, M12, M21, S12);
500  }
501 
502  /**
503  * See the documentation for Geodesic::ArcDirect.
504  **********************************************************************/
505  void ArcDirect(real lat1, real lon1, real azi1, real a12,
506  real& lat2, real& lon2) const {
507  real t;
508  GenDirect(lat1, lon1, azi1, true, a12,
509  LATITUDE | LONGITUDE,
510  lat2, lon2, t, t, t, t, t, t);
511  }
512 
513  /**
514  * See the documentation for Geodesic::ArcDirect.
515  **********************************************************************/
516  void ArcDirect(real lat1, real lon1, real azi1, real a12,
517  real& lat2, real& lon2, real& azi2) const {
518  real t;
519  GenDirect(lat1, lon1, azi1, true, a12,
520  LATITUDE | LONGITUDE | AZIMUTH,
521  lat2, lon2, azi2, t, t, t, t, t);
522  }
523 
524  /**
525  * See the documentation for Geodesic::ArcDirect.
526  **********************************************************************/
527  void ArcDirect(real lat1, real lon1, real azi1, real a12,
528  real& lat2, real& lon2, real& azi2, real& s12)
529  const {
530  real t;
531  GenDirect(lat1, lon1, azi1, true, a12,
532  LATITUDE | LONGITUDE | AZIMUTH | DISTANCE,
533  lat2, lon2, azi2, s12, t, t, t, t);
534  }
535 
536  /**
537  * See the documentation for Geodesic::ArcDirect.
538  **********************************************************************/
539  void ArcDirect(real lat1, real lon1, real azi1, real a12,
540  real& lat2, real& lon2, real& azi2,
541  real& s12, real& m12) const {
542  real t;
543  GenDirect(lat1, lon1, azi1, true, a12,
544  LATITUDE | LONGITUDE | AZIMUTH | DISTANCE |
545  REDUCEDLENGTH,
546  lat2, lon2, azi2, s12, m12, t, t, t);
547  }
548 
549  /**
550  * See the documentation for Geodesic::ArcDirect.
551  **********************************************************************/
552  void ArcDirect(real lat1, real lon1, real azi1, real a12,
553  real& lat2, real& lon2, real& azi2, real& s12,
554  real& M12, real& M21) const {
555  real t;
556  GenDirect(lat1, lon1, azi1, true, a12,
557  LATITUDE | LONGITUDE | AZIMUTH | DISTANCE |
558  GEODESICSCALE,
559  lat2, lon2, azi2, s12, t, M12, M21, t);
560  }
561 
562  /**
563  * See the documentation for Geodesic::ArcDirect.
564  **********************************************************************/
565  void ArcDirect(real lat1, real lon1, real azi1, real a12,
566  real& lat2, real& lon2, real& azi2, real& s12,
567  real& m12, real& M12, real& M21) const {
568  real t;
569  GenDirect(lat1, lon1, azi1, true, a12,
570  LATITUDE | LONGITUDE | AZIMUTH | DISTANCE |
571  REDUCEDLENGTH | GEODESICSCALE,
572  lat2, lon2, azi2, s12, m12, M12, M21, t);
573  }
574  ///@}
575 
576  /** \name General version of the direct geodesic solution.
577  **********************************************************************/
578  ///@{
579 
580  /**
581  * The general direct geodesic problem. Geodesic::Direct and
582  * Geodesic::ArcDirect are defined in terms of this function.
583  *
584  * @param[in] lat1 latitude of point 1 (degrees).
585  * @param[in] lon1 longitude of point 1 (degrees).
586  * @param[in] azi1 azimuth at point 1 (degrees).
587  * @param[in] arcmode boolean flag determining the meaning of the \e
588  * s12_a12.
589  * @param[in] s12_a12 if \e arcmode is false, this is the distance between
590  * point 1 and point 2 (meters); otherwise it is the arc length between
591  * point 1 and point 2 (degrees); it can be negative.
592  * @param[in] outmask a bitor'ed combination of Geodesic::mask values
593  * specifying which of the following parameters should be set.
594  * @param[out] lat2 latitude of point 2 (degrees).
595  * @param[out] lon2 longitude of point 2 (degrees).
596  * @param[out] azi2 (forward) azimuth at point 2 (degrees).
597  * @param[out] s12 distance between point 1 and point 2 (meters).
598  * @param[out] m12 reduced length of geodesic (meters).
599  * @param[out] M12 geodesic scale of point 2 relative to point 1
600  * (dimensionless).
601  * @param[out] M21 geodesic scale of point 1 relative to point 2
602  * (dimensionless).
603  * @param[out] S12 area under the geodesic (meters<sup>2</sup>).
604  * @return \e a12 arc length of between point 1 and point 2 (degrees).
605  *
606  * The Geodesic::mask values possible for \e outmask are
607  * - \e outmask |= Geodesic::LATITUDE for the latitude \e lat2;
608  * - \e outmask |= Geodesic::LONGITUDE for the latitude \e lon2;
609  * - \e outmask |= Geodesic::AZIMUTH for the latitude \e azi2;
610  * - \e outmask |= Geodesic::DISTANCE for the distance \e s12;
611  * - \e outmask |= Geodesic::REDUCEDLENGTH for the reduced length \e
612  * m12;
613  * - \e outmask |= Geodesic::GEODESICSCALE for the geodesic scales \e
614  * M12 and \e M21;
615  * - \e outmask |= Geodesic::AREA for the area \e S12;
616  * - \e outmask |= Geodesic::ALL for all of the above;
617  * - \e outmask |= Geodesic::LONG_UNROLL to unroll \e lon2 instead of
618  * wrapping it into the range [&minus;180&deg;, 180&deg;).
619  * .
620  * The function value \e a12 is always computed and returned and this
621  * equals \e s12_a12 is \e arcmode is true. If \e outmask includes
622  * Geodesic::DISTANCE and \e arcmode is false, then \e s12 = \e s12_a12.
623  * It is not necessary to include Geodesic::DISTANCE_IN in \e outmask; this
624  * is automatically included is \e arcmode is false.
625  *
626  * With the Geodesic::LONG_UNROLL bit set, the quantity \e lon2 &minus; \e
627  * lon1 indicates how many times and in what sense the geodesic encircles
628  * the ellipsoid. Because \e lon2 might be outside the normal allowed
629  * range for longitudes, [&minus;540&deg;, 540&deg;), be sure to normalize
630  * it with Math::AngNormalize2 before using it in other GeographicLib
631  * calls.
632  **********************************************************************/
633  Math::real GenDirect(real lat1, real lon1, real azi1,
634  bool arcmode, real s12_a12, unsigned outmask,
635  real& lat2, real& lon2, real& azi2,
636  real& s12, real& m12, real& M12, real& M21,
637  real& S12) const;
638  ///@}
639 
640  /** \name Inverse geodesic problem.
641  **********************************************************************/
642  ///@{
643  /**
644  * Solve the inverse geodesic problem.
645  *
646  * @param[in] lat1 latitude of point 1 (degrees).
647  * @param[in] lon1 longitude of point 1 (degrees).
648  * @param[in] lat2 latitude of point 2 (degrees).
649  * @param[in] lon2 longitude of point 2 (degrees).
650  * @param[out] s12 distance between point 1 and point 2 (meters).
651  * @param[out] azi1 azimuth at point 1 (degrees).
652  * @param[out] azi2 (forward) azimuth at point 2 (degrees).
653  * @param[out] m12 reduced length of geodesic (meters).
654  * @param[out] M12 geodesic scale of point 2 relative to point 1
655  * (dimensionless).
656  * @param[out] M21 geodesic scale of point 1 relative to point 2
657  * (dimensionless).
658  * @param[out] S12 area under the geodesic (meters<sup>2</sup>).
659  * @return \e a12 arc length of between point 1 and point 2 (degrees).
660  *
661  * \e lat1 and \e lat2 should be in the range [&minus;90&deg;, 90&deg;]; \e
662  * lon1 and \e lon2 should be in the range [&minus;540&deg;, 540&deg;).
663  * The values of \e azi1 and \e azi2 returned are in the range
664  * [&minus;180&deg;, 180&deg;).
665  *
666  * If either point is at a pole, the azimuth is defined by keeping the
667  * longitude fixed, writing \e lat = &plusmn;(90&deg; &minus; &epsilon;),
668  * and taking the limit &epsilon; &rarr; 0+.
669  *
670  * The solution to the inverse problem is found using Newton's method. If
671  * this fails to converge (this is very unlikely in geodetic applications
672  * but does occur for very eccentric ellipsoids), then the bisection method
673  * is used to refine the solution.
674  *
675  * The following functions are overloaded versions of Geodesic::Inverse
676  * which omit some of the output parameters. Note, however, that the arc
677  * length is always computed and returned as the function value.
678  **********************************************************************/
679  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
680  real& s12, real& azi1, real& azi2, real& m12,
681  real& M12, real& M21, real& S12) const {
682  return GenInverse(lat1, lon1, lat2, lon2,
683  DISTANCE | AZIMUTH |
684  REDUCEDLENGTH | GEODESICSCALE | AREA,
685  s12, azi1, azi2, m12, M12, M21, S12);
686  }
687 
688  /**
689  * See the documentation for Geodesic::Inverse.
690  **********************************************************************/
691  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
692  real& s12) const {
693  real t;
694  return GenInverse(lat1, lon1, lat2, lon2,
695  DISTANCE,
696  s12, t, t, t, t, t, t);
697  }
698 
699  /**
700  * See the documentation for Geodesic::Inverse.
701  **********************************************************************/
702  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
703  real& azi1, real& azi2) const {
704  real t;
705  return GenInverse(lat1, lon1, lat2, lon2,
706  AZIMUTH,
707  t, azi1, azi2, t, t, t, t);
708  }
709 
710  /**
711  * See the documentation for Geodesic::Inverse.
712  **********************************************************************/
713  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
714  real& s12, real& azi1, real& azi2)
715  const {
716  real t;
717  return GenInverse(lat1, lon1, lat2, lon2,
718  DISTANCE | AZIMUTH,
719  s12, azi1, azi2, t, t, t, t);
720  }
721 
722  /**
723  * See the documentation for Geodesic::Inverse.
724  **********************************************************************/
725  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
726  real& s12, real& azi1, real& azi2, real& m12)
727  const {
728  real t;
729  return GenInverse(lat1, lon1, lat2, lon2,
730  DISTANCE | AZIMUTH | REDUCEDLENGTH,
731  s12, azi1, azi2, m12, t, t, t);
732  }
733 
734  /**
735  * See the documentation for Geodesic::Inverse.
736  **********************************************************************/
737  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
738  real& s12, real& azi1, real& azi2,
739  real& M12, real& M21) const {
740  real t;
741  return GenInverse(lat1, lon1, lat2, lon2,
742  DISTANCE | AZIMUTH | GEODESICSCALE,
743  s12, azi1, azi2, t, M12, M21, t);
744  }
745 
746  /**
747  * See the documentation for Geodesic::Inverse.
748  **********************************************************************/
749  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
750  real& s12, real& azi1, real& azi2, real& m12,
751  real& M12, real& M21) const {
752  real t;
753  return GenInverse(lat1, lon1, lat2, lon2,
754  DISTANCE | AZIMUTH |
755  REDUCEDLENGTH | GEODESICSCALE,
756  s12, azi1, azi2, m12, M12, M21, t);
757  }
758  ///@}
759 
760  /** \name General version of inverse geodesic solution.
761  **********************************************************************/
762  ///@{
763  /**
764  * The general inverse geodesic calculation. Geodesic::Inverse is defined
765  * in terms of this function.
766  *
767  * @param[in] lat1 latitude of point 1 (degrees).
768  * @param[in] lon1 longitude of point 1 (degrees).
769  * @param[in] lat2 latitude of point 2 (degrees).
770  * @param[in] lon2 longitude of point 2 (degrees).
771  * @param[in] outmask a bitor'ed combination of Geodesic::mask values
772  * specifying which of the following parameters should be set.
773  * @param[out] s12 distance between point 1 and point 2 (meters).
774  * @param[out] azi1 azimuth at point 1 (degrees).
775  * @param[out] azi2 (forward) azimuth at point 2 (degrees).
776  * @param[out] m12 reduced length of geodesic (meters).
777  * @param[out] M12 geodesic scale of point 2 relative to point 1
778  * (dimensionless).
779  * @param[out] M21 geodesic scale of point 1 relative to point 2
780  * (dimensionless).
781  * @param[out] S12 area under the geodesic (meters<sup>2</sup>).
782  * @return \e a12 arc length of between point 1 and point 2 (degrees).
783  *
784  * The Geodesic::mask values possible for \e outmask are
785  * - \e outmask |= Geodesic::DISTANCE for the distance \e s12;
786  * - \e outmask |= Geodesic::AZIMUTH for the latitude \e azi2;
787  * - \e outmask |= Geodesic::REDUCEDLENGTH for the reduced length \e
788  * m12;
789  * - \e outmask |= Geodesic::GEODESICSCALE for the geodesic scales \e
790  * M12 and \e M21;
791  * - \e outmask |= Geodesic::AREA for the area \e S12;
792  * - \e outmask |= Geodesic::ALL for all of the above.
793  * .
794  * The arc length is always computed and returned as the function value.
795  **********************************************************************/
796  Math::real GenInverse(real lat1, real lon1, real lat2, real lon2,
797  unsigned outmask,
798  real& s12, real& azi1, real& azi2,
799  real& m12, real& M12, real& M21, real& S12)
800  const;
801  ///@}
802 
803  /** \name Interface to GeodesicLine.
804  **********************************************************************/
805  ///@{
806 
807  /**
808  * Set up to compute several points on a single geodesic.
809  *
810  * @param[in] lat1 latitude of point 1 (degrees).
811  * @param[in] lon1 longitude of point 1 (degrees).
812  * @param[in] azi1 azimuth at point 1 (degrees).
813  * @param[in] caps bitor'ed combination of Geodesic::mask values
814  * specifying the capabilities the GeodesicLine object should possess,
815  * i.e., which quantities can be returned in calls to
816  * GeodesicLine::Position.
817  * @return a GeodesicLine object.
818  *
819  * \e lat1 should be in the range [&minus;90&deg;, 90&deg;]; \e lon1 and \e
820  * azi1 should be in the range [&minus;540&deg;, 540&deg;).
821  *
822  * The Geodesic::mask values are
823  * - \e caps |= Geodesic::LATITUDE for the latitude \e lat2; this is
824  * added automatically;
825  * - \e caps |= Geodesic::LONGITUDE for the latitude \e lon2;
826  * - \e caps |= Geodesic::AZIMUTH for the azimuth \e azi2; this is
827  * added automatically;
828  * - \e caps |= Geodesic::DISTANCE for the distance \e s12;
829  * - \e caps |= Geodesic::REDUCEDLENGTH for the reduced length \e m12;
830  * - \e caps |= Geodesic::GEODESICSCALE for the geodesic scales \e M12
831  * and \e M21;
832  * - \e caps |= Geodesic::AREA for the area \e S12;
833  * - \e caps |= Geodesic::DISTANCE_IN permits the length of the
834  * geodesic to be given in terms of \e s12; without this capability the
835  * length can only be specified in terms of arc length;
836  * - \e caps |= Geodesic::ALL for all of the above.
837  * .
838  * The default value of \e caps is Geodesic::ALL.
839  *
840  * If the point is at a pole, the azimuth is defined by keeping \e lon1
841  * fixed, writing \e lat1 = &plusmn;(90 &minus; &epsilon;), and taking the
842  * limit &epsilon; &rarr; 0+.
843  **********************************************************************/
844  GeodesicLine Line(real lat1, real lon1, real azi1, unsigned caps = ALL)
845  const;
846 
847  ///@}
848 
849  /** \name Inspector functions.
850  **********************************************************************/
851  ///@{
852 
853  /**
854  * @return \e a the equatorial radius of the ellipsoid (meters). This is
855  * the value used in the constructor.
856  **********************************************************************/
857  Math::real MajorRadius() const { return _a; }
858 
859  /**
860  * @return \e f the flattening of the ellipsoid. This is the
861  * value used in the constructor.
862  **********************************************************************/
863  Math::real Flattening() const { return _f; }
864 
865  /// \cond SKIP
866  /**
867  * <b>DEPRECATED</b>
868  * @return \e r the inverse flattening of the ellipsoid.
869  **********************************************************************/
870  Math::real InverseFlattening() const { return 1/_f; }
871  /// \endcond
872 
873  /**
874  * @return total area of ellipsoid in meters<sup>2</sup>. The area of a
875  * polygon encircling a pole can be found by adding
876  * Geodesic::EllipsoidArea()/2 to the sum of \e S12 for each side of the
877  * polygon.
878  **********************************************************************/
880  { return 4 * Math::pi() * _c2; }
881  ///@}
882 
883  /**
884  * A global instantiation of Geodesic with the parameters for the WGS84
885  * ellipsoid.
886  **********************************************************************/
887  static const Geodesic& WGS84();
888 
889  };
890 
891 } // namespace GeographicLib
892 
893 #endif // GEOGRAPHICLIB_GEODESIC_HPP
void ArcDirect(real lat1, real lon1, real azi1, real a12, real &lat2, real &lon2, real &azi2, real &s12, real &M12, real &M21) const
Definition: Geodesic.hpp:552
static T pi()
Definition: Math.hpp:214
#define GEOGRAPHICLIB_EXPORT
Definition: Constants.hpp:90
void ArcDirect(real lat1, real lon1, real azi1, real a12, real &lat2, real &lon2, real &azi2, real &s12, real &m12) const
Definition: Geodesic.hpp:539
Math::real Direct(real lat1, real lon1, real azi1, real s12, real &lat2, real &lon2, real &azi2, real &m12, real &M12, real &M21, real &S12) const
Definition: Geodesic.hpp:379
Math::real Direct(real lat1, real lon1, real azi1, real s12, real &lat2, real &lon2, real &azi2, real &m12) const
Definition: Geodesic.hpp:417
GeographicLib::Math::real real
Definition: GeodSolve.cpp:32
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &s12, real &azi1, real &azi2, real &m12, real &M12, real &M21, real &S12) const
Definition: Geodesic.hpp:679
Math::real MajorRadius() const
Definition: Geodesic.hpp:857
void ArcDirect(real lat1, real lon1, real azi1, real a12, real &lat2, real &lon2) const
Definition: Geodesic.hpp:505
void ArcDirect(real lat1, real lon1, real azi1, real a12, real &lat2, real &lon2, real &azi2, real &s12, real &m12, real &M12, real &M21) const
Definition: Geodesic.hpp:565
Math::real Direct(real lat1, real lon1, real azi1, real s12, real &lat2, real &lon2) const
Definition: Geodesic.hpp:393
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &s12, real &azi1, real &azi2, real &M12, real &M21) const
Definition: Geodesic.hpp:737
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &s12, real &azi1, real &azi2, real &m12) const
Definition: Geodesic.hpp:725
Math::real Direct(real lat1, real lon1, real azi1, real s12, real &lat2, real &lon2, real &azi2, real &m12, real &M12, real &M21) const
Definition: Geodesic.hpp:442
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &s12, real &azi1, real &azi2) const
Definition: Geodesic.hpp:713
Namespace for GeographicLib.
Definition: Accumulator.cpp:12
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &s12) const
Definition: Geodesic.hpp:691
Math::real EllipsoidArea() const
Definition: Geodesic.hpp:879
void ArcDirect(real lat1, real lon1, real azi1, real a12, real &lat2, real &lon2, real &azi2) const
Definition: Geodesic.hpp:516
void ArcDirect(real lat1, real lon1, real azi1, real a12, real &lat2, real &lon2, real &azi2, real &s12, real &m12, real &M12, real &M21, real &S12) const
Definition: Geodesic.hpp:492
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &s12, real &azi1, real &azi2, real &m12, real &M12, real &M21) const
Definition: Geodesic.hpp:749
Header for GeographicLib::Constants class.
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &azi1, real &azi2) const
Definition: Geodesic.hpp:702
void ArcDirect(real lat1, real lon1, real azi1, real a12, real &lat2, real &lon2, real &azi2, real &s12) const
Definition: Geodesic.hpp:527
#define GEOGRAPHICLIB_GEODESIC_ORDER
Definition: Geodesic.hpp:20
Math::real Direct(real lat1, real lon1, real azi1, real s12, real &lat2, real &lon2, real &azi2) const
Definition: Geodesic.hpp:405
Math::real Direct(real lat1, real lon1, real azi1, real s12, real &lat2, real &lon2, real &azi2, real &M12, real &M21) const
Definition: Geodesic.hpp:429
Math::real Flattening() const
Definition: Geodesic.hpp:863
Geodesic calculations
Definition: Geodesic.hpp:171