Math.cpp
Go to the documentation of this file.
1 
10 #include <GeographicLib/Math.hpp>
11 
12 #if defined(_MSC_VER)
13 // Squelch warnings about constant conditional expressions
14 # pragma warning (disable: 4127)
15 #endif
16 
17 namespace GeographicLib {
18 
19  using namespace std;
20 
21  template<typename T> T Math::eatanhe(T x, T es) {
22  return es > T(0) ? es * atanh(es * x) : -es * atan(es * x);
23  }
24 
25  template<typename T> T Math::taupf(T tau, T es) {
26  T tau1 = hypot(T(1), tau),
27  sig = sinh( eatanhe(tau / tau1, es ) );
28  return hypot(T(1), sig) * tau - sig * tau1;
29  }
30 
31  template<typename T> T Math::tauf(T taup, T es) {
32  static const int numit = 5;
33  static const T tol = sqrt(numeric_limits<T>::epsilon()) / T(10);
34  T e2m = T(1) - sq(es),
35  // To lowest order in e^2, taup = (1 - e^2) * tau = _e2m * tau; so use
36  // tau = taup/_e2m as a starting guess. (This starting guess is the
37  // geocentric latitude which, to first order in the flattening, is equal
38  // to the conformal latitude.) Only 1 iteration is needed for |lat| <
39  // 3.35 deg, otherwise 2 iterations are needed. If, instead, tau = taup
40  // is used the mean number of iterations increases to 1.99 (2 iterations
41  // are needed except near tau = 0).
42  tau = taup/e2m,
43  stol = tol * max(T(1), abs(taup));
44  // min iterations = 1, max iterations = 2; mean = 1.94
45  for (int i = 0; i < numit || GEOGRAPHICLIB_PANIC; ++i) {
46  T taupa = taupf(tau, es),
47  dtau = (taup - taupa) * (1 + e2m * sq(tau)) /
48  ( e2m * hypot(T(1), tau) * hypot(T(1), taupa) );
49  tau += dtau;
50  if (!(abs(dtau) >= stol))
51  break;
52  }
53  return tau;
54  }
55 
57  // Instantiate
58  template Math::real Math::eatanhe<Math::real>(Math::real, Math::real);
59  template Math::real Math::taupf<Math::real>(Math::real, Math::real);
60  template Math::real Math::tauf<Math::real>(Math::real, Math::real);
62 
63 } // namespace GeographicLib
#define max(a, b)
Definition: datatypes.h:20
Definition: BFloat16.h:88
EIGEN_DEVICE_FUNC const SinhReturnType sinh() const
static double epsilon
Definition: testRot3.cpp:37
EIGEN_DEVICE_FUNC const AtanReturnType atan() const
Header for GeographicLib::Math class.
Eigen::Triplet< double > T
Namespace for GeographicLib.
EigenSolver< MatrixXf > es
Jet< T, N > sqrt(const Jet< T, N > &f)
Definition: jet.h:418
static T tauf(T taup, T es)
Definition: Math.cpp:31
const G double tol
Definition: Group.h:86
static T eatanhe(T x, T es)
Definition: Math.cpp:21
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
#define abs(x)
Definition: datatypes.h:17
static T taupf(T tau, T es)
Definition: Math.cpp:25
#define GEOGRAPHICLIB_PANIC
Definition: Math.hpp:87


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:45