GeographicLib  1.42
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 [0, 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_NOWRAP
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  * Do not wrap the \e lon2 in the direct calculation.
309  * @hideinitializer
310  **********************************************************************/
311  LONG_NOWRAP = 1U<<15,
312  /**
313  * All capabilities, calculate everything. (LONG_NOWRAP is not
314  * included in this mask.)
315  * @hideinitializer
316  **********************************************************************/
317  ALL = OUT_ALL| CAP_ALL,
318  };
319 
320  /** \name Constructor
321  **********************************************************************/
322  ///@{
323  /**
324  * Constructor for a ellipsoid with
325  *
326  * @param[in] a equatorial radius (meters).
327  * @param[in] f flattening of ellipsoid. Setting \e f = 0 gives a sphere.
328  * Negative \e f gives a prolate ellipsoid. If \e f &gt; 1, set
329  * flattening to 1/\e f.
330  * @exception GeographicErr if \e a or (1 &minus; \e f) \e a is not
331  * positive.
332  **********************************************************************/
333  Geodesic(real a, real f);
334  ///@}
335 
336  /** \name Direct geodesic problem specified in terms of distance.
337  **********************************************************************/
338  ///@{
339  /**
340  * Solve the direct geodesic problem where the length of the geodesic
341  * is specified in terms of distance.
342  *
343  * @param[in] lat1 latitude of point 1 (degrees).
344  * @param[in] lon1 longitude of point 1 (degrees).
345  * @param[in] azi1 azimuth at point 1 (degrees).
346  * @param[in] s12 distance between point 1 and point 2 (meters); it can be
347  * negative.
348  * @param[out] lat2 latitude of point 2 (degrees).
349  * @param[out] lon2 longitude of point 2 (degrees).
350  * @param[out] azi2 (forward) azimuth at point 2 (degrees).
351  * @param[out] m12 reduced length of geodesic (meters).
352  * @param[out] M12 geodesic scale of point 2 relative to point 1
353  * (dimensionless).
354  * @param[out] M21 geodesic scale of point 1 relative to point 2
355  * (dimensionless).
356  * @param[out] S12 area under the geodesic (meters<sup>2</sup>).
357  * @return \e a12 arc length of between point 1 and point 2 (degrees).
358  *
359  * \e lat1 should be in the range [&minus;90&deg;, 90&deg;]; \e lon1 and \e
360  * azi1 should be in the range [&minus;540&deg;, 540&deg;). The values of
361  * \e lon2 and \e azi2 returned are in the range [&minus;180&deg;,
362  * 180&deg;).
363  *
364  * If either point is at a pole, the azimuth is defined by keeping the
365  * longitude fixed, writing \e lat = &plusmn;(90&deg; &minus; &epsilon;),
366  * and taking the limit &epsilon; &rarr; 0+. An arc length greater that
367  * 180&deg; signifies a geodesic which is not a shortest path. (For a
368  * prolate ellipsoid, an additional condition is necessary for a shortest
369  * path: the longitudinal extent must not exceed of 180&deg;.)
370  *
371  * The following functions are overloaded versions of Geodesic::Direct
372  * which omit some of the output parameters. Note, however, that the arc
373  * length is always computed and returned as the function value.
374  **********************************************************************/
375  Math::real Direct(real lat1, real lon1, real azi1, real s12,
376  real& lat2, real& lon2, real& azi2,
377  real& m12, real& M12, real& M21, real& S12)
378  const {
379  real t;
380  return GenDirect(lat1, lon1, azi1, false, s12,
381  LATITUDE | LONGITUDE | AZIMUTH |
382  REDUCEDLENGTH | GEODESICSCALE | AREA,
383  lat2, lon2, azi2, t, m12, M12, M21, S12);
384  }
385 
386  /**
387  * See the documentation for Geodesic::Direct.
388  **********************************************************************/
389  Math::real Direct(real lat1, real lon1, real azi1, real s12,
390  real& lat2, real& lon2)
391  const {
392  real t;
393  return GenDirect(lat1, lon1, azi1, false, s12,
394  LATITUDE | LONGITUDE,
395  lat2, lon2, t, t, t, t, t, t);
396  }
397 
398  /**
399  * See the documentation for Geodesic::Direct.
400  **********************************************************************/
401  Math::real Direct(real lat1, real lon1, real azi1, real s12,
402  real& lat2, real& lon2, real& azi2)
403  const {
404  real t;
405  return GenDirect(lat1, lon1, azi1, false, s12,
406  LATITUDE | LONGITUDE | AZIMUTH,
407  lat2, lon2, azi2, t, t, t, t, t);
408  }
409 
410  /**
411  * See the documentation for Geodesic::Direct.
412  **********************************************************************/
413  Math::real Direct(real lat1, real lon1, real azi1, real s12,
414  real& lat2, real& lon2, real& azi2, real& m12)
415  const {
416  real t;
417  return GenDirect(lat1, lon1, azi1, false, s12,
418  LATITUDE | LONGITUDE | AZIMUTH | REDUCEDLENGTH,
419  lat2, lon2, azi2, t, m12, t, t, t);
420  }
421 
422  /**
423  * See the documentation for Geodesic::Direct.
424  **********************************************************************/
425  Math::real Direct(real lat1, real lon1, real azi1, real s12,
426  real& lat2, real& lon2, real& azi2,
427  real& M12, real& M21)
428  const {
429  real t;
430  return GenDirect(lat1, lon1, azi1, false, s12,
431  LATITUDE | LONGITUDE | AZIMUTH | GEODESICSCALE,
432  lat2, lon2, azi2, t, t, M12, M21, t);
433  }
434 
435  /**
436  * See the documentation for Geodesic::Direct.
437  **********************************************************************/
438  Math::real Direct(real lat1, real lon1, real azi1, real s12,
439  real& lat2, real& lon2, real& azi2,
440  real& m12, real& M12, real& M21)
441  const {
442  real t;
443  return GenDirect(lat1, lon1, azi1, false, s12,
444  LATITUDE | LONGITUDE | AZIMUTH |
445  REDUCEDLENGTH | GEODESICSCALE,
446  lat2, lon2, azi2, t, m12, M12, M21, t);
447  }
448  ///@}
449 
450  /** \name Direct geodesic problem specified in terms of arc length.
451  **********************************************************************/
452  ///@{
453  /**
454  * Solve the direct geodesic problem where the length of the geodesic
455  * is specified in terms of arc length.
456  *
457  * @param[in] lat1 latitude of point 1 (degrees).
458  * @param[in] lon1 longitude of point 1 (degrees).
459  * @param[in] azi1 azimuth at point 1 (degrees).
460  * @param[in] a12 arc length between point 1 and point 2 (degrees); it can
461  * be negative.
462  * @param[out] lat2 latitude of point 2 (degrees).
463  * @param[out] lon2 longitude of point 2 (degrees).
464  * @param[out] azi2 (forward) azimuth at point 2 (degrees).
465  * @param[out] s12 distance between point 1 and point 2 (meters).
466  * @param[out] m12 reduced length of geodesic (meters).
467  * @param[out] M12 geodesic scale of point 2 relative to point 1
468  * (dimensionless).
469  * @param[out] M21 geodesic scale of point 1 relative to point 2
470  * (dimensionless).
471  * @param[out] S12 area under the geodesic (meters<sup>2</sup>).
472  *
473  * \e lat1 should be in the range [&minus;90&deg;, 90&deg;]; \e lon1 and \e
474  * azi1 should be in the range [&minus;540&deg;, 540&deg;). The values of
475  * \e lon2 and \e azi2 returned are in the range [&minus;180&deg;,
476  * 180&deg;).
477  *
478  * If either point is at a pole, the azimuth is defined by keeping the
479  * longitude fixed, writing \e lat = &plusmn;(90&deg; &minus; &epsilon;),
480  * and taking the limit &epsilon; &rarr; 0+. An arc length greater that
481  * 180&deg; signifies a geodesic which is not a shortest path. (For a
482  * prolate ellipsoid, an additional condition is necessary for a shortest
483  * path: the longitudinal extent must not exceed of 180&deg;.)
484  *
485  * The following functions are overloaded versions of Geodesic::Direct
486  * which omit some of the output parameters.
487  **********************************************************************/
488  void ArcDirect(real lat1, real lon1, real azi1, real a12,
489  real& lat2, real& lon2, real& azi2, real& s12,
490  real& m12, real& M12, real& M21, real& S12)
491  const {
492  GenDirect(lat1, lon1, azi1, true, a12,
493  LATITUDE | LONGITUDE | AZIMUTH | DISTANCE |
494  REDUCEDLENGTH | GEODESICSCALE | AREA,
495  lat2, lon2, azi2, s12, m12, M12, M21, S12);
496  }
497 
498  /**
499  * See the documentation for Geodesic::ArcDirect.
500  **********************************************************************/
501  void ArcDirect(real lat1, real lon1, real azi1, real a12,
502  real& lat2, real& lon2) const {
503  real t;
504  GenDirect(lat1, lon1, azi1, true, a12,
505  LATITUDE | LONGITUDE,
506  lat2, lon2, t, t, t, t, t, t);
507  }
508 
509  /**
510  * See the documentation for Geodesic::ArcDirect.
511  **********************************************************************/
512  void ArcDirect(real lat1, real lon1, real azi1, real a12,
513  real& lat2, real& lon2, real& azi2) const {
514  real t;
515  GenDirect(lat1, lon1, azi1, true, a12,
516  LATITUDE | LONGITUDE | AZIMUTH,
517  lat2, lon2, azi2, t, t, t, t, t);
518  }
519 
520  /**
521  * See the documentation for Geodesic::ArcDirect.
522  **********************************************************************/
523  void ArcDirect(real lat1, real lon1, real azi1, real a12,
524  real& lat2, real& lon2, real& azi2, real& s12)
525  const {
526  real t;
527  GenDirect(lat1, lon1, azi1, true, a12,
528  LATITUDE | LONGITUDE | AZIMUTH | DISTANCE,
529  lat2, lon2, azi2, s12, t, t, t, t);
530  }
531 
532  /**
533  * See the documentation for Geodesic::ArcDirect.
534  **********************************************************************/
535  void ArcDirect(real lat1, real lon1, real azi1, real a12,
536  real& lat2, real& lon2, real& azi2,
537  real& s12, real& m12) const {
538  real t;
539  GenDirect(lat1, lon1, azi1, true, a12,
540  LATITUDE | LONGITUDE | AZIMUTH | DISTANCE |
541  REDUCEDLENGTH,
542  lat2, lon2, azi2, s12, m12, t, t, t);
543  }
544 
545  /**
546  * See the documentation for Geodesic::ArcDirect.
547  **********************************************************************/
548  void ArcDirect(real lat1, real lon1, real azi1, real a12,
549  real& lat2, real& lon2, real& azi2, real& s12,
550  real& M12, real& M21) const {
551  real t;
552  GenDirect(lat1, lon1, azi1, true, a12,
553  LATITUDE | LONGITUDE | AZIMUTH | DISTANCE |
554  GEODESICSCALE,
555  lat2, lon2, azi2, s12, t, M12, M21, t);
556  }
557 
558  /**
559  * See the documentation for Geodesic::ArcDirect.
560  **********************************************************************/
561  void ArcDirect(real lat1, real lon1, real azi1, real a12,
562  real& lat2, real& lon2, real& azi2, real& s12,
563  real& m12, real& M12, real& M21) const {
564  real t;
565  GenDirect(lat1, lon1, azi1, true, a12,
566  LATITUDE | LONGITUDE | AZIMUTH | DISTANCE |
567  REDUCEDLENGTH | GEODESICSCALE,
568  lat2, lon2, azi2, s12, m12, M12, M21, t);
569  }
570  ///@}
571 
572  /** \name General version of the direct geodesic solution.
573  **********************************************************************/
574  ///@{
575 
576  /**
577  * The general direct geodesic problem. Geodesic::Direct and
578  * Geodesic::ArcDirect are defined in terms of this function.
579  *
580  * @param[in] lat1 latitude of point 1 (degrees).
581  * @param[in] lon1 longitude of point 1 (degrees).
582  * @param[in] azi1 azimuth at point 1 (degrees).
583  * @param[in] arcmode boolean flag determining the meaning of the \e
584  * s12_a12.
585  * @param[in] s12_a12 if \e arcmode is false, this is the distance between
586  * point 1 and point 2 (meters); otherwise it is the arc length between
587  * point 1 and point 2 (degrees); it can be negative.
588  * @param[in] outmask a bitor'ed combination of Geodesic::mask values
589  * specifying which of the following parameters should be set.
590  * @param[out] lat2 latitude of point 2 (degrees).
591  * @param[out] lon2 longitude of point 2 (degrees).
592  * @param[out] azi2 (forward) azimuth at point 2 (degrees).
593  * @param[out] s12 distance between point 1 and point 2 (meters).
594  * @param[out] m12 reduced length of geodesic (meters).
595  * @param[out] M12 geodesic scale of point 2 relative to point 1
596  * (dimensionless).
597  * @param[out] M21 geodesic scale of point 1 relative to point 2
598  * (dimensionless).
599  * @param[out] S12 area under the geodesic (meters<sup>2</sup>).
600  * @return \e a12 arc length of between point 1 and point 2 (degrees).
601  *
602  * The Geodesic::mask values possible for \e outmask are
603  * - \e outmask |= Geodesic::LATITUDE for the latitude \e lat2;
604  * - \e outmask |= Geodesic::LONGITUDE for the latitude \e lon2;
605  * - \e outmask |= Geodesic::AZIMUTH for the latitude \e azi2;
606  * - \e outmask |= Geodesic::DISTANCE for the distance \e s12;
607  * - \e outmask |= Geodesic::REDUCEDLENGTH for the reduced length \e
608  * m12;
609  * - \e outmask |= Geodesic::GEODESICSCALE for the geodesic scales \e
610  * M12 and \e M21;
611  * - \e outmask |= Geodesic::AREA for the area \e S12;
612  * - \e outmask |= Geodesic::ALL for all of the above;
613  * - \e outmask |= Geodesic::LONG_NOWRAP stops the returned value of \e
614  * lon2 being wrapped into the range [&minus;180&deg;, 180&deg;).
615  * .
616  * The function value \e a12 is always computed and returned and this
617  * equals \e s12_a12 is \e arcmode is true. If \e outmask includes
618  * Geodesic::DISTANCE and \e arcmode is false, then \e s12 = \e s12_a12.
619  * It is not necessary to include Geodesic::DISTANCE_IN in \e outmask; this
620  * is automatically included is \e arcmode is false.
621  *
622  * With the LONG_NOWRAP bit set, the quantity \e lon2 &minus; \e lon1
623  * indicates how many times the geodesic wrapped around the ellipsoid.
624  * Because \e lon2 might be outside the normal allowed range for
625  * longitudes, [&minus;540&deg;, 540&deg;), be sure to normalize it with
626  * Math::AngNormalize2 before using it in other GeographicLib calls.
627  **********************************************************************/
628  Math::real GenDirect(real lat1, real lon1, real azi1,
629  bool arcmode, real s12_a12, unsigned outmask,
630  real& lat2, real& lon2, real& azi2,
631  real& s12, real& m12, real& M12, real& M21,
632  real& S12) const;
633  ///@}
634 
635  /** \name Inverse geodesic problem.
636  **********************************************************************/
637  ///@{
638  /**
639  * Solve the inverse geodesic problem.
640  *
641  * @param[in] lat1 latitude of point 1 (degrees).
642  * @param[in] lon1 longitude of point 1 (degrees).
643  * @param[in] lat2 latitude of point 2 (degrees).
644  * @param[in] lon2 longitude of point 2 (degrees).
645  * @param[out] s12 distance between point 1 and point 2 (meters).
646  * @param[out] azi1 azimuth at point 1 (degrees).
647  * @param[out] azi2 (forward) azimuth at point 2 (degrees).
648  * @param[out] m12 reduced length of geodesic (meters).
649  * @param[out] M12 geodesic scale of point 2 relative to point 1
650  * (dimensionless).
651  * @param[out] M21 geodesic scale of point 1 relative to point 2
652  * (dimensionless).
653  * @param[out] S12 area under the geodesic (meters<sup>2</sup>).
654  * @return \e a12 arc length of between point 1 and point 2 (degrees).
655  *
656  * \e lat1 and \e lat2 should be in the range [&minus;90&deg;, 90&deg;]; \e
657  * lon1 and \e lon2 should be in the range [&minus;540&deg;, 540&deg;).
658  * The values of \e azi1 and \e azi2 returned are in the range
659  * [&minus;180&deg;, 180&deg;).
660  *
661  * If either point is at a pole, the azimuth is defined by keeping the
662  * longitude fixed, writing \e lat = &plusmn;(90&deg; &minus; &epsilon;),
663  * and taking the limit &epsilon; &rarr; 0+.
664  *
665  * The solution to the inverse problem is found using Newton's method. If
666  * this fails to converge (this is very unlikely in geodetic applications
667  * but does occur for very eccentric ellipsoids), then the bisection method
668  * is used to refine the solution.
669  *
670  * The following functions are overloaded versions of Geodesic::Inverse
671  * which omit some of the output parameters. Note, however, that the arc
672  * length is always computed and returned as the function value.
673  **********************************************************************/
674  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
675  real& s12, real& azi1, real& azi2, real& m12,
676  real& M12, real& M21, real& S12) const {
677  return GenInverse(lat1, lon1, lat2, lon2,
678  DISTANCE | AZIMUTH |
679  REDUCEDLENGTH | GEODESICSCALE | AREA,
680  s12, azi1, azi2, m12, M12, M21, S12);
681  }
682 
683  /**
684  * See the documentation for Geodesic::Inverse.
685  **********************************************************************/
686  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
687  real& s12) const {
688  real t;
689  return GenInverse(lat1, lon1, lat2, lon2,
690  DISTANCE,
691  s12, t, t, t, t, t, t);
692  }
693 
694  /**
695  * See the documentation for Geodesic::Inverse.
696  **********************************************************************/
697  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
698  real& azi1, real& azi2) const {
699  real t;
700  return GenInverse(lat1, lon1, lat2, lon2,
701  AZIMUTH,
702  t, azi1, azi2, t, t, t, t);
703  }
704 
705  /**
706  * See the documentation for Geodesic::Inverse.
707  **********************************************************************/
708  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
709  real& s12, real& azi1, real& azi2)
710  const {
711  real t;
712  return GenInverse(lat1, lon1, lat2, lon2,
713  DISTANCE | AZIMUTH,
714  s12, azi1, azi2, t, t, t, t);
715  }
716 
717  /**
718  * See the documentation for Geodesic::Inverse.
719  **********************************************************************/
720  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
721  real& s12, real& azi1, real& azi2, real& m12)
722  const {
723  real t;
724  return GenInverse(lat1, lon1, lat2, lon2,
725  DISTANCE | AZIMUTH | REDUCEDLENGTH,
726  s12, azi1, azi2, m12, t, t, t);
727  }
728 
729  /**
730  * See the documentation for Geodesic::Inverse.
731  **********************************************************************/
732  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
733  real& s12, real& azi1, real& azi2,
734  real& M12, real& M21) const {
735  real t;
736  return GenInverse(lat1, lon1, lat2, lon2,
737  DISTANCE | AZIMUTH | GEODESICSCALE,
738  s12, azi1, azi2, t, M12, M21, t);
739  }
740 
741  /**
742  * See the documentation for Geodesic::Inverse.
743  **********************************************************************/
744  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
745  real& s12, real& azi1, real& azi2, real& m12,
746  real& M12, real& M21) const {
747  real t;
748  return GenInverse(lat1, lon1, lat2, lon2,
749  DISTANCE | AZIMUTH |
750  REDUCEDLENGTH | GEODESICSCALE,
751  s12, azi1, azi2, m12, M12, M21, t);
752  }
753  ///@}
754 
755  /** \name General version of inverse geodesic solution.
756  **********************************************************************/
757  ///@{
758  /**
759  * The general inverse geodesic calculation. Geodesic::Inverse is defined
760  * in terms of this function.
761  *
762  * @param[in] lat1 latitude of point 1 (degrees).
763  * @param[in] lon1 longitude of point 1 (degrees).
764  * @param[in] lat2 latitude of point 2 (degrees).
765  * @param[in] lon2 longitude of point 2 (degrees).
766  * @param[in] outmask a bitor'ed combination of Geodesic::mask values
767  * specifying which of the following parameters should be set.
768  * @param[out] s12 distance between point 1 and point 2 (meters).
769  * @param[out] azi1 azimuth at point 1 (degrees).
770  * @param[out] azi2 (forward) azimuth at point 2 (degrees).
771  * @param[out] m12 reduced length of geodesic (meters).
772  * @param[out] M12 geodesic scale of point 2 relative to point 1
773  * (dimensionless).
774  * @param[out] M21 geodesic scale of point 1 relative to point 2
775  * (dimensionless).
776  * @param[out] S12 area under the geodesic (meters<sup>2</sup>).
777  * @return \e a12 arc length of between point 1 and point 2 (degrees).
778  *
779  * The Geodesic::mask values possible for \e outmask are
780  * - \e outmask |= Geodesic::DISTANCE for the distance \e s12;
781  * - \e outmask |= Geodesic::AZIMUTH for the latitude \e azi2;
782  * - \e outmask |= Geodesic::REDUCEDLENGTH for the reduced length \e
783  * m12;
784  * - \e outmask |= Geodesic::GEODESICSCALE for the geodesic scales \e
785  * M12 and \e M21;
786  * - \e outmask |= Geodesic::AREA for the area \e S12;
787  * - \e outmask |= Geodesic::ALL for all of the above.
788  * .
789  * The arc length is always computed and returned as the function value.
790  **********************************************************************/
791  Math::real GenInverse(real lat1, real lon1, real lat2, real lon2,
792  unsigned outmask,
793  real& s12, real& azi1, real& azi2,
794  real& m12, real& M12, real& M21, real& S12)
795  const;
796  ///@}
797 
798  /** \name Interface to GeodesicLine.
799  **********************************************************************/
800  ///@{
801 
802  /**
803  * Set up to compute several points on a single geodesic.
804  *
805  * @param[in] lat1 latitude of point 1 (degrees).
806  * @param[in] lon1 longitude of point 1 (degrees).
807  * @param[in] azi1 azimuth at point 1 (degrees).
808  * @param[in] caps bitor'ed combination of Geodesic::mask values
809  * specifying the capabilities the GeodesicLine object should possess,
810  * i.e., which quantities can be returned in calls to
811  * GeodesicLine::Position.
812  * @return a GeodesicLine object.
813  *
814  * \e lat1 should be in the range [&minus;90&deg;, 90&deg;]; \e lon1 and \e
815  * azi1 should be in the range [&minus;540&deg;, 540&deg;).
816  *
817  * The Geodesic::mask values are
818  * - \e caps |= Geodesic::LATITUDE for the latitude \e lat2; this is
819  * added automatically;
820  * - \e caps |= Geodesic::LONGITUDE for the latitude \e lon2;
821  * - \e caps |= Geodesic::AZIMUTH for the azimuth \e azi2; this is
822  * added automatically;
823  * - \e caps |= Geodesic::DISTANCE for the distance \e s12;
824  * - \e caps |= Geodesic::REDUCEDLENGTH for the reduced length \e m12;
825  * - \e caps |= Geodesic::GEODESICSCALE for the geodesic scales \e M12
826  * and \e M21;
827  * - \e caps |= Geodesic::AREA for the area \e S12;
828  * - \e caps |= Geodesic::DISTANCE_IN permits the length of the
829  * geodesic to be given in terms of \e s12; without this capability the
830  * length can only be specified in terms of arc length;
831  * - \e caps |= Geodesic::ALL for all of the above.
832  * .
833  * The default value of \e caps is Geodesic::ALL.
834  *
835  * If the point is at a pole, the azimuth is defined by keeping \e lon1
836  * fixed, writing \e lat1 = &plusmn;(90 &minus; &epsilon;), and taking the
837  * limit &epsilon; &rarr; 0+.
838  **********************************************************************/
839  GeodesicLine Line(real lat1, real lon1, real azi1, unsigned caps = ALL)
840  const;
841 
842  ///@}
843 
844  /** \name Inspector functions.
845  **********************************************************************/
846  ///@{
847 
848  /**
849  * @return \e a the equatorial radius of the ellipsoid (meters). This is
850  * the value used in the constructor.
851  **********************************************************************/
852  Math::real MajorRadius() const { return _a; }
853 
854  /**
855  * @return \e f the flattening of the ellipsoid. This is the
856  * value used in the constructor.
857  **********************************************************************/
858  Math::real Flattening() const { return _f; }
859 
860  /// \cond SKIP
861  /**
862  * <b>DEPRECATED</b>
863  * @return \e r the inverse flattening of the ellipsoid.
864  **********************************************************************/
865  Math::real InverseFlattening() const { return 1/_f; }
866  /// \endcond
867 
868  /**
869  * @return total area of ellipsoid in meters<sup>2</sup>. The area of a
870  * polygon encircling a pole can be found by adding
871  * Geodesic::EllipsoidArea()/2 to the sum of \e S12 for each side of the
872  * polygon.
873  **********************************************************************/
875  { return 4 * Math::pi() * _c2; }
876  ///@}
877 
878  /**
879  * A global instantiation of Geodesic with the parameters for the WGS84
880  * ellipsoid.
881  **********************************************************************/
882  static const Geodesic& WGS84();
883 
884  };
885 
886 } // namespace GeographicLib
887 
888 #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:548
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:535
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:375
Math::real Direct(real lat1, real lon1, real azi1, real s12, real &lat2, real &lon2, real &azi2, real &m12) const
Definition: Geodesic.hpp:413
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:674
Math::real MajorRadius() const
Definition: Geodesic.hpp:852
void ArcDirect(real lat1, real lon1, real azi1, real a12, real &lat2, real &lon2) const
Definition: Geodesic.hpp:501
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:561
Math::real Direct(real lat1, real lon1, real azi1, real s12, real &lat2, real &lon2) const
Definition: Geodesic.hpp:389
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:732
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &s12, real &azi1, real &azi2, real &m12) const
Definition: Geodesic.hpp:720
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:438
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &s12, real &azi1, real &azi2) const
Definition: Geodesic.hpp:708
Namespace for GeographicLib.
Definition: Accumulator.cpp:12
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &s12) const
Definition: Geodesic.hpp:686
Math::real EllipsoidArea() const
Definition: Geodesic.hpp:874
void ArcDirect(real lat1, real lon1, real azi1, real a12, real &lat2, real &lon2, real &azi2) const
Definition: Geodesic.hpp:512
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:488
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:744
Header for GeographicLib::Constants class.
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &azi1, real &azi2) const
Definition: Geodesic.hpp:697
void ArcDirect(real lat1, real lon1, real azi1, real a12, real &lat2, real &lon2, real &azi2, real &s12) const
Definition: Geodesic.hpp:523
#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:401
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:425
Math::real Flattening() const
Definition: Geodesic.hpp:858
Geodesic calculations
Definition: Geodesic.hpp:171