GeographicLib  1.42
GeodesicExact.hpp
Go to the documentation of this file.
1 /**
2  * \file GeodesicExact.hpp
3  * \brief Header for GeographicLib::GeodesicExact class
4  *
5  * Copyright (c) Charles Karney (2012-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_GEODESICEXACT_HPP)
11 #define GEOGRAPHICLIB_GEODESICEXACT_HPP 1
12 
15 
16 #if !defined(GEOGRAPHICLIB_GEODESICEXACT_ORDER)
17 /**
18  * The order of the expansions used by GeodesicExact.
19  **********************************************************************/
20 # define GEOGRAPHICLIB_GEODESICEXACT_ORDER 30
21 #endif
22 
23 namespace GeographicLib {
24 
25  class GeodesicLineExact;
26 
27  /**
28  * \brief Exact geodesic calculations
29  *
30  * The equations for geodesics on an ellipsoid can be expressed in terms of
31  * incomplete elliptic integrals. The Geodesic class expands these integrals
32  * in a series in the flattening \e f and this provides an accurate solution
33  * for \e f &isin; [-0.01, 0.01]. The GeodesicExact class computes the
34  * ellitpic integrals directly and so provides a solution which is valid for
35  * all \e f. However, in practice, its use should be limited to about
36  * <i>b</i>/\e a &isin; [0.01, 100] or \e f &isin; [-99, 0.99].
37  *
38  * For the WGS84 ellipsoid, these classes are 2--3 times \e slower than the
39  * series solution and 2--3 times \e less \e accurate (because it's less easy
40  * to control round-off errors with the elliptic integral formulation); i.e.,
41  * the error is about 40 nm (40 nanometers) instead of 15 nm. However the
42  * error in the series solution scales as <i>f</i><sup>7</sup> while the
43  * error in the elliptic integral solution depends weakly on \e f. If the
44  * quarter meridian distance is 10000 km and the ratio <i>b</i>/\e a = 1
45  * &minus; \e f is varied then the approximate maximum error (expressed as a
46  * distance) is <pre>
47  * 1 - f error (nm)
48  * 1/128 387
49  * 1/64 345
50  * 1/32 269
51  * 1/16 210
52  * 1/8 115
53  * 1/4 69
54  * 1/2 36
55  * 1 15
56  * 2 25
57  * 4 96
58  * 8 318
59  * 16 985
60  * 32 2352
61  * 64 6008
62  * 128 19024
63  * </pre>
64  *
65  * The computation of the area in these classes is via a 30th order series.
66  * This gives accurate results for <i>b</i>/\e a &isin; [1/2, 2]; the
67  * accuracy is about 8 decimal digits for <i>b</i>/\e a &isin; [1/4, 4].
68  *
69  * See \ref geodellip for the formulation. See the documentation on the
70  * Geodesic class for additional information on the geodesic problems.
71  *
72  * Example of use:
73  * \include example-GeodesicExact.cpp
74  *
75  * <a href="GeodSolve.1.html">GeodSolve</a> is a command-line utility
76  * providing access to the functionality of GeodesicExact and
77  * GeodesicLineExact (via the -E option).
78  **********************************************************************/
79 
81  private:
82  typedef Math::real real;
83  friend class GeodesicLineExact;
84  static const int nC4_ = GEOGRAPHICLIB_GEODESICEXACT_ORDER;
85  static const int nC4x_ = (nC4_ * (nC4_ + 1)) / 2;
86  static const unsigned maxit1_ = 20;
87  unsigned maxit2_;
88  real tiny_, tol0_, tol1_, tol2_, tolb_, xthresh_;
89 
90  enum captype {
91  CAP_NONE = 0U,
92  CAP_E = 1U<<0,
93  // Skip 1U<<1 for compatibility with Geodesic (not required)
94  CAP_D = 1U<<2,
95  CAP_H = 1U<<3,
96  CAP_C4 = 1U<<4,
97  CAP_ALL = 0x1FU,
98  CAP_MASK = CAP_ALL,
99  OUT_ALL = 0x7F80U,
100  OUT_MASK = 0xFF80U, // Includes LONG_NOWRAP
101  };
102 
103  static real CosSeries(real sinx, real cosx, const real c[], int n);
104  static real Astroid(real x, real y);
105 
106  real _a, _f, _f1, _e2, _ep2, _n, _b, _c2, _etol2;
107  real _C4x[nC4x_];
108 
109  void Lengths(const EllipticFunction& E,
110  real sig12,
111  real ssig1, real csig1, real dn1,
112  real ssig2, real csig2, real dn2,
113  real cbet1, real cbet2,
114  real& s12s, real& m12a, real& m0,
115  bool scalep, real& M12, real& M21) const;
116  real InverseStart(EllipticFunction& E,
117  real sbet1, real cbet1, real dn1,
118  real sbet2, real cbet2, real dn2,
119  real lam12,
120  real& salp1, real& calp1,
121  real& salp2, real& calp2, real& dnm) const;
122  real Lambda12(real sbet1, real cbet1, real dn1,
123  real sbet2, real cbet2, real dn2,
124  real salp1, real calp1,
125  real& salp2, real& calp2, real& sig12,
126  real& ssig1, real& csig1, real& ssig2, real& csig2,
127  EllipticFunction& E,
128  real& omg12, bool diffp, real& dlam12) const;
129 
130  // These are Maxima generated functions to provide series approximations to
131  // the integrals for the area.
132  void C4coeff();
133  void C4f(real k2, real c[]) const;
134  // Large coefficients are split so that lo contains the low 52 bits and hi
135  // the rest. This choice avoids double rounding with doubles and higher
136  // precision types. float coefficients will suffer double rounding;
137  // however the accuracy is already lousy for floats.
138  static Math::real inline reale(long long hi, long long lo) {
139  using std::ldexp;
140  return ldexp(real(hi), 52) + lo;
141  }
142  static const Math::real* rawC4coeff();
143 
144  public:
145 
146  /**
147  * Bit masks for what calculations to do. These masks do double duty.
148  * They signify to the GeodesicLineExact::GeodesicLineExact constructor and
149  * to GeodesicExact::Line what capabilities should be included in the
150  * GeodesicLineExact object. They also specify which results to return in
151  * the general routines GeodesicExact::GenDirect and
152  * GeodesicExact::GenInverse routines. GeodesicLineExact::mask is a
153  * duplication of this enum.
154  **********************************************************************/
155  enum mask {
156  /**
157  * No capabilities, no output.
158  * @hideinitializer
159  **********************************************************************/
160  NONE = 0U,
161  /**
162  * Calculate latitude \e lat2. (It's not necessary to include this as a
163  * capability to GeodesicLineExact because this is included by default.)
164  * @hideinitializer
165  **********************************************************************/
166  LATITUDE = 1U<<7 | CAP_NONE,
167  /**
168  * Calculate longitude \e lon2.
169  * @hideinitializer
170  **********************************************************************/
171  LONGITUDE = 1U<<8 | CAP_H,
172  /**
173  * Calculate azimuths \e azi1 and \e azi2. (It's not necessary to
174  * include this as a capability to GeodesicLineExact because this is
175  * included by default.)
176  * @hideinitializer
177  **********************************************************************/
178  AZIMUTH = 1U<<9 | CAP_NONE,
179  /**
180  * Calculate distance \e s12.
181  * @hideinitializer
182  **********************************************************************/
183  DISTANCE = 1U<<10 | CAP_E,
184  /**
185  * Allow distance \e s12 to be used as input in the direct geodesic
186  * problem.
187  * @hideinitializer
188  **********************************************************************/
189  DISTANCE_IN = 1U<<11 | CAP_E,
190  /**
191  * Calculate reduced length \e m12.
192  * @hideinitializer
193  **********************************************************************/
194  REDUCEDLENGTH = 1U<<12 | CAP_D,
195  /**
196  * Calculate geodesic scales \e M12 and \e M21.
197  * @hideinitializer
198  **********************************************************************/
199  GEODESICSCALE = 1U<<13 | CAP_D,
200  /**
201  * Calculate area \e S12.
202  * @hideinitializer
203  **********************************************************************/
204  AREA = 1U<<14 | CAP_C4,
205  /**
206  * Do not wrap the \e lon2 in the direct calculation.
207  * @hideinitializer
208  **********************************************************************/
209  LONG_NOWRAP = 1U<<15,
210  /**
211  * All capabilities, calculate everything. (LONG_NOWRAP is not
212  * included in this mask.)
213  * @hideinitializer
214  **********************************************************************/
215  ALL = OUT_ALL| CAP_ALL,
216  };
217 
218  /** \name Constructor
219  **********************************************************************/
220  ///@{
221  /**
222  * Constructor for a ellipsoid with
223  *
224  * @param[in] a equatorial radius (meters).
225  * @param[in] f flattening of ellipsoid. Setting \e f = 0 gives a sphere.
226  * Negative \e f gives a prolate ellipsoid. If \e f &gt; 1, set
227  * flattening to 1/\e f.
228  * @exception GeographicErr if \e a or (1 &minus; \e f) \e a is not
229  * positive.
230  **********************************************************************/
231  GeodesicExact(real a, real f);
232  ///@}
233 
234  /** \name Direct geodesic problem specified in terms of distance.
235  **********************************************************************/
236  ///@{
237  /**
238  * Perform the direct geodesic calculation where the length of the geodesic
239  * is specified in terms of distance.
240  *
241  * @param[in] lat1 latitude of point 1 (degrees).
242  * @param[in] lon1 longitude of point 1 (degrees).
243  * @param[in] azi1 azimuth at point 1 (degrees).
244  * @param[in] s12 distance between point 1 and point 2 (meters); it can be
245  * signed.
246  * @param[out] lat2 latitude of point 2 (degrees).
247  * @param[out] lon2 longitude of point 2 (degrees).
248  * @param[out] azi2 (forward) azimuth at point 2 (degrees).
249  * @param[out] m12 reduced length of geodesic (meters).
250  * @param[out] M12 geodesic scale of point 2 relative to point 1
251  * (dimensionless).
252  * @param[out] M21 geodesic scale of point 1 relative to point 2
253  * (dimensionless).
254  * @param[out] S12 area under the geodesic (meters<sup>2</sup>).
255  * @return \e a12 arc length of between point 1 and point 2 (degrees).
256  *
257  * \e lat1 should be in the range [&minus;90&deg;, 90&deg;]; \e lon1 and \e
258  * azi1 should be in the range [&minus;540&deg;, 540&deg;). The values of
259  * \e lon2 and \e azi2 returned are in the range [&minus;180&deg;,
260  * 180&deg;).
261  *
262  * If either point is at a pole, the azimuth is defined by keeping the
263  * longitude fixed, writing \e lat = &plusmn;(90&deg; &minus; &epsilon;),
264  * and taking the limit &epsilon; &rarr; 0+. An arc length greater that
265  * 180&deg; signifies a geodesic which is not a shortest path. (For a
266  * prolate ellipsoid, an additional condition is necessary for a shortest
267  * path: the longitudinal extent must not exceed of 180&deg;.)
268  *
269  * The following functions are overloaded versions of GeodesicExact::Direct
270  * which omit some of the output parameters. Note, however, that the arc
271  * length is always computed and returned as the function value.
272  **********************************************************************/
273  Math::real Direct(real lat1, real lon1, real azi1, real s12,
274  real& lat2, real& lon2, real& azi2,
275  real& m12, real& M12, real& M21, real& S12)
276  const {
277  real t;
278  return GenDirect(lat1, lon1, azi1, false, s12,
279  LATITUDE | LONGITUDE | AZIMUTH |
280  REDUCEDLENGTH | GEODESICSCALE | AREA,
281  lat2, lon2, azi2, t, m12, M12, M21, S12);
282  }
283 
284  /**
285  * See the documentation for GeodesicExact::Direct.
286  **********************************************************************/
287  Math::real Direct(real lat1, real lon1, real azi1, real s12,
288  real& lat2, real& lon2)
289  const {
290  real t;
291  return GenDirect(lat1, lon1, azi1, false, s12,
292  LATITUDE | LONGITUDE,
293  lat2, lon2, t, t, t, t, t, t);
294  }
295 
296  /**
297  * See the documentation for GeodesicExact::Direct.
298  **********************************************************************/
299  Math::real Direct(real lat1, real lon1, real azi1, real s12,
300  real& lat2, real& lon2, real& azi2)
301  const {
302  real t;
303  return GenDirect(lat1, lon1, azi1, false, s12,
304  LATITUDE | LONGITUDE | AZIMUTH,
305  lat2, lon2, azi2, t, t, t, t, t);
306  }
307 
308  /**
309  * See the documentation for GeodesicExact::Direct.
310  **********************************************************************/
311  Math::real Direct(real lat1, real lon1, real azi1, real s12,
312  real& lat2, real& lon2, real& azi2, real& m12)
313  const {
314  real t;
315  return GenDirect(lat1, lon1, azi1, false, s12,
316  LATITUDE | LONGITUDE | AZIMUTH | REDUCEDLENGTH,
317  lat2, lon2, azi2, t, m12, t, t, t);
318  }
319 
320  /**
321  * See the documentation for GeodesicExact::Direct.
322  **********************************************************************/
323  Math::real Direct(real lat1, real lon1, real azi1, real s12,
324  real& lat2, real& lon2, real& azi2,
325  real& M12, real& M21)
326  const {
327  real t;
328  return GenDirect(lat1, lon1, azi1, false, s12,
329  LATITUDE | LONGITUDE | AZIMUTH | GEODESICSCALE,
330  lat2, lon2, azi2, t, t, M12, M21, t);
331  }
332 
333  /**
334  * See the documentation for GeodesicExact::Direct.
335  **********************************************************************/
336  Math::real Direct(real lat1, real lon1, real azi1, real s12,
337  real& lat2, real& lon2, real& azi2,
338  real& m12, real& M12, real& M21)
339  const {
340  real t;
341  return GenDirect(lat1, lon1, azi1, false, s12,
342  LATITUDE | LONGITUDE | AZIMUTH |
343  REDUCEDLENGTH | GEODESICSCALE,
344  lat2, lon2, azi2, t, m12, M12, M21, t);
345  }
346  ///@}
347 
348  /** \name Direct geodesic problem specified in terms of arc length.
349  **********************************************************************/
350  ///@{
351  /**
352  * Perform the direct geodesic calculation where the length of the geodesic
353  * is specified in terms of arc length.
354  *
355  * @param[in] lat1 latitude of point 1 (degrees).
356  * @param[in] lon1 longitude of point 1 (degrees).
357  * @param[in] azi1 azimuth at point 1 (degrees).
358  * @param[in] a12 arc length between point 1 and point 2 (degrees); it can
359  * be signed.
360  * @param[out] lat2 latitude of point 2 (degrees).
361  * @param[out] lon2 longitude of point 2 (degrees).
362  * @param[out] azi2 (forward) azimuth at point 2 (degrees).
363  * @param[out] s12 distance between point 1 and point 2 (meters).
364  * @param[out] m12 reduced length of geodesic (meters).
365  * @param[out] M12 geodesic scale of point 2 relative to point 1
366  * (dimensionless).
367  * @param[out] M21 geodesic scale of point 1 relative to point 2
368  * (dimensionless).
369  * @param[out] S12 area under the geodesic (meters<sup>2</sup>).
370  *
371  * \e lat1 should be in the range [&minus;90&deg;, 90&deg;]; \e lon1 and \e
372  * azi1 should be in the range [&minus;540&deg;, 540&deg;). The values of
373  * \e lon2 and \e azi2 returned are in the range [&minus;180&deg;,
374  * 180&deg;).
375  *
376  * If either point is at a pole, the azimuth is defined by keeping the
377  * longitude fixed, writing \e lat = &plusmn;(90&deg; &minus; &epsilon;),
378  * and taking the limit &epsilon; &rarr; 0+. An arc length greater that
379  * 180&deg; signifies a geodesic which is not a shortest path. (For a
380  * prolate ellipsoid, an additional condition is necessary for a shortest
381  * path: the longitudinal extent must not exceed of 180&deg;.)
382  *
383  * The following functions are overloaded versions of GeodesicExact::Direct
384  * which omit some of the output parameters.
385  **********************************************************************/
386  void ArcDirect(real lat1, real lon1, real azi1, real a12,
387  real& lat2, real& lon2, real& azi2, real& s12,
388  real& m12, real& M12, real& M21, real& S12)
389  const {
390  GenDirect(lat1, lon1, azi1, true, a12,
391  LATITUDE | LONGITUDE | AZIMUTH | DISTANCE |
392  REDUCEDLENGTH | GEODESICSCALE | AREA,
393  lat2, lon2, azi2, s12, m12, M12, M21, S12);
394  }
395 
396  /**
397  * See the documentation for GeodesicExact::ArcDirect.
398  **********************************************************************/
399  void ArcDirect(real lat1, real lon1, real azi1, real a12,
400  real& lat2, real& lon2) const {
401  real t;
402  GenDirect(lat1, lon1, azi1, true, a12,
403  LATITUDE | LONGITUDE,
404  lat2, lon2, t, t, t, t, t, t);
405  }
406 
407  /**
408  * See the documentation for GeodesicExact::ArcDirect.
409  **********************************************************************/
410  void ArcDirect(real lat1, real lon1, real azi1, real a12,
411  real& lat2, real& lon2, real& azi2) const {
412  real t;
413  GenDirect(lat1, lon1, azi1, true, a12,
414  LATITUDE | LONGITUDE | AZIMUTH,
415  lat2, lon2, azi2, t, t, t, t, t);
416  }
417 
418  /**
419  * See the documentation for GeodesicExact::ArcDirect.
420  **********************************************************************/
421  void ArcDirect(real lat1, real lon1, real azi1, real a12,
422  real& lat2, real& lon2, real& azi2, real& s12)
423  const {
424  real t;
425  GenDirect(lat1, lon1, azi1, true, a12,
426  LATITUDE | LONGITUDE | AZIMUTH | DISTANCE,
427  lat2, lon2, azi2, s12, t, t, t, t);
428  }
429 
430  /**
431  * See the documentation for GeodesicExact::ArcDirect.
432  **********************************************************************/
433  void ArcDirect(real lat1, real lon1, real azi1, real a12,
434  real& lat2, real& lon2, real& azi2,
435  real& s12, real& m12) const {
436  real t;
437  GenDirect(lat1, lon1, azi1, true, a12,
438  LATITUDE | LONGITUDE | AZIMUTH | DISTANCE |
439  REDUCEDLENGTH,
440  lat2, lon2, azi2, s12, m12, t, t, t);
441  }
442 
443  /**
444  * See the documentation for GeodesicExact::ArcDirect.
445  **********************************************************************/
446  void ArcDirect(real lat1, real lon1, real azi1, real a12,
447  real& lat2, real& lon2, real& azi2, real& s12,
448  real& M12, real& M21) const {
449  real t;
450  GenDirect(lat1, lon1, azi1, true, a12,
451  LATITUDE | LONGITUDE | AZIMUTH | DISTANCE |
452  GEODESICSCALE,
453  lat2, lon2, azi2, s12, t, M12, M21, t);
454  }
455 
456  /**
457  * See the documentation for GeodesicExact::ArcDirect.
458  **********************************************************************/
459  void ArcDirect(real lat1, real lon1, real azi1, real a12,
460  real& lat2, real& lon2, real& azi2, real& s12,
461  real& m12, real& M12, real& M21) const {
462  real t;
463  GenDirect(lat1, lon1, azi1, true, a12,
464  LATITUDE | LONGITUDE | AZIMUTH | DISTANCE |
465  REDUCEDLENGTH | GEODESICSCALE,
466  lat2, lon2, azi2, s12, m12, M12, M21, t);
467  }
468  ///@}
469 
470  /** \name General version of the direct geodesic solution.
471  **********************************************************************/
472  ///@{
473 
474  /**
475  * The general direct geodesic calculation. GeodesicExact::Direct and
476  * GeodesicExact::ArcDirect are defined in terms of this function.
477  *
478  * @param[in] lat1 latitude of point 1 (degrees).
479  * @param[in] lon1 longitude of point 1 (degrees).
480  * @param[in] azi1 azimuth at point 1 (degrees).
481  * @param[in] arcmode boolean flag determining the meaning of the second
482  * parameter.
483  * @param[in] s12_a12 if \e arcmode is false, this is the distance between
484  * point 1 and point 2 (meters); otherwise it is the arc length between
485  * point 1 and point 2 (degrees); it can be signed.
486  * @param[in] outmask a bitor'ed combination of GeodesicExact::mask values
487  * specifying which of the following parameters should be set.
488  * @param[out] lat2 latitude of point 2 (degrees).
489  * @param[out] lon2 longitude of point 2 (degrees).
490  * @param[out] azi2 (forward) azimuth at point 2 (degrees).
491  * @param[out] s12 distance between point 1 and point 2 (meters).
492  * @param[out] m12 reduced length of geodesic (meters).
493  * @param[out] M12 geodesic scale of point 2 relative to point 1
494  * (dimensionless).
495  * @param[out] M21 geodesic scale of point 1 relative to point 2
496  * (dimensionless).
497  * @param[out] S12 area under the geodesic (meters<sup>2</sup>).
498  * @return \e a12 arc length of between point 1 and point 2 (degrees).
499  *
500  * The GeodesicExact::mask values possible for \e outmask are
501  * - \e outmask |= GeodesicExact::LATITUDE for the latitude \e lat2;
502  * - \e outmask |= GeodesicExact::LONGITUDE for the latitude \e lon2;
503  * - \e outmask |= GeodesicExact::AZIMUTH for the latitude \e azi2;
504  * - \e outmask |= GeodesicExact::DISTANCE for the distance \e s12;
505  * - \e outmask |= GeodesicExact::REDUCEDLENGTH for the reduced length \e
506  * m12;
507  * - \e outmask |= GeodesicExact::GEODESICSCALE for the geodesic scales \e
508  * M12 and \e M21;
509  * - \e outmask |= GeodesicExact::AREA for the area \e S12;
510  * - \e outmask |= GeodesicExact::ALL for all of the above;
511  * - \e outmask |= GeodesicExact::LONG_NOWRAP stops the returned value of
512  * \e lon2 being wrapped into the range [&minus;180&deg;, 180&deg;).
513  * .
514  * The function value \e a12 is always computed and returned and this
515  * equals \e s12_a12 is \e arcmode is true. If \e outmask includes
516  * GeodesicExact::DISTANCE and \e arcmode is false, then \e s12 = \e
517  * s12_a12. It is not necessary to include GeodesicExact::DISTANCE_IN in
518  * \e outmask; this is automatically included is \e arcmode is false.
519  *
520  * With the LONG_NOWRAP bit set, the quantity \e lon2 &minus; \e lon1
521  * indicates how many times the geodesic wrapped around the ellipsoid.
522  * Because \e lon2 might be outside the normal allowed range for
523  * longitudes, [&minus;540&deg;, 540&deg;), be sure to normalize it with
524  * Math::AngNormalize2 before using it in other GeographicLib calls.
525  **********************************************************************/
526  Math::real GenDirect(real lat1, real lon1, real azi1,
527  bool arcmode, real s12_a12, unsigned outmask,
528  real& lat2, real& lon2, real& azi2,
529  real& s12, real& m12, real& M12, real& M21,
530  real& S12) const;
531  ///@}
532 
533  /** \name Inverse geodesic problem.
534  **********************************************************************/
535  ///@{
536  /**
537  * Perform the inverse geodesic calculation.
538  *
539  * @param[in] lat1 latitude of point 1 (degrees).
540  * @param[in] lon1 longitude of point 1 (degrees).
541  * @param[in] lat2 latitude of point 2 (degrees).
542  * @param[in] lon2 longitude of point 2 (degrees).
543  * @param[out] s12 distance between point 1 and point 2 (meters).
544  * @param[out] azi1 azimuth at point 1 (degrees).
545  * @param[out] azi2 (forward) azimuth at point 2 (degrees).
546  * @param[out] m12 reduced length of geodesic (meters).
547  * @param[out] M12 geodesic scale of point 2 relative to point 1
548  * (dimensionless).
549  * @param[out] M21 geodesic scale of point 1 relative to point 2
550  * (dimensionless).
551  * @param[out] S12 area under the geodesic (meters<sup>2</sup>).
552  * @return \e a12 arc length of between point 1 and point 2 (degrees).
553  *
554  * \e lat1 and \e lat2 should be in the range [&minus;90&deg;, 90&deg;]; \e
555  * lon1 and \e lon2 should be in the range [&minus;540&deg;, 540&deg;).
556  * The values of \e azi1 and \e azi2 returned are in the range
557  * [&minus;180&deg;, 180&deg;).
558  *
559  * If either point is at a pole, the azimuth is defined by keeping the
560  * longitude fixed, writing \e lat = &plusmn;(90&deg; &minus; &epsilon;),
561  * and taking the limit &epsilon; &rarr; 0+.
562  *
563  * The following functions are overloaded versions of GeodesicExact::Inverse
564  * which omit some of the output parameters. Note, however, that the arc
565  * length is always computed and returned as the function value.
566  **********************************************************************/
567  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
568  real& s12, real& azi1, real& azi2, real& m12,
569  real& M12, real& M21, real& S12) const {
570  return GenInverse(lat1, lon1, lat2, lon2,
571  DISTANCE | AZIMUTH |
572  REDUCEDLENGTH | GEODESICSCALE | AREA,
573  s12, azi1, azi2, m12, M12, M21, S12);
574  }
575 
576  /**
577  * See the documentation for GeodesicExact::Inverse.
578  **********************************************************************/
579  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
580  real& s12) const {
581  real t;
582  return GenInverse(lat1, lon1, lat2, lon2,
583  DISTANCE,
584  s12, t, t, t, t, t, t);
585  }
586 
587  /**
588  * See the documentation for GeodesicExact::Inverse.
589  **********************************************************************/
590  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
591  real& azi1, real& azi2) const {
592  real t;
593  return GenInverse(lat1, lon1, lat2, lon2,
594  AZIMUTH,
595  t, azi1, azi2, t, t, t, t);
596  }
597 
598  /**
599  * See the documentation for GeodesicExact::Inverse.
600  **********************************************************************/
601  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
602  real& s12, real& azi1, real& azi2)
603  const {
604  real t;
605  return GenInverse(lat1, lon1, lat2, lon2,
606  DISTANCE | AZIMUTH,
607  s12, azi1, azi2, t, t, t, t);
608  }
609 
610  /**
611  * See the documentation for GeodesicExact::Inverse.
612  **********************************************************************/
613  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
614  real& s12, real& azi1, real& azi2, real& m12)
615  const {
616  real t;
617  return GenInverse(lat1, lon1, lat2, lon2,
618  DISTANCE | AZIMUTH | REDUCEDLENGTH,
619  s12, azi1, azi2, m12, t, t, t);
620  }
621 
622  /**
623  * See the documentation for GeodesicExact::Inverse.
624  **********************************************************************/
625  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
626  real& s12, real& azi1, real& azi2,
627  real& M12, real& M21) const {
628  real t;
629  return GenInverse(lat1, lon1, lat2, lon2,
630  DISTANCE | AZIMUTH | GEODESICSCALE,
631  s12, azi1, azi2, t, M12, M21, t);
632  }
633 
634  /**
635  * See the documentation for GeodesicExact::Inverse.
636  **********************************************************************/
637  Math::real Inverse(real lat1, real lon1, real lat2, real lon2,
638  real& s12, real& azi1, real& azi2, real& m12,
639  real& M12, real& M21) const {
640  real t;
641  return GenInverse(lat1, lon1, lat2, lon2,
642  DISTANCE | AZIMUTH |
643  REDUCEDLENGTH | GEODESICSCALE,
644  s12, azi1, azi2, m12, M12, M21, t);
645  }
646  ///@}
647 
648  /** \name General version of inverse geodesic solution.
649  **********************************************************************/
650  ///@{
651  /**
652  * The general inverse geodesic calculation. GeodesicExact::Inverse is
653  * defined in terms of this function.
654  *
655  * @param[in] lat1 latitude of point 1 (degrees).
656  * @param[in] lon1 longitude of point 1 (degrees).
657  * @param[in] lat2 latitude of point 2 (degrees).
658  * @param[in] lon2 longitude of point 2 (degrees).
659  * @param[in] outmask a bitor'ed combination of GeodesicExact::mask values
660  * specifying which of the following parameters should be set.
661  * @param[out] s12 distance between point 1 and point 2 (meters).
662  * @param[out] azi1 azimuth at point 1 (degrees).
663  * @param[out] azi2 (forward) azimuth at point 2 (degrees).
664  * @param[out] m12 reduced length of geodesic (meters).
665  * @param[out] M12 geodesic scale of point 2 relative to point 1
666  * (dimensionless).
667  * @param[out] M21 geodesic scale of point 1 relative to point 2
668  * (dimensionless).
669  * @param[out] S12 area under the geodesic (meters<sup>2</sup>).
670  * @return \e a12 arc length of between point 1 and point 2 (degrees).
671  *
672  * The GeodesicExact::mask values possible for \e outmask are
673  * - \e outmask |= GeodesicExact::DISTANCE for the distance \e s12;
674  * - \e outmask |= GeodesicExact::AZIMUTH for the latitude \e azi2;
675  * - \e outmask |= GeodesicExact::REDUCEDLENGTH for the reduced length \e
676  * m12;
677  * - \e outmask |= GeodesicExact::GEODESICSCALE for the geodesic scales \e
678  * M12 and \e M21;
679  * - \e outmask |= GeodesicExact::AREA for the area \e S12;
680  * - \e outmask |= GeodesicExact::ALL for all of the above.
681  * .
682  * The arc length is always computed and returned as the function value.
683  **********************************************************************/
684  Math::real GenInverse(real lat1, real lon1, real lat2, real lon2,
685  unsigned outmask,
686  real& s12, real& azi1, real& azi2,
687  real& m12, real& M12, real& M21, real& S12)
688  const;
689  ///@}
690 
691  /** \name Interface to GeodesicLineExact.
692  **********************************************************************/
693  ///@{
694 
695  /**
696  * Set up to compute several points on a single geodesic.
697  *
698  * @param[in] lat1 latitude of point 1 (degrees).
699  * @param[in] lon1 longitude of point 1 (degrees).
700  * @param[in] azi1 azimuth at point 1 (degrees).
701  * @param[in] caps bitor'ed combination of GeodesicExact::mask values
702  * specifying the capabilities the GeodesicLineExact object should
703  * possess, i.e., which quantities can be returned in calls to
704  * GeodesicLineExact::Position.
705  * @return a GeodesicLineExact object.
706  *
707  * \e lat1 should be in the range [&minus;90&deg;, 90&deg;]; \e lon1 and \e
708  * azi1 should be in the range [&minus;540&deg;, 540&deg;).
709  *
710  * The GeodesicExact::mask values are
711  * - \e caps |= GeodesicExact::LATITUDE for the latitude \e lat2; this is
712  * added automatically;
713  * - \e caps |= GeodesicExact::LONGITUDE for the latitude \e lon2;
714  * - \e caps |= GeodesicExact::AZIMUTH for the azimuth \e azi2; this is
715  * added automatically;
716  * - \e caps |= GeodesicExact::DISTANCE for the distance \e s12;
717  * - \e caps |= GeodesicExact::REDUCEDLENGTH for the reduced length \e m12;
718  * - \e caps |= GeodesicExact::GEODESICSCALE for the geodesic scales \e M12
719  * and \e M21;
720  * - \e caps |= GeodesicExact::AREA for the area \e S12;
721  * - \e caps |= GeodesicExact::DISTANCE_IN permits the length of the
722  * geodesic to be given in terms of \e s12; without this capability the
723  * length can only be specified in terms of arc length;
724  * - \e caps |= GeodesicExact::ALL for all of the above.
725  * .
726  * The default value of \e caps is GeodesicExact::ALL which turns on all
727  * the capabilities.
728  *
729  * If the point is at a pole, the azimuth is defined by keeping \e lon1
730  * fixed, writing \e lat1 = &plusmn;(90 &minus; &epsilon;), and taking the
731  * limit &epsilon; &rarr; 0+.
732  **********************************************************************/
733  GeodesicLineExact Line(real lat1, real lon1, real azi1, unsigned caps = ALL)
734  const;
735 
736  ///@}
737 
738  /** \name Inspector functions.
739  **********************************************************************/
740  ///@{
741 
742  /**
743  * @return \e a the equatorial radius of the ellipsoid (meters). This is
744  * the value used in the constructor.
745  **********************************************************************/
746  Math::real MajorRadius() const { return _a; }
747 
748  /**
749  * @return \e f the flattening of the ellipsoid. This is the
750  * value used in the constructor.
751  **********************************************************************/
752  Math::real Flattening() const { return _f; }
753 
754  /// \cond SKIP
755  /**
756  * <b>DEPRECATED</b>
757  * @return \e r the inverse flattening of the ellipsoid.
758  **********************************************************************/
759  Math::real InverseFlattening() const { return 1/_f; }
760  /// \endcond
761 
762  /**
763  * @return total area of ellipsoid in meters<sup>2</sup>. The area of a
764  * polygon encircling a pole can be found by adding
765  * GeodesicExact::EllipsoidArea()/2 to the sum of \e S12 for each side of
766  * the polygon.
767  **********************************************************************/
769  { return 4 * Math::pi() * _c2; }
770  ///@}
771 
772  /**
773  * A global instantiation of GeodesicExact with the parameters for the WGS84
774  * ellipsoid.
775  **********************************************************************/
776  static const GeodesicExact& WGS84();
777 
778  };
779 
780 } // namespace GeographicLib
781 
782 #endif // GEOGRAPHICLIB_GEODESICEXACT_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, real &S12) const
static T pi()
Definition: Math.hpp:214
#define GEOGRAPHICLIB_EXPORT
Definition: Constants.hpp:90
Math::real Flattening() const
Math::real EllipsoidArea() const
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &s12, real &azi1, real &azi2, real &m12, real &M12, real &M21) const
GeographicLib::Math::real real
Definition: GeodSolve.cpp:32
Math::real Direct(real lat1, real lon1, real azi1, real s12, real &lat2, real &lon2, real &azi2) const
Math::real Direct(real lat1, real lon1, real azi1, real s12, real &lat2, real &lon2, real &azi2, real &m12, real &M12, real &M21) const
void ArcDirect(real lat1, real lon1, real azi1, real a12, real &lat2, real &lon2) const
Elliptic integrals and functions.
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &s12, real &azi1, real &azi2, real &M12, real &M21) const
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
void ArcDirect(real lat1, real lon1, real azi1, real a12, real &lat2, real &lon2, real &azi2, real &s12) const
#define GEOGRAPHICLIB_GEODESICEXACT_ORDER
Math::real Direct(real lat1, real lon1, real azi1, real s12, real &lat2, real &lon2) const
void ArcDirect(real lat1, real lon1, real azi1, real a12, real &lat2, real &lon2, real &azi2, real &s12, real &M12, real &M21) const
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &azi1, real &azi2) const
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, real &m12) const
Math::real Direct(real lat1, real lon1, real azi1, real s12, real &lat2, real &lon2, real &azi2, real &M12, real &M21) const
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &s12) const
Header for GeographicLib::EllipticFunction class.
Exact geodesic calculations.
void ArcDirect(real lat1, real lon1, real azi1, real a12, real &lat2, real &lon2, real &azi2) const
Header for GeographicLib::Constants class.
Math::real Direct(real lat1, real lon1, real azi1, real s12, real &lat2, real &lon2, real &azi2, real &m12) const
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &s12, real &azi1, real &azi2, real &m12) const
Math::real MajorRadius() const
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &s12, real &azi1, real &azi2) const
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
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