GeographicLib  1.45
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] &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  * - s12 = 0 (coincident points). There are infinitely many geodesics which
130  * can be generated by setting [\e azi1, \e azi2] &rarr; [\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.
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)
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;].
815  *
816  * The Geodesic::mask values are
817  * - \e caps |= Geodesic::LATITUDE for the latitude \e lat2; this is
818  * added automatically;
819  * - \e caps |= Geodesic::LONGITUDE for the latitude \e lon2;
820  * - \e caps |= Geodesic::AZIMUTH for the azimuth \e azi2; this is
821  * added automatically;
822  * - \e caps |= Geodesic::DISTANCE for the distance \e s12;
823  * - \e caps |= Geodesic::REDUCEDLENGTH for the reduced length \e m12;
824  * - \e caps |= Geodesic::GEODESICSCALE for the geodesic scales \e M12
825  * and \e M21;
826  * - \e caps |= Geodesic::AREA for the area \e S12;
827  * - \e caps |= Geodesic::DISTANCE_IN permits the length of the
828  * geodesic to be given in terms of \e s12; without this capability the
829  * length can only be specified in terms of arc length;
830  * - \e caps |= Geodesic::ALL for all of the above.
831  * .
832  * The default value of \e caps is Geodesic::ALL.
833  *
834  * If the point is at a pole, the azimuth is defined by keeping \e lon1
835  * fixed, writing \e lat1 = &plusmn;(90 &minus; &epsilon;), and taking the
836  * limit &epsilon; &rarr; 0+.
837  **********************************************************************/
838  GeodesicLine Line(real lat1, real lon1, real azi1, unsigned caps = ALL)
839  const;
840 
841  ///@}
842 
843  /** \name Inspector functions.
844  **********************************************************************/
845  ///@{
846 
847  /**
848  * @return \e a the equatorial radius of the ellipsoid (meters). This is
849  * the value used in the constructor.
850  **********************************************************************/
851  Math::real MajorRadius() const { return _a; }
852 
853  /**
854  * @return \e f the flattening of the ellipsoid. This is the
855  * value used in the constructor.
856  **********************************************************************/
857  Math::real Flattening() const { return _f; }
858 
859  /// \cond SKIP
860  /**
861  * <b>DEPRECATED</b>
862  * @return \e r the inverse flattening of the ellipsoid.
863  **********************************************************************/
864  Math::real InverseFlattening() const { return 1/_f; }
865  /// \endcond
866 
867  /**
868  * @return total area of ellipsoid in meters<sup>2</sup>. The area of a
869  * polygon encircling a pole can be found by adding
870  * Geodesic::EllipsoidArea()/2 to the sum of \e S12 for each side of the
871  * polygon.
872  **********************************************************************/
874  { return 4 * Math::pi() * _c2; }
875  ///@}
876 
877  /**
878  * A global instantiation of Geodesic with the parameters for the WGS84
879  * ellipsoid.
880  **********************************************************************/
881  static const Geodesic& WGS84();
882 
883  };
884 
885 } // namespace GeographicLib
886 
887 #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:551
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:538
Math::real Direct(real lat1, real lon1, real azi1, real s12, real &lat2, real &lon2, real &azi2, real &m12, real &M12, real &M21, real &S12) const
Definition: Geodesic.hpp:379
Math::real Direct(real lat1, real lon1, real azi1, real s12, real &lat2, real &lon2, real &azi2, real &m12) const
Definition: Geodesic.hpp:417
GeographicLib::Math::real real
Definition: GeodSolve.cpp:32
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &s12, real &azi1, real &azi2, real &m12, real &M12, real &M21, real &S12) const
Definition: Geodesic.hpp:674
Math::real MajorRadius() const
Definition: Geodesic.hpp:851
void ArcDirect(real lat1, real lon1, real azi1, real a12, real &lat2, real &lon2) const
Definition: Geodesic.hpp:504
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) const
Definition: Geodesic.hpp:393
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &s12, real &azi1, real &azi2, real &M12, real &M21) const
Definition: Geodesic.hpp: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:442
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:873
void ArcDirect(real lat1, real lon1, real azi1, real a12, real &lat2, real &lon2, real &azi2) const
Definition: Geodesic.hpp:515
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
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:526
#define GEOGRAPHICLIB_GEODESIC_ORDER
Definition: Geodesic.hpp:20
Math::real Direct(real lat1, real lon1, real azi1, real s12, real &lat2, real &lon2, real &azi2) const
Definition: Geodesic.hpp:405
Math::real Direct(real lat1, real lon1, real azi1, real s12, real &lat2, real &lon2, real &azi2, real &M12, real &M21) const
Definition: Geodesic.hpp:429
Math::real Flattening() const
Definition: Geodesic.hpp:857
Geodesic calculations
Definition: Geodesic.hpp:171