GeographicLib  1.44
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  // Size for temporary array
187  // nC = max(max(nC1_, nC1p_, nC2_) + 1, max(nC3_, nC4_))
188  static const int nC_ = GEOGRAPHICLIB_GEODESIC_ORDER + 1;
189  static const unsigned maxit1_ = 20;
190  unsigned maxit2_;
191  real tiny_, tol0_, tol1_, tol2_, tolb_, xthresh_;
192 
193  enum captype {
194  CAP_NONE = 0U,
195  CAP_C1 = 1U<<0,
196  CAP_C1p = 1U<<1,
197  CAP_C2 = 1U<<2,
198  CAP_C3 = 1U<<3,
199  CAP_C4 = 1U<<4,
200  CAP_ALL = 0x1FU,
201  CAP_MASK = CAP_ALL,
202  OUT_ALL = 0x7F80U,
203  OUT_MASK = 0xFF80U, // Includes LONG_UNROLL
204  };
205 
206  static real SinCosSeries(bool sinp,
207  real sinx, real cosx, const real c[], int n);
208  static real Astroid(real x, real y);
209 
210  real _a, _f, _f1, _e2, _ep2, _n, _b, _c2, _etol2;
211  real _A3x[nA3x_], _C3x[nC3x_], _C4x[nC4x_];
212 
213  void Lengths(real eps, real sig12,
214  real ssig1, real csig1, real dn1,
215  real ssig2, real csig2, real dn2,
216  real cbet1, real cbet2, unsigned outmask,
217  real& s12s, real& m12a, real& m0,
218  real& M12, real& M21, real Ca[]) const;
219  real InverseStart(real sbet1, real cbet1, real dn1,
220  real sbet2, real cbet2, real dn2,
221  real lam12,
222  real& salp1, real& calp1,
223  real& salp2, real& calp2, real& dnm,
224  real Ca[]) const;
225  real Lambda12(real sbet1, real cbet1, real dn1,
226  real sbet2, real cbet2, real dn2,
227  real salp1, real calp1,
228  real& salp2, real& calp2, real& sig12,
229  real& ssig1, real& csig1, real& ssig2, real& csig2,
230  real& eps, real& domg12, bool diffp, real& dlam12,
231  real Ca[])
232  const;
233 
234  // These are Maxima generated functions to provide series approximations to
235  // the integrals for the ellipsoidal geodesic.
236  static real A1m1f(real eps);
237  static void C1f(real eps, real c[]);
238  static void C1pf(real eps, real c[]);
239  static real A2m1f(real eps);
240  static void C2f(real eps, real c[]);
241 
242  void A3coeff();
243  real A3f(real eps) const;
244  void C3coeff();
245  void C3f(real eps, real c[]) const;
246  void C4coeff();
247  void C4f(real k2, real c[]) const;
248 
249  public:
250 
251  /**
252  * Bit masks for what calculations to do. These masks do double duty.
253  * They signify to the GeodesicLine::GeodesicLine constructor and to
254  * Geodesic::Line what capabilities should be included in the GeodesicLine
255  * object. They also specify which results to return in the general
256  * routines Geodesic::GenDirect and Geodesic::GenInverse routines.
257  * GeodesicLine::mask is a duplication of this enum.
258  **********************************************************************/
259  enum mask {
260  /**
261  * No capabilities, no output.
262  * @hideinitializer
263  **********************************************************************/
264  NONE = 0U,
265  /**
266  * Calculate latitude \e lat2. (It's not necessary to include this as a
267  * capability to GeodesicLine because this is included by default.)
268  * @hideinitializer
269  **********************************************************************/
270  LATITUDE = 1U<<7 | CAP_NONE,
271  /**
272  * Calculate longitude \e lon2.
273  * @hideinitializer
274  **********************************************************************/
275  LONGITUDE = 1U<<8 | CAP_C3,
276  /**
277  * Calculate azimuths \e azi1 and \e azi2. (It's not necessary to
278  * include this as a capability to GeodesicLine because this is included
279  * by default.)
280  * @hideinitializer
281  **********************************************************************/
282  AZIMUTH = 1U<<9 | CAP_NONE,
283  /**
284  * Calculate distance \e s12.
285  * @hideinitializer
286  **********************************************************************/
287  DISTANCE = 1U<<10 | CAP_C1,
288  /**
289  * Allow distance \e s12 to be used as input in the direct geodesic
290  * problem.
291  * @hideinitializer
292  **********************************************************************/
293  DISTANCE_IN = 1U<<11 | CAP_C1 | CAP_C1p,
294  /**
295  * Calculate reduced length \e m12.
296  * @hideinitializer
297  **********************************************************************/
298  REDUCEDLENGTH = 1U<<12 | CAP_C1 | CAP_C2,
299  /**
300  * Calculate geodesic scales \e M12 and \e M21.
301  * @hideinitializer
302  **********************************************************************/
303  GEODESICSCALE = 1U<<13 | CAP_C1 | CAP_C2,
304  /**
305  * Calculate area \e S12.
306  * @hideinitializer
307  **********************************************************************/
308  AREA = 1U<<14 | CAP_C4,
309  /**
310  * Unroll \e lon2 in the direct calculation. (This flag used to be
311  * called LONG_NOWRAP.)
312  * @hideinitializer
313  **********************************************************************/
314  LONG_UNROLL = 1U<<15,
315  /// \cond SKIP
316  LONG_NOWRAP = LONG_UNROLL,
317  /// \endcond
318  /**
319  * All capabilities, calculate everything. (LONG_UNROLL is not
320  * included in this mask.)
321  * @hideinitializer
322  **********************************************************************/
323  ALL = OUT_ALL| CAP_ALL,
324  };
325 
326  /** \name Constructor
327  **********************************************************************/
328  ///@{
329  /**
330  * Constructor for a ellipsoid with
331  *
332  * @param[in] a equatorial radius (meters).
333  * @param[in] f flattening of ellipsoid. Setting \e f = 0 gives a sphere.
334  * Negative \e f gives a prolate ellipsoid. If \e f &gt; 1, set
335  * flattening to 1/\e f.
336  * @exception GeographicErr if \e a or (1 &minus; \e f) \e a is not
337  * positive.
338  **********************************************************************/
339  Geodesic(real a, real f);
340  ///@}
341 
342  /** \name Direct geodesic problem specified in terms of distance.
343  **********************************************************************/
344  ///@{
345  /**
346  * Solve the direct geodesic problem where the length of the geodesic
347  * is specified in terms of distance.
348  *
349  * @param[in] lat1 latitude of point 1 (degrees).
350  * @param[in] lon1 longitude of point 1 (degrees).
351  * @param[in] azi1 azimuth at point 1 (degrees).
352  * @param[in] s12 distance between point 1 and point 2 (meters); it can be
353  * negative.
354  * @param[out] lat2 latitude of point 2 (degrees).
355  * @param[out] lon2 longitude of point 2 (degrees).
356  * @param[out] azi2 (forward) azimuth at point 2 (degrees).
357  * @param[out] m12 reduced length of geodesic (meters).
358  * @param[out] M12 geodesic scale of point 2 relative to point 1
359  * (dimensionless).
360  * @param[out] M21 geodesic scale of point 1 relative to point 2
361  * (dimensionless).
362  * @param[out] S12 area under the geodesic (meters<sup>2</sup>).
363  * @return \e a12 arc length of between point 1 and point 2 (degrees).
364  *
365  * \e lat1 should be in the range [&minus;90&deg;, 90&deg;]. The values of
366  * \e lon2 and \e azi2 returned are in the range [&minus;180&deg;,
367  * 180&deg;).
368  *
369  * If either point is at a pole, the azimuth is defined by keeping the
370  * longitude fixed, writing \e lat = &plusmn;(90&deg; &minus; &epsilon;),
371  * and taking the limit &epsilon; &rarr; 0+. An arc length greater that
372  * 180&deg; signifies a geodesic which is not a shortest path. (For a
373  * prolate ellipsoid, an additional condition is necessary for a shortest
374  * path: the longitudinal extent must not exceed of 180&deg;.)
375  *
376  * The following functions are overloaded versions of Geodesic::Direct
377  * which omit some of the output parameters. Note, however, that the arc
378  * length is always computed and returned as the function value.
379  **********************************************************************/
380  Math::real Direct(real lat1, real lon1, real azi1, real s12,
381  real& lat2, real& lon2, real& azi2,
382  real& m12, real& M12, real& M21, real& S12)
383  const {
384  real t;
385  return GenDirect(lat1, lon1, azi1, false, s12,
386  LATITUDE | LONGITUDE | AZIMUTH |
387  REDUCEDLENGTH | GEODESICSCALE | AREA,
388  lat2, lon2, azi2, t, m12, M12, M21, S12);
389  }
390 
391  /**
392  * See the documentation for Geodesic::Direct.
393  **********************************************************************/
394  Math::real Direct(real lat1, real lon1, real azi1, real s12,
395  real& lat2, real& lon2)
396  const {
397  real t;
398  return GenDirect(lat1, lon1, azi1, false, s12,
399  LATITUDE | LONGITUDE,
400  lat2, lon2, t, t, t, t, t, t);
401  }
402 
403  /**
404  * See the documentation for Geodesic::Direct.
405  **********************************************************************/
406  Math::real Direct(real lat1, real lon1, real azi1, real s12,
407  real& lat2, real& lon2, real& azi2)
408  const {
409  real t;
410  return GenDirect(lat1, lon1, azi1, false, s12,
411  LATITUDE | LONGITUDE | AZIMUTH,
412  lat2, lon2, azi2, t, t, t, t, t);
413  }
414 
415  /**
416  * See the documentation for Geodesic::Direct.
417  **********************************************************************/
418  Math::real Direct(real lat1, real lon1, real azi1, real s12,
419  real& lat2, real& lon2, real& azi2, real& m12)
420  const {
421  real t;
422  return GenDirect(lat1, lon1, azi1, false, s12,
423  LATITUDE | LONGITUDE | AZIMUTH | REDUCEDLENGTH,
424  lat2, lon2, azi2, t, m12, t, t, t);
425  }
426 
427  /**
428  * See the documentation for Geodesic::Direct.
429  **********************************************************************/
430  Math::real Direct(real lat1, real lon1, real azi1, real s12,
431  real& lat2, real& lon2, real& azi2,
432  real& M12, real& M21)
433  const {
434  real t;
435  return GenDirect(lat1, lon1, azi1, false, s12,
436  LATITUDE | LONGITUDE | AZIMUTH | GEODESICSCALE,
437  lat2, lon2, azi2, t, t, M12, M21, t);
438  }
439 
440  /**
441  * See the documentation for Geodesic::Direct.
442  **********************************************************************/
443  Math::real Direct(real lat1, real lon1, real azi1, real s12,
444  real& lat2, real& lon2, real& azi2,
445  real& m12, real& M12, real& M21)
446  const {
447  real t;
448  return GenDirect(lat1, lon1, azi1, false, s12,
449  LATITUDE | LONGITUDE | AZIMUTH |
450  REDUCEDLENGTH | GEODESICSCALE,
451  lat2, lon2, azi2, t, m12, M12, M21, t);
452  }
453  ///@}
454 
455  /** \name Direct geodesic problem specified in terms of arc length.
456  **********************************************************************/
457  ///@{
458  /**
459  * Solve the direct geodesic problem where the length of the geodesic
460  * is specified in terms of arc length.
461  *
462  * @param[in] lat1 latitude of point 1 (degrees).
463  * @param[in] lon1 longitude of point 1 (degrees).
464  * @param[in] azi1 azimuth at point 1 (degrees).
465  * @param[in] a12 arc length between point 1 and point 2 (degrees); it can
466  * be negative.
467  * @param[out] lat2 latitude of point 2 (degrees).
468  * @param[out] lon2 longitude of point 2 (degrees).
469  * @param[out] azi2 (forward) azimuth at point 2 (degrees).
470  * @param[out] s12 distance between point 1 and point 2 (meters).
471  * @param[out] m12 reduced length of geodesic (meters).
472  * @param[out] M12 geodesic scale of point 2 relative to point 1
473  * (dimensionless).
474  * @param[out] M21 geodesic scale of point 1 relative to point 2
475  * (dimensionless).
476  * @param[out] S12 area under the geodesic (meters<sup>2</sup>).
477  *
478  * \e lat1 should be in the range [&minus;90&deg;, 90&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.
629  **********************************************************************/
630  Math::real GenDirect(real lat1, real lon1, real azi1,
631  bool arcmode, real s12_a12, unsigned outmask,
632  real& lat2, real& lon2, real& azi2,
633  real& s12, real& m12, real& M12, real& M21,
634  real& S12) const;
635  ///@}
636 
637  /** \name Inverse geodesic problem.
638  **********************************************************************/
639  ///@{
640  /**
641  * Solve the inverse geodesic problem.
642  *
643  * @param[in] lat1 latitude of point 1 (degrees).
644  * @param[in] lon1 longitude of point 1 (degrees).
645  * @param[in] lat2 latitude of point 2 (degrees).
646  * @param[in] lon2 longitude of point 2 (degrees).
647  * @param[out] s12 distance between point 1 and point 2 (meters).
648  * @param[out] azi1 azimuth at point 1 (degrees).
649  * @param[out] azi2 (forward) azimuth at point 2 (degrees).
650  * @param[out] m12 reduced length of geodesic (meters).
651  * @param[out] M12 geodesic scale of point 2 relative to point 1
652  * (dimensionless).
653  * @param[out] M21 geodesic scale of point 1 relative to point 2
654  * (dimensionless).
655  * @param[out] S12 area under the geodesic (meters<sup>2</sup>).
656  * @return \e a12 arc length of between point 1 and point 2 (degrees).
657  *
658  * \e lat1 and \e lat2 should be in the range [&minus;90&deg;, 90&deg;].
659  * The values of \e azi1 and \e azi2 returned are in the range
660  * [&minus;180&deg;, 180&deg;).
661  *
662  * If either point is at a pole, the azimuth is defined by keeping the
663  * longitude fixed, writing \e lat = &plusmn;(90&deg; &minus; &epsilon;),
664  * and taking the limit &epsilon; &rarr; 0+.
665  *
666  * The solution to the inverse problem is found using Newton's method. If
667  * this fails to converge (this is very unlikely in geodetic applications
668  * but does occur for very eccentric ellipsoids), then the bisection method
669  * is used to refine the solution.
670  *
671  * The following functions are overloaded versions of Geodesic::Inverse
672  * which omit some of the output parameters. Note, however, that the arc
673  * length is always computed and returned as the function value.
674  **********************************************************************/
675  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
676  real& s12, real& azi1, real& azi2, real& m12,
677  real& M12, real& M21, real& S12) const {
678  return GenInverse(lat1, lon1, lat2, lon2,
679  DISTANCE | AZIMUTH |
680  REDUCEDLENGTH | GEODESICSCALE | AREA,
681  s12, azi1, azi2, m12, M12, M21, S12);
682  }
683 
684  /**
685  * See the documentation for Geodesic::Inverse.
686  **********************************************************************/
687  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
688  real& s12) const {
689  real t;
690  return GenInverse(lat1, lon1, lat2, lon2,
691  DISTANCE,
692  s12, t, t, t, t, t, t);
693  }
694 
695  /**
696  * See the documentation for Geodesic::Inverse.
697  **********************************************************************/
698  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
699  real& azi1, real& azi2) const {
700  real t;
701  return GenInverse(lat1, lon1, lat2, lon2,
702  AZIMUTH,
703  t, azi1, azi2, t, t, t, t);
704  }
705 
706  /**
707  * See the documentation for Geodesic::Inverse.
708  **********************************************************************/
709  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
710  real& s12, real& azi1, real& azi2)
711  const {
712  real t;
713  return GenInverse(lat1, lon1, lat2, lon2,
714  DISTANCE | AZIMUTH,
715  s12, azi1, azi2, t, t, t, t);
716  }
717 
718  /**
719  * See the documentation for Geodesic::Inverse.
720  **********************************************************************/
721  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
722  real& s12, real& azi1, real& azi2, real& m12)
723  const {
724  real t;
725  return GenInverse(lat1, lon1, lat2, lon2,
726  DISTANCE | AZIMUTH | REDUCEDLENGTH,
727  s12, azi1, azi2, m12, t, t, t);
728  }
729 
730  /**
731  * See the documentation for Geodesic::Inverse.
732  **********************************************************************/
733  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
734  real& s12, real& azi1, real& azi2,
735  real& M12, real& M21) const {
736  real t;
737  return GenInverse(lat1, lon1, lat2, lon2,
738  DISTANCE | AZIMUTH | GEODESICSCALE,
739  s12, azi1, azi2, t, M12, M21, t);
740  }
741 
742  /**
743  * See the documentation for Geodesic::Inverse.
744  **********************************************************************/
745  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
746  real& s12, real& azi1, real& azi2, real& m12,
747  real& M12, real& M21) const {
748  real t;
749  return GenInverse(lat1, lon1, lat2, lon2,
750  DISTANCE | AZIMUTH |
751  REDUCEDLENGTH | GEODESICSCALE,
752  s12, azi1, azi2, m12, M12, M21, t);
753  }
754  ///@}
755 
756  /** \name General version of inverse geodesic solution.
757  **********************************************************************/
758  ///@{
759  /**
760  * The general inverse geodesic calculation. Geodesic::Inverse is defined
761  * in terms of this function.
762  *
763  * @param[in] lat1 latitude of point 1 (degrees).
764  * @param[in] lon1 longitude of point 1 (degrees).
765  * @param[in] lat2 latitude of point 2 (degrees).
766  * @param[in] lon2 longitude of point 2 (degrees).
767  * @param[in] outmask a bitor'ed combination of Geodesic::mask values
768  * specifying which of the following parameters should be set.
769  * @param[out] s12 distance between point 1 and point 2 (meters).
770  * @param[out] azi1 azimuth at point 1 (degrees).
771  * @param[out] azi2 (forward) azimuth at point 2 (degrees).
772  * @param[out] m12 reduced length of geodesic (meters).
773  * @param[out] M12 geodesic scale of point 2 relative to point 1
774  * (dimensionless).
775  * @param[out] M21 geodesic scale of point 1 relative to point 2
776  * (dimensionless).
777  * @param[out] S12 area under the geodesic (meters<sup>2</sup>).
778  * @return \e a12 arc length of between point 1 and point 2 (degrees).
779  *
780  * The Geodesic::mask values possible for \e outmask are
781  * - \e outmask |= Geodesic::DISTANCE for the distance \e s12;
782  * - \e outmask |= Geodesic::AZIMUTH for the latitude \e azi2;
783  * - \e outmask |= Geodesic::REDUCEDLENGTH for the reduced length \e
784  * m12;
785  * - \e outmask |= Geodesic::GEODESICSCALE for the geodesic scales \e
786  * M12 and \e M21;
787  * - \e outmask |= Geodesic::AREA for the area \e S12;
788  * - \e outmask |= Geodesic::ALL for all of the above.
789  * .
790  * The arc length is always computed and returned as the function value.
791  **********************************************************************/
792  Math::real GenInverse(real lat1, real lon1, real lat2, real lon2,
793  unsigned outmask,
794  real& s12, real& azi1, real& azi2,
795  real& m12, real& M12, real& M21, real& S12)
796  const;
797  ///@}
798 
799  /** \name Interface to GeodesicLine.
800  **********************************************************************/
801  ///@{
802 
803  /**
804  * Set up to compute several points on a single geodesic.
805  *
806  * @param[in] lat1 latitude of point 1 (degrees).
807  * @param[in] lon1 longitude of point 1 (degrees).
808  * @param[in] azi1 azimuth at point 1 (degrees).
809  * @param[in] caps bitor'ed combination of Geodesic::mask values
810  * specifying the capabilities the GeodesicLine object should possess,
811  * i.e., which quantities can be returned in calls to
812  * GeodesicLine::Position.
813  * @return a GeodesicLine object.
814  *
815  * \e lat1 should be in the range [&minus;90&deg;, 90&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:552
static T pi()
Definition: Math.hpp:216
#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:380
Math::real Direct(real lat1, real lon1, real azi1, real s12, real &lat2, real &lon2, real &azi2, real &m12) const
Definition: Geodesic.hpp:418
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:675
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: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:394
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:733
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &s12, real &azi1, real &azi2, real &m12) const
Definition: Geodesic.hpp:721
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:443
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &s12, real &azi1, real &azi2) const
Definition: Geodesic.hpp:709
Namespace for GeographicLib.
Definition: Accumulator.cpp:12
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &s12) const
Definition: Geodesic.hpp:687
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: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:745
Header for GeographicLib::Constants class.
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &azi1, real &azi2) const
Definition: Geodesic.hpp:698
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:406
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:430
Math::real Flattening() const
Definition: Geodesic.hpp:858
Geodesic calculations
Definition: Geodesic.hpp:171