GeographicLib  1.49
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-2016) <charles@karney.com> and licensed
6  * under the MIT/X11 License. For more information, see
7  * https://geographiclib.sourceforge.io/
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="https://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] &rarr; [\e
116  * azi2, \e azi1], [\e M12, \e M21] &rarr; [\e M21, \e M12], \e S12 &rarr;
117  * &minus;\e S12. (This occurs when the longitude difference is near
118  * &plusmn;180&deg; for 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] &rarr; [&minus;\e azi1, &minus;\e azi2], \e S12 &rarr;
123  * &minus;\e S12. (This occurs when \e lat2 is near &minus;\e lat1 for
124  * prolate 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] &rarr; [\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  * - \e s12 = 0 (coincident points). There are infinitely many geodesics
130  * which can be generated by setting [\e azi1, \e azi2] &rarr;
131  * [\e azi1, \e azi2] + [\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="https://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  * equatorial 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://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://doi.org/10.1007/s00190-012-0578-z">
158  * 10.1007/s00190-012-0578-z</a>;
159  * addenda:
160  * <a href="https://geographiclib.sourceforge.io/geod-addenda.html">
161  * geod-addenda.html</a>.
162  * .
163  * For more information on geodesics see \ref geodesic.
164  *
165  * Example of use:
166  * \include example-Geodesic.cpp
167  *
168  * <a href="GeodSolve.1.html">GeodSolve</a> is a command-line utility
169  * providing access to the functionality of Geodesic and GeodesicLine.
170  **********************************************************************/
171 
173  private:
174  typedef Math::real real;
175  friend class GeodesicLine;
176  static const int nA1_ = GEOGRAPHICLIB_GEODESIC_ORDER;
177  static const int nC1_ = GEOGRAPHICLIB_GEODESIC_ORDER;
178  static const int nC1p_ = GEOGRAPHICLIB_GEODESIC_ORDER;
179  static const int nA2_ = GEOGRAPHICLIB_GEODESIC_ORDER;
180  static const int nC2_ = GEOGRAPHICLIB_GEODESIC_ORDER;
181  static const int nA3_ = GEOGRAPHICLIB_GEODESIC_ORDER;
182  static const int nA3x_ = nA3_;
183  static const int nC3_ = GEOGRAPHICLIB_GEODESIC_ORDER;
184  static const int nC3x_ = (nC3_ * (nC3_ - 1)) / 2;
185  static const int nC4_ = GEOGRAPHICLIB_GEODESIC_ORDER;
186  static const int nC4x_ = (nC4_ * (nC4_ + 1)) / 2;
187  // Size for temporary array
188  // nC = max(max(nC1_, nC1p_, nC2_) + 1, max(nC3_, nC4_))
189  static const int nC_ = GEOGRAPHICLIB_GEODESIC_ORDER + 1;
190  static const unsigned maxit1_ = 20;
191  unsigned maxit2_;
192  real tiny_, tol0_, tol1_, tol2_, tolb_, xthresh_;
193 
194  enum captype {
195  CAP_NONE = 0U,
196  CAP_C1 = 1U<<0,
197  CAP_C1p = 1U<<1,
198  CAP_C2 = 1U<<2,
199  CAP_C3 = 1U<<3,
200  CAP_C4 = 1U<<4,
201  CAP_ALL = 0x1FU,
202  CAP_MASK = CAP_ALL,
203  OUT_ALL = 0x7F80U,
204  OUT_MASK = 0xFF80U, // Includes LONG_UNROLL
205  };
206 
207  static real SinCosSeries(bool sinp,
208  real sinx, real cosx, const real c[], int n);
209  static real Astroid(real x, real y);
210 
211  real _a, _f, _f1, _e2, _ep2, _n, _b, _c2, _etol2;
212  real _A3x[nA3x_], _C3x[nC3x_], _C4x[nC4x_];
213 
214  void Lengths(real eps, real sig12,
215  real ssig1, real csig1, real dn1,
216  real ssig2, real csig2, real dn2,
217  real cbet1, real cbet2, unsigned outmask,
218  real& s12s, real& m12a, real& m0,
219  real& M12, real& M21, real Ca[]) const;
220  real InverseStart(real sbet1, real cbet1, real dn1,
221  real sbet2, real cbet2, real dn2,
222  real lam12, real slam12, real clam12,
223  real& salp1, real& calp1,
224  real& salp2, real& calp2, real& dnm,
225  real Ca[]) const;
226  real Lambda12(real sbet1, real cbet1, real dn1,
227  real sbet2, real cbet2, real dn2,
228  real salp1, real calp1, real slam120, real clam120,
229  real& salp2, real& calp2, real& sig12,
230  real& ssig1, real& csig1, real& ssig2, real& csig2,
231  real& eps, real& domg12,
232  bool diffp, real& dlam12, real Ca[]) const;
233  real GenInverse(real lat1, real lon1, real lat2, real lon2,
234  unsigned outmask, real& s12,
235  real& salp1, real& calp1, real& salp2, real& calp2,
236  real& m12, real& M12, real& M21, real& S12) const;
237 
238  // These are Maxima generated functions to provide series approximations to
239  // the integrals for the ellipsoidal geodesic.
240  static real A1m1f(real eps);
241  static void C1f(real eps, real c[]);
242  static void C1pf(real eps, real c[]);
243  static real A2m1f(real eps);
244  static void C2f(real eps, real c[]);
245 
246  void A3coeff();
247  real A3f(real eps) const;
248  void C3coeff();
249  void C3f(real eps, real c[]) const;
250  void C4coeff();
251  void C4f(real k2, real c[]) const;
252 
253  public:
254 
255  /**
256  * Bit masks for what calculations to do. These masks do double duty.
257  * They signify to the GeodesicLine::GeodesicLine constructor and to
258  * Geodesic::Line what capabilities should be included in the GeodesicLine
259  * object. They also specify which results to return in the general
260  * routines Geodesic::GenDirect and Geodesic::GenInverse routines.
261  * GeodesicLine::mask is a duplication of this enum.
262  **********************************************************************/
263  enum mask {
264  /**
265  * No capabilities, no output.
266  * @hideinitializer
267  **********************************************************************/
268  NONE = 0U,
269  /**
270  * Calculate latitude \e lat2. (It's not necessary to include this as a
271  * capability to GeodesicLine because this is included by default.)
272  * @hideinitializer
273  **********************************************************************/
274  LATITUDE = 1U<<7 | CAP_NONE,
275  /**
276  * Calculate longitude \e lon2.
277  * @hideinitializer
278  **********************************************************************/
279  LONGITUDE = 1U<<8 | CAP_C3,
280  /**
281  * Calculate azimuths \e azi1 and \e azi2. (It's not necessary to
282  * include this as a capability to GeodesicLine because this is included
283  * by default.)
284  * @hideinitializer
285  **********************************************************************/
286  AZIMUTH = 1U<<9 | CAP_NONE,
287  /**
288  * Calculate distance \e s12.
289  * @hideinitializer
290  **********************************************************************/
291  DISTANCE = 1U<<10 | CAP_C1,
292  /**
293  * Allow distance \e s12 to be used as input in the direct geodesic
294  * problem.
295  * @hideinitializer
296  **********************************************************************/
297  DISTANCE_IN = 1U<<11 | CAP_C1 | CAP_C1p,
298  /**
299  * Calculate reduced length \e m12.
300  * @hideinitializer
301  **********************************************************************/
302  REDUCEDLENGTH = 1U<<12 | CAP_C1 | CAP_C2,
303  /**
304  * Calculate geodesic scales \e M12 and \e M21.
305  * @hideinitializer
306  **********************************************************************/
307  GEODESICSCALE = 1U<<13 | CAP_C1 | CAP_C2,
308  /**
309  * Calculate area \e S12.
310  * @hideinitializer
311  **********************************************************************/
312  AREA = 1U<<14 | CAP_C4,
313  /**
314  * Unroll \e lon2 in the direct calculation.
315  * @hideinitializer
316  **********************************************************************/
317  LONG_UNROLL = 1U<<15,
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.
335  * @exception GeographicErr if \e a or (1 &minus; \e f) \e a is not
336  * positive.
337  **********************************************************************/
338  Geodesic(real a, real f);
339  ///@}
340 
341  /** \name Direct geodesic problem specified in terms of distance.
342  **********************************************************************/
343  ///@{
344  /**
345  * Solve the direct geodesic problem where the length of the geodesic
346  * is specified in terms of distance.
347  *
348  * @param[in] lat1 latitude of point 1 (degrees).
349  * @param[in] lon1 longitude of point 1 (degrees).
350  * @param[in] azi1 azimuth at point 1 (degrees).
351  * @param[in] s12 distance between point 1 and point 2 (meters); it can be
352  * negative.
353  * @param[out] lat2 latitude of point 2 (degrees).
354  * @param[out] lon2 longitude of point 2 (degrees).
355  * @param[out] azi2 (forward) azimuth at point 2 (degrees).
356  * @param[out] m12 reduced length of geodesic (meters).
357  * @param[out] M12 geodesic scale of point 2 relative to point 1
358  * (dimensionless).
359  * @param[out] M21 geodesic scale of point 1 relative to point 2
360  * (dimensionless).
361  * @param[out] S12 area under the geodesic (meters<sup>2</sup>).
362  * @return \e a12 arc length of between point 1 and point 2 (degrees).
363  *
364  * \e lat1 should be in the range [&minus;90&deg;, 90&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;]. The values of
478  * \e lon2 and \e azi2 returned are in the range [&minus;180&deg;,
479  * 180&deg;].
480  *
481  * If either point is at a pole, the azimuth is defined by keeping the
482  * longitude fixed, writing \e lat = &plusmn;(90&deg; &minus; &epsilon;),
483  * and taking the limit &epsilon; &rarr; 0+. An arc length greater that
484  * 180&deg; signifies a geodesic which is not a shortest path. (For a
485  * prolate ellipsoid, an additional condition is necessary for a shortest
486  * path: the longitudinal extent must not exceed of 180&deg;.)
487  *
488  * The following functions are overloaded versions of Geodesic::Direct
489  * which omit some of the output parameters.
490  **********************************************************************/
491  void ArcDirect(real lat1, real lon1, real azi1, real a12,
492  real& lat2, real& lon2, real& azi2, real& s12,
493  real& m12, real& M12, real& M21, real& S12)
494  const {
495  GenDirect(lat1, lon1, azi1, true, a12,
496  LATITUDE | LONGITUDE | AZIMUTH | DISTANCE |
497  REDUCEDLENGTH | GEODESICSCALE | AREA,
498  lat2, lon2, azi2, s12, m12, M12, M21, S12);
499  }
500 
501  /**
502  * See the documentation for Geodesic::ArcDirect.
503  **********************************************************************/
504  void ArcDirect(real lat1, real lon1, real azi1, real a12,
505  real& lat2, real& lon2) const {
506  real t;
507  GenDirect(lat1, lon1, azi1, true, a12,
508  LATITUDE | LONGITUDE,
509  lat2, lon2, t, t, t, t, t, t);
510  }
511 
512  /**
513  * See the documentation for Geodesic::ArcDirect.
514  **********************************************************************/
515  void ArcDirect(real lat1, real lon1, real azi1, real a12,
516  real& lat2, real& lon2, real& azi2) const {
517  real t;
518  GenDirect(lat1, lon1, azi1, true, a12,
519  LATITUDE | LONGITUDE | AZIMUTH,
520  lat2, lon2, azi2, t, t, t, t, t);
521  }
522 
523  /**
524  * See the documentation for Geodesic::ArcDirect.
525  **********************************************************************/
526  void ArcDirect(real lat1, real lon1, real azi1, real a12,
527  real& lat2, real& lon2, real& azi2, real& s12)
528  const {
529  real t;
530  GenDirect(lat1, lon1, azi1, true, a12,
531  LATITUDE | LONGITUDE | AZIMUTH | DISTANCE,
532  lat2, lon2, azi2, s12, t, t, t, t);
533  }
534 
535  /**
536  * See the documentation for Geodesic::ArcDirect.
537  **********************************************************************/
538  void ArcDirect(real lat1, real lon1, real azi1, real a12,
539  real& lat2, real& lon2, real& azi2,
540  real& s12, real& m12) const {
541  real t;
542  GenDirect(lat1, lon1, azi1, true, a12,
543  LATITUDE | LONGITUDE | AZIMUTH | DISTANCE |
544  REDUCEDLENGTH,
545  lat2, lon2, azi2, s12, m12, t, t, t);
546  }
547 
548  /**
549  * See the documentation for Geodesic::ArcDirect.
550  **********************************************************************/
551  void ArcDirect(real lat1, real lon1, real azi1, real a12,
552  real& lat2, real& lon2, real& azi2, real& s12,
553  real& M12, real& M21) const {
554  real t;
555  GenDirect(lat1, lon1, azi1, true, a12,
556  LATITUDE | LONGITUDE | AZIMUTH | DISTANCE |
557  GEODESICSCALE,
558  lat2, lon2, azi2, s12, t, M12, M21, t);
559  }
560 
561  /**
562  * See the documentation for Geodesic::ArcDirect.
563  **********************************************************************/
564  void ArcDirect(real lat1, real lon1, real azi1, real a12,
565  real& lat2, real& lon2, real& azi2, real& s12,
566  real& m12, real& M12, real& M21) const {
567  real t;
568  GenDirect(lat1, lon1, azi1, true, a12,
569  LATITUDE | LONGITUDE | AZIMUTH | DISTANCE |
570  REDUCEDLENGTH | GEODESICSCALE,
571  lat2, lon2, azi2, s12, m12, M12, M21, t);
572  }
573  ///@}
574 
575  /** \name General version of the direct geodesic solution.
576  **********************************************************************/
577  ///@{
578 
579  /**
580  * The general direct geodesic problem. Geodesic::Direct and
581  * Geodesic::ArcDirect are defined in terms of this function.
582  *
583  * @param[in] lat1 latitude of point 1 (degrees).
584  * @param[in] lon1 longitude of point 1 (degrees).
585  * @param[in] azi1 azimuth at point 1 (degrees).
586  * @param[in] arcmode boolean flag determining the meaning of the \e
587  * s12_a12.
588  * @param[in] s12_a12 if \e arcmode is false, this is the distance between
589  * point 1 and point 2 (meters); otherwise it is the arc length between
590  * point 1 and point 2 (degrees); it can be negative.
591  * @param[in] outmask a bitor'ed combination of Geodesic::mask values
592  * specifying which of the following parameters should be set.
593  * @param[out] lat2 latitude of point 2 (degrees).
594  * @param[out] lon2 longitude of point 2 (degrees).
595  * @param[out] azi2 (forward) azimuth at point 2 (degrees).
596  * @param[out] s12 distance between point 1 and point 2 (meters).
597  * @param[out] m12 reduced length of geodesic (meters).
598  * @param[out] M12 geodesic scale of point 2 relative to point 1
599  * (dimensionless).
600  * @param[out] M21 geodesic scale of point 1 relative to point 2
601  * (dimensionless).
602  * @param[out] S12 area under the geodesic (meters<sup>2</sup>).
603  * @return \e a12 arc length of between point 1 and point 2 (degrees).
604  *
605  * The Geodesic::mask values possible for \e outmask are
606  * - \e outmask |= Geodesic::LATITUDE for the latitude \e lat2;
607  * - \e outmask |= Geodesic::LONGITUDE for the latitude \e lon2;
608  * - \e outmask |= Geodesic::AZIMUTH for the latitude \e azi2;
609  * - \e outmask |= Geodesic::DISTANCE for the distance \e s12;
610  * - \e outmask |= Geodesic::REDUCEDLENGTH for the reduced length \e
611  * m12;
612  * - \e outmask |= Geodesic::GEODESICSCALE for the geodesic scales \e
613  * M12 and \e M21;
614  * - \e outmask |= Geodesic::AREA for the area \e S12;
615  * - \e outmask |= Geodesic::ALL for all of the above;
616  * - \e outmask |= Geodesic::LONG_UNROLL to unroll \e lon2 instead of
617  * wrapping it into the range [&minus;180&deg;, 180&deg;].
618  * .
619  * The function value \e a12 is always computed and returned and this
620  * equals \e s12_a12 is \e arcmode is true. If \e outmask includes
621  * Geodesic::DISTANCE and \e arcmode is false, then \e s12 = \e s12_a12.
622  * It is not necessary to include Geodesic::DISTANCE_IN in \e outmask; this
623  * is automatically included is \e arcmode is false.
624  *
625  * With the Geodesic::LONG_UNROLL bit set, the quantity \e lon2 &minus; \e
626  * lon1 indicates how many times and in what sense the geodesic encircles
627  * the ellipsoid.
628  **********************************************************************/
629  Math::real GenDirect(real lat1, real lon1, real azi1,
630  bool arcmode, real s12_a12, unsigned outmask,
631  real& lat2, real& lon2, real& azi2,
632  real& s12, real& m12, real& M12, real& M21,
633  real& S12) const;
634  ///@}
635 
636  /** \name Inverse geodesic problem.
637  **********************************************************************/
638  ///@{
639  /**
640  * Solve the inverse geodesic problem.
641  *
642  * @param[in] lat1 latitude of point 1 (degrees).
643  * @param[in] lon1 longitude of point 1 (degrees).
644  * @param[in] lat2 latitude of point 2 (degrees).
645  * @param[in] lon2 longitude of point 2 (degrees).
646  * @param[out] s12 distance between point 1 and point 2 (meters).
647  * @param[out] azi1 azimuth at point 1 (degrees).
648  * @param[out] azi2 (forward) azimuth at point 2 (degrees).
649  * @param[out] m12 reduced length of geodesic (meters).
650  * @param[out] M12 geodesic scale of point 2 relative to point 1
651  * (dimensionless).
652  * @param[out] M21 geodesic scale of point 1 relative to point 2
653  * (dimensionless).
654  * @param[out] S12 area under the geodesic (meters<sup>2</sup>).
655  * @return \e a12 arc length of between point 1 and point 2 (degrees).
656  *
657  * \e lat1 and \e lat2 should be in the range [&minus;90&deg;, 90&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) const;
795  ///@}
796 
797  /** \name Interface to GeodesicLine.
798  **********************************************************************/
799  ///@{
800 
801  /**
802  * Set up to compute several points on a single geodesic.
803  *
804  * @param[in] lat1 latitude of point 1 (degrees).
805  * @param[in] lon1 longitude of point 1 (degrees).
806  * @param[in] azi1 azimuth at point 1 (degrees).
807  * @param[in] caps bitor'ed combination of Geodesic::mask values
808  * specifying the capabilities the GeodesicLine object should possess,
809  * i.e., which quantities can be returned in calls to
810  * GeodesicLine::Position.
811  * @return a GeodesicLine object.
812  *
813  * \e lat1 should be in the range [&minus;90&deg;, 90&deg;].
814  *
815  * The Geodesic::mask values are
816  * - \e caps |= Geodesic::LATITUDE for the latitude \e lat2; this is
817  * added automatically;
818  * - \e caps |= Geodesic::LONGITUDE for the latitude \e lon2;
819  * - \e caps |= Geodesic::AZIMUTH for the azimuth \e azi2; this is
820  * added automatically;
821  * - \e caps |= Geodesic::DISTANCE for the distance \e s12;
822  * - \e caps |= Geodesic::REDUCEDLENGTH for the reduced length \e m12;
823  * - \e caps |= Geodesic::GEODESICSCALE for the geodesic scales \e M12
824  * and \e M21;
825  * - \e caps |= Geodesic::AREA for the area \e S12;
826  * - \e caps |= Geodesic::DISTANCE_IN permits the length of the
827  * geodesic to be given in terms of \e s12; without this capability the
828  * length can only be specified in terms of arc length;
829  * - \e caps |= Geodesic::ALL for all of the above.
830  * .
831  * The default value of \e caps is Geodesic::ALL.
832  *
833  * If the point is at a pole, the azimuth is defined by keeping \e lon1
834  * fixed, writing \e lat1 = &plusmn;(90 &minus; &epsilon;), and taking the
835  * limit &epsilon; &rarr; 0+.
836  **********************************************************************/
837  GeodesicLine Line(real lat1, real lon1, real azi1, unsigned caps = ALL)
838  const;
839 
840  /**
841  * Define a GeodesicLine in terms of the inverse geodesic problem.
842  *
843  * @param[in] lat1 latitude of point 1 (degrees).
844  * @param[in] lon1 longitude of point 1 (degrees).
845  * @param[in] lat2 latitude of point 2 (degrees).
846  * @param[in] lon2 longitude of point 2 (degrees).
847  * @param[in] caps bitor'ed combination of Geodesic::mask values
848  * specifying the capabilities the GeodesicLine object should possess,
849  * i.e., which quantities can be returned in calls to
850  * GeodesicLine::Position.
851  * @return a GeodesicLine object.
852  *
853  * This function sets point 3 of the GeodesicLine to correspond to point 2
854  * of the inverse geodesic problem.
855  *
856  * \e lat1 and \e lat2 should be in the range [&minus;90&deg;, 90&deg;].
857  **********************************************************************/
858  GeodesicLine InverseLine(real lat1, real lon1, real lat2, real lon2,
859  unsigned caps = ALL) const;
860 
861  /**
862  * Define a GeodesicLine in terms of the direct geodesic problem specified
863  * in terms of distance.
864  *
865  * @param[in] lat1 latitude of point 1 (degrees).
866  * @param[in] lon1 longitude of point 1 (degrees).
867  * @param[in] azi1 azimuth at point 1 (degrees).
868  * @param[in] s12 distance between point 1 and point 2 (meters); it can be
869  * negative.
870  * @param[in] caps bitor'ed combination of Geodesic::mask values
871  * specifying the capabilities the GeodesicLine object should possess,
872  * i.e., which quantities can be returned in calls to
873  * GeodesicLine::Position.
874  * @return a GeodesicLine object.
875  *
876  * This function sets point 3 of the GeodesicLine to correspond to point 2
877  * of the direct geodesic problem.
878  *
879  * \e lat1 should be in the range [&minus;90&deg;, 90&deg;].
880  **********************************************************************/
881  GeodesicLine DirectLine(real lat1, real lon1, real azi1, real s12,
882  unsigned caps = ALL) const;
883 
884  /**
885  * Define a GeodesicLine in terms of the direct geodesic problem specified
886  * in terms of arc length.
887  *
888  * @param[in] lat1 latitude of point 1 (degrees).
889  * @param[in] lon1 longitude of point 1 (degrees).
890  * @param[in] azi1 azimuth at point 1 (degrees).
891  * @param[in] a12 arc length between point 1 and point 2 (degrees); it can
892  * be negative.
893  * @param[in] caps bitor'ed combination of Geodesic::mask values
894  * specifying the capabilities the GeodesicLine object should possess,
895  * i.e., which quantities can be returned in calls to
896  * GeodesicLine::Position.
897  * @return a GeodesicLine object.
898  *
899  * This function sets point 3 of the GeodesicLine to correspond to point 2
900  * of the direct geodesic problem.
901  *
902  * \e lat1 should be in the range [&minus;90&deg;, 90&deg;].
903  **********************************************************************/
904  GeodesicLine ArcDirectLine(real lat1, real lon1, real azi1, real a12,
905  unsigned caps = ALL) const;
906 
907  /**
908  * Define a GeodesicLine in terms of the direct geodesic problem specified
909  * in terms of either distance or arc length.
910  *
911  * @param[in] lat1 latitude of point 1 (degrees).
912  * @param[in] lon1 longitude of point 1 (degrees).
913  * @param[in] azi1 azimuth at point 1 (degrees).
914  * @param[in] arcmode boolean flag determining the meaning of the \e
915  * s12_a12.
916  * @param[in] s12_a12 if \e arcmode is false, this is the distance between
917  * point 1 and point 2 (meters); otherwise it is the arc length between
918  * point 1 and point 2 (degrees); it can be negative.
919  * @param[in] caps bitor'ed combination of Geodesic::mask values
920  * specifying the capabilities the GeodesicLine object should possess,
921  * i.e., which quantities can be returned in calls to
922  * GeodesicLine::Position.
923  * @return a GeodesicLine object.
924  *
925  * This function sets point 3 of the GeodesicLine to correspond to point 2
926  * of the direct geodesic problem.
927  *
928  * \e lat1 should be in the range [&minus;90&deg;, 90&deg;].
929  **********************************************************************/
930  GeodesicLine GenDirectLine(real lat1, real lon1, real azi1,
931  bool arcmode, real s12_a12,
932  unsigned caps = ALL) const;
933  ///@}
934 
935  /** \name Inspector functions.
936  **********************************************************************/
937  ///@{
938 
939  /**
940  * @return \e a the equatorial radius of the ellipsoid (meters). This is
941  * the value used in the constructor.
942  **********************************************************************/
943  Math::real MajorRadius() const { return _a; }
944 
945  /**
946  * @return \e f the flattening of the ellipsoid. This is the
947  * value used in the constructor.
948  **********************************************************************/
949  Math::real Flattening() const { return _f; }
950 
951  /**
952  * @return total area of ellipsoid in meters<sup>2</sup>. The area of a
953  * polygon encircling a pole can be found by adding
954  * Geodesic::EllipsoidArea()/2 to the sum of \e S12 for each side of the
955  * polygon.
956  **********************************************************************/
958  { return 4 * Math::pi() * _c2; }
959  ///@}
960 
961  /**
962  * A global instantiation of Geodesic with the parameters for the WGS84
963  * ellipsoid.
964  **********************************************************************/
965  static const Geodesic& WGS84();
966 
967  };
968 
969 } // namespace GeographicLib
970 
971 #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 &M12, real &M21) const
Definition: Geodesic.hpp:564
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
static T pi()
Definition: Math.hpp:202
#define GEOGRAPHICLIB_EXPORT
Definition: Constants.hpp:91
Math::real MajorRadius() const
Definition: Geodesic.hpp:943
GeographicLib::Math::real real
Definition: GeodSolve.cpp:31
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) const
Definition: Geodesic.hpp:504
Math::real Direct(real lat1, real lon1, real azi1, real s12, real &lat2, real &lon2) const
Definition: Geodesic.hpp:393
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:491
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:551
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &s12, real &azi1, real &azi2) const
Definition: Geodesic.hpp:708
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
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
Namespace for GeographicLib.
Definition: Accumulator.cpp:12
void ArcDirect(real lat1, real lon1, real azi1, real a12, real &lat2, real &lon2, real &azi2, real &s12) const
Definition: Geodesic.hpp:526
void ArcDirect(real lat1, real lon1, real azi1, real a12, real &lat2, real &lon2, real &azi2) const
Definition: Geodesic.hpp:515
Math::real Flattening() const
Definition: Geodesic.hpp:949
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 Inverse(real lat1, real lon1, real lat2, real lon2, real &s12) const
Definition: Geodesic.hpp:686
Math::real Direct(real lat1, real lon1, real azi1, real s12, real &lat2, real &lon2, real &azi2, real &m12) const
Definition: Geodesic.hpp:417
Header for GeographicLib::Constants class.
Math::real EllipsoidArea() const
Definition: Geodesic.hpp:957
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 &M21) const
Definition: Geodesic.hpp:429
#define GEOGRAPHICLIB_GEODESIC_ORDER
Definition: Geodesic.hpp:20
void ArcDirect(real lat1, real lon1, real azi1, real a12, real &lat2, real &lon2, real &azi2, real &s12, real &m12) const
Definition: Geodesic.hpp:538
Geodesic calculations
Definition: Geodesic.hpp:172
Math::real Direct(real lat1, real lon1, real azi1, real s12, real &lat2, real &lon2, real &azi2) const
Definition: Geodesic.hpp:405
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