Rhumb.hpp
Go to the documentation of this file.
1 
10 #if !defined(GEOGRAPHICLIB_RHUMB_HPP)
11 #define GEOGRAPHICLIB_RHUMB_HPP 1
12 
15 
16 #if !defined(GEOGRAPHICLIB_RHUMBAREA_ORDER)
17 
21 # define GEOGRAPHICLIB_RHUMBAREA_ORDER \
22  (GEOGRAPHICLIB_PRECISION == 2 ? 6 : \
23  (GEOGRAPHICLIB_PRECISION == 1 ? 4 : 8))
24 #endif
25 
26 namespace GeographicLib {
27 
28  class RhumbLine;
29  template <class T> class PolygonAreaT;
30 
67  private:
68  typedef Math::real real;
69  friend class RhumbLine;
70  template <class T> friend class PolygonAreaT;
72  bool _exact;
73  real _c2;
74  static const int tm_maxord = GEOGRAPHICLIB_TRANSVERSEMERCATOR_ORDER;
75  static const int maxpow_ = GEOGRAPHICLIB_RHUMBAREA_ORDER;
76  // _R[0] unused
77  real _R[maxpow_ + 1];
78  static real gd(real x)
79  { using std::atan; using std::sinh; return atan(sinh(x)); }
80 
81  // Use divided differences to determine (mu2 - mu1) / (psi2 - psi1)
82  // accurately
83  //
84  // Definition: Df(x,y,d) = (f(x) - f(y)) / (x - y)
85  // See:
86  // W. M. Kahan and R. J. Fateman,
87  // Symbolic computation of divided differences,
88  // SIGSAM Bull. 33(3), 7-28 (1999)
89  // https://doi.org/10.1145/334714.334716
90  // http://www.cs.berkeley.edu/~fateman/papers/divdiff.pdf
91 
92  static real Dlog(real x, real y) {
93  real t = x - y;
94  return t != 0 ? 2 * Math::atanh(t / (x + y)) / t : 1 / x;
95  }
96  // N.B., x and y are in degrees
97  static real Dtan(real x, real y) {
98  real d = x - y, tx = Math::tand(x), ty = Math::tand(y), txy = tx * ty;
99  return d != 0 ?
100  (2 * txy > -1 ? (1 + txy) * Math::tand(d) : tx - ty) /
101  (d * Math::degree()) :
102  1 + txy;
103  }
104  static real Datan(real x, real y) {
105  using std::atan;
106  real d = x - y, xy = x * y;
107  return d != 0 ?
108  (2 * xy > -1 ? atan( d / (1 + xy) ) : atan(x) - atan(y)) / d :
109  1 / (1 + xy);
110  }
111  static real Dsin(real x, real y) {
112  using std::sin; using std::cos;
113  real d = (x - y) / 2;
114  return cos((x + y)/2) * (d != 0 ? sin(d) / d : 1);
115  }
116  static real Dsinh(real x, real y) {
117  using std::sinh; using std::cosh;
118  real d = (x - y) / 2;
119  return cosh((x + y) / 2) * (d != 0 ? sinh(d) / d : 1);
120  }
121  static real Dcosh(real x, real y) {
122  using std::sinh;
123  real d = (x - y) / 2;
124  return sinh((x + y) / 2) * (d != 0 ? sinh(d) / d : 1);
125  }
126  static real Dasinh(real x, real y) {
127  real d = x - y,
128  hx = Math::hypot(real(1), x), hy = Math::hypot(real(1), y);
129  return d != 0 ? Math::asinh(x*y > 0 ? d * (x + y) / (x*hy + y*hx) :
130  x*hy - y*hx) / d :
131  1 / hx;
132  }
133  static real Dgd(real x, real y) {
134  using std::sinh;
135  return Datan(sinh(x), sinh(y)) * Dsinh(x, y);
136  }
137  // N.B., x and y are the tangents of the angles
138  static real Dgdinv(real x, real y)
139  { return Dasinh(x, y) / Datan(x, y); }
140  // Copied from LambertConformalConic...
141  // Deatanhe(x,y) = eatanhe((x-y)/(1-e^2*x*y))/(x-y)
142  real Deatanhe(real x, real y) const {
143  real t = x - y, d = 1 - _ell._e2 * x * y;
144  return t != 0 ? Math::eatanhe(t / d, _ell._es) / t : _ell._e2 / d;
145  }
146  // (E(x) - E(y)) / (x - y) -- E = incomplete elliptic integral of 2nd kind
147  real DE(real x, real y) const;
148  // (mux - muy) / (phix - phiy) using elliptic integrals
149  real DRectifying(real latx, real laty) const;
150  // (psix - psiy) / (phix - phiy)
151  real DIsometric(real latx, real laty) const;
152 
153  // (sum(c[j]*sin(2*j*x),j=1..n) - sum(c[j]*sin(2*j*x),j=1..n)) / (x - y)
154  static real SinCosSeries(bool sinp,
155  real x, real y, const real c[], int n);
156  // (mux - muy) / (chix - chiy) using Krueger's series
157  real DConformalToRectifying(real chix, real chiy) const;
158  // (chix - chiy) / (mux - muy) using Krueger's series
159  real DRectifyingToConformal(real mux, real muy) const;
160 
161  // (mux - muy) / (psix - psiy)
162  // N.B., psix and psiy are in degrees
163  real DIsometricToRectifying(real psix, real psiy) const;
164  // (psix - psiy) / (mux - muy)
165  real DRectifyingToIsometric(real mux, real muy) const;
166 
167  real MeanSinXi(real psi1, real psi2) const;
168 
169  // The following two functions (with lots of ignored arguments) mimic the
170  // interface to the corresponding Geodesic function. These are needed by
171  // PolygonAreaT.
172  void GenDirect(real lat1, real lon1, real azi12,
173  bool, real s12, unsigned outmask,
174  real& lat2, real& lon2, real&, real&, real&, real&, real&,
175  real& S12) const {
176  GenDirect(lat1, lon1, azi12, s12, outmask, lat2, lon2, S12);
177  }
178  void GenInverse(real lat1, real lon1, real lat2, real lon2,
179  unsigned outmask, real& s12, real& azi12,
180  real&, real& , real& , real& , real& S12) const {
181  GenInverse(lat1, lon1, lat2, lon2, outmask, s12, azi12, S12);
182  }
183  public:
184 
190  enum mask {
195  NONE = 0U,
200  LATITUDE = 1U<<7,
205  LONGITUDE = 1U<<8,
210  AZIMUTH = 1U<<9,
215  DISTANCE = 1U<<10,
220  AREA = 1U<<14,
225  LONG_UNROLL = 1U<<15,
230  ALL = 0x7F80U,
231  };
232 
247  Rhumb(real a, real f, bool exact = true);
248 
271  void Direct(real lat1, real lon1, real azi12, real s12,
272  real& lat2, real& lon2, real& S12) const {
273  GenDirect(lat1, lon1, azi12, s12,
274  LATITUDE | LONGITUDE | AREA, lat2, lon2, S12);
275  }
276 
280  void Direct(real lat1, real lon1, real azi12, real s12,
281  real& lat2, real& lon2) const {
282  real t;
283  GenDirect(lat1, lon1, azi12, s12, LATITUDE | LONGITUDE, lat2, lon2, t);
284  }
285 
313  void GenDirect(real lat1, real lon1, real azi12, real s12,
314  unsigned outmask, real& lat2, real& lon2, real& S12) const;
315 
338  void Inverse(real lat1, real lon1, real lat2, real lon2,
339  real& s12, real& azi12, real& S12) const {
340  GenInverse(lat1, lon1, lat2, lon2,
341  DISTANCE | AZIMUTH | AREA, s12, azi12, S12);
342  }
343 
347  void Inverse(real lat1, real lon1, real lat2, real lon2,
348  real& s12, real& azi12) const {
349  real t;
350  GenInverse(lat1, lon1, lat2, lon2, DISTANCE | AZIMUTH, s12, azi12, t);
351  }
352 
373  void GenInverse(real lat1, real lon1, real lat2, real lon2,
374  unsigned outmask,
375  real& s12, real& azi12, real& S12) const;
376 
392  RhumbLine Line(real lat1, real lon1, real azi12) const;
393 
396 
402  Math::real MajorRadius() const { return _ell.MajorRadius(); }
403 
408  Math::real Flattening() const { return _ell.Flattening(); }
409 
410  Math::real EllipsoidArea() const { return _ell.Area(); }
411 
416  static const Rhumb& WGS84();
417  };
418 
438  private:
439  typedef Math::real real;
440  friend class Rhumb;
441  const Rhumb& _rh;
442  bool _exact;
443  real _lat1, _lon1, _azi12, _salp, _calp, _mu1, _psi1, _r1;
444  RhumbLine& operator=(const RhumbLine&); // copy assignment not allowed
445  RhumbLine(const Rhumb& rh, real lat1, real lon1, real azi12,
446  bool exact);
447  public:
448 
452  enum mask {
457  NONE = Rhumb::NONE,
462  LATITUDE = Rhumb::LATITUDE,
467  LONGITUDE = Rhumb::LONGITUDE,
472  AZIMUTH = Rhumb::AZIMUTH,
477  DISTANCE = Rhumb::DISTANCE,
482  AREA = Rhumb::AREA,
487  LONG_UNROLL = Rhumb::LONG_UNROLL,
492  ALL = Rhumb::ALL,
493  };
494 
512  void Position(real s12, real& lat2, real& lon2, real& S12) const {
513  GenPosition(s12, LATITUDE | LONGITUDE | AREA, lat2, lon2, S12);
514  }
515 
520  void Position(real s12, real& lat2, real& lon2) const {
521  real t;
522  GenPosition(s12, LATITUDE | LONGITUDE, lat2, lon2, t);
523  }
524 
553  void GenPosition(real s12, unsigned outmask,
554  real& lat2, real& lon2, real& S12) const;
555 
558 
563  Math::real Latitude() const { return _lat1; }
564 
568  Math::real Longitude() const { return _lon1; }
569 
573  Math::real Azimuth() const { return _azi12; }
574 
579  Math::real MajorRadius() const { return _rh.MajorRadius(); }
580 
585  Math::real Flattening() const { return _rh.Flattening(); }
586  };
587 
588 } // namespace GeographicLib
589 
590 #endif // GEOGRAPHICLIB_RHUMB_HPP
void Inverse(real lat1, real lon1, real lat2, real lon2, real &s12, real &azi12, real &S12) const
Definition: Rhumb.hpp:338
static real Dasinh(real x, real y)
Definition: Rhumb.hpp:126
#define GEOGRAPHICLIB_EXPORT
Definition: Constants.hpp:91
static real Dgd(real x, real y)
Definition: Rhumb.hpp:133
float real
Definition: datatypes.h:10
Scalar * y
static real Dtan(real x, real y)
Definition: Rhumb.hpp:97
static real Dcosh(real x, real y)
Definition: Rhumb.hpp:121
int n
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
EIGEN_DEVICE_FUNC const CoshReturnType cosh() const
Ellipsoid _ell
Definition: Rhumb.hpp:71
static real Dlog(real x, real y)
Definition: Rhumb.hpp:92
void Position(real s12, real &lat2, real &lon2) const
Definition: Rhumb.hpp:520
Matrix< float, 2, 1 > xy
Definition: LLT_solve.cpp:7
#define GEOGRAPHICLIB_RHUMBAREA_ORDER
Definition: Rhumb.hpp:21
static T atanh(T x)
Definition: Math.hpp:328
Math::real Latitude() const
Definition: Rhumb.hpp:563
static real Dsin(real x, real y)
Definition: Rhumb.hpp:111
Math::real MajorRadius() const
Definition: Rhumb.hpp:402
Array33i a
static T asinh(T x)
Definition: Math.hpp:311
Math::real EllipsoidArea() const
Definition: Rhumb.hpp:410
EIGEN_DEVICE_FUNC const CosReturnType cos() const
static T hypot(T x, T y)
Definition: Math.hpp:243
EIGEN_DEVICE_FUNC const SinhReturnType sinh() const
const Rhumb & _rh
Definition: Rhumb.hpp:441
Math::real MajorRadius() const
Definition: Ellipsoid.hpp:80
Math::real Azimuth() const
Definition: Rhumb.hpp:573
static real gd(real x)
Definition: Rhumb.hpp:78
Math::real Longitude() const
Definition: Rhumb.hpp:568
EIGEN_DEVICE_FUNC const AtanReturnType atan() const
static real Datan(real x, real y)
Definition: Rhumb.hpp:104
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Namespace for GeographicLib.
#define GEOGRAPHICLIB_TRANSVERSEMERCATOR_ORDER
static T degree()
Definition: Math.hpp:216
real Deatanhe(real x, real y) const
Definition: Rhumb.hpp:142
Header for GeographicLib::Ellipsoid class.
Math::real Flattening() const
Definition: Rhumb.hpp:408
Properties of an ellipsoid.
Definition: Ellipsoid.hpp:39
Math::real MajorRadius() const
Definition: Rhumb.hpp:579
static real Dgdinv(real x, real y)
Definition: Rhumb.hpp:138
static T tand(T x)
Definition: Math.hpp:671
Math::real Area() const
Header for GeographicLib::Constants class.
Solve of the direct and inverse rhumb problems.
Definition: Rhumb.hpp:66
void GenInverse(real lat1, real lon1, real lat2, real lon2, unsigned outmask, real &s12, real &azi12, real &, real &, real &, real &, real &S12) const
Definition: Rhumb.hpp:178
void Inverse(real lat1, real lon1, real lat2, real lon2, real &s12, real &azi12) const
Definition: Rhumb.hpp:347
Find a sequence of points on a single rhumb line.
Definition: Rhumb.hpp:437
Math::real Flattening() const
Definition: Rhumb.hpp:585
EIGEN_DEVICE_FUNC const SinReturnType sin() const
void GenDirect(real lat1, real lon1, real azi12, bool, real s12, unsigned outmask, real &lat2, real &lon2, real &, real &, real &, real &, real &, real &S12) const
Definition: Rhumb.hpp:172
static T eatanhe(T x, T es)
Definition: Math.cpp:21
void Direct(real lat1, real lon1, real azi12, real s12, real &lat2, real &lon2) const
Definition: Rhumb.hpp:280
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Math::real Flattening() const
Definition: Ellipsoid.hpp:120
Math::real real
Definition: Rhumb.hpp:68
void Direct(real lat1, real lon1, real azi12, real s12, real &lat2, real &lon2, real &S12) const
Definition: Rhumb.hpp:271
static real Dsinh(real x, real y)
Definition: Rhumb.hpp:116
void Position(real s12, real &lat2, real &lon2, real &S12) const
Definition: Rhumb.hpp:512
Point2 t(10, 10)


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:43:53