GeographicLib  1.51
JacobiConformal.hpp
Go to the documentation of this file.
1 /**
2  * \file JacobiConformal.hpp
3  * \brief Header for GeographicLib::JacobiConformal class
4  *
5  * <b>NOTE:</b> This is just sample code. It is not part of GeographicLib
6  * itself.
7  *
8  * Copyright (c) Charles Karney (2014-2020) <charles@karney.com> and licensed
9  * under the MIT/X11 License. For more information, see
10  * https://geographiclib.sourceforge.io/
11  **********************************************************************/
12 
14 
15 namespace GeographicLib {
16  /**
17  * \brief Jacobi's conformal projection of a triaxial ellipsoid
18  *
19  * <b>NOTE:</b> This is just sample code. It is not part of GeographicLib
20  * itself.
21  *
22  * This is a conformal projection of the ellipsoid to a plane in which
23  * the grid lines are straight; see Jacobi,
24  * <a href="https://books.google.com/books?id=ryEOAAAAQAAJ&pg=PA212">
25  * Vorlesungen &uuml;ber Dynamik, &sect;28</a>. The constructor takes the
26  * semi-axes of the ellipsoid (which must be in order). Member functions map
27  * the ellipsoidal coordinates &omega; and &beta; separately to \e x and \e
28  * y. Jacobi's coordinates have been multiplied by
29  * (<i>a</i><sup>2</sup>&minus;<i>c</i><sup>2</sup>)<sup>1/2</sup> /
30  * (2<i>b</i>) so that the customary results are returned in the cases of
31  * a sphere or an ellipsoid of revolution.
32  *
33  * The ellipsoid is oriented so that the large principal ellipse, \f$Z=0\f$,
34  * is the equator, \f$\beta=0\f$, while the small principal ellipse,
35  * \f$Y=0\f$, is the prime meridian, \f$\omega=0\f$. The four umbilic
36  * points, \f$\left|\omega\right| = \left|\beta\right| = \frac12\pi\f$, lie
37  * on middle principal ellipse in the plane \f$X=0\f$.
38  *
39  * For more information on this projection, see \ref jacobi.
40  **********************************************************************/
42  typedef Math::real real;
43  real _a, _b, _c, _ab2, _bc2, _ac2;
44  EllipticFunction _ex, _ey;
45  static void norm(real& x, real& y) {
46  using std::hypot;
47  real z = hypot(x, y); x /= z; y /= z;
48  }
49  public:
50  /**
51  * Constructor for a trixial ellipsoid with semi-axes.
52  *
53  * @param[in] a the largest semi-axis.
54  * @param[in] b the middle semi-axis.
55  * @param[in] c the smallest semi-axis.
56  *
57  * The semi-axes must satisfy \e a &ge; \e b &ge; \e c > 0 and \e a >
58  * \e c. This form of the constructor cannot be used to specify a
59  * sphere (use the next constructor).
60  **********************************************************************/
61  JacobiConformal(real a, real b, real c)
62  : _a(a), _b(b), _c(c)
63  , _ab2((_a - _b) * (_a + _b))
64  , _bc2((_b - _c) * (_b + _c))
65  , _ac2((_a - _c) * (_a + _c))
66  , _ex(_ab2 / _ac2 * Math::sq(_c / _b), -_ab2 / Math::sq(_b),
67  _bc2 / _ac2 * Math::sq(_a / _b), Math::sq(_a / _b))
68  , _ey(_bc2 / _ac2 * Math::sq(_a / _b), +_bc2 / Math::sq(_b),
69  _ab2 / _ac2 * Math::sq(_c / _b), Math::sq(_c / _b))
70  {
71  using std::isfinite;
72  if (!(isfinite(_a) && _a >= _b && _b >= _c && _c > 0))
73  throw GeographicErr("JacobiConformal: axes are not in order");
74  if (!(_a > _c))
75  throw GeographicErr
76  ("JacobiConformal: use alternate constructor for sphere");
77  }
78  /**
79  * Alternate constructor for a triaxial ellipsoid.
80  *
81  * @param[in] a the largest semi-axis.
82  * @param[in] b the middle semi-axis.
83  * @param[in] c the smallest semi-axis.
84  * @param[in] ab the relative magnitude of \e a &minus; \e b.
85  * @param[in] bc the relative magnitude of \e b &minus; \e c.
86  *
87  * This form can be used to specify a sphere. The semi-axes must
88  * satisfy \e a &ge; \e b &ge; c > 0. The ratio \e ab : \e bc must equal
89  * (<i>a</i>&minus;<i>b</i>) : (<i>b</i>&minus;<i>c</i>) with \e ab
90  * &ge; 0, \e bc &ge; 0, and \e ab + \e bc > 0.
91  **********************************************************************/
92  JacobiConformal(real a, real b, real c, real ab, real bc)
93  : _a(a), _b(b), _c(c)
94  , _ab2(ab * (_a + _b))
95  , _bc2(bc * (_b + _c))
96  , _ac2(_ab2 + _bc2)
97  , _ex(_ab2 / _ac2 * Math::sq(_c / _b),
98  -(_a - _b) * (_a + _b) / Math::sq(_b),
99  _bc2 / _ac2 * Math::sq(_a / _b), Math::sq(_a / _b))
100  , _ey(_bc2 / _ac2 * Math::sq(_a / _b),
101  +(_b - _c) * (_b + _c) / Math::sq(_b),
102  _ab2 / _ac2 * Math::sq(_c / _b), Math::sq(_c / _b))
103  {
104  using std::isfinite;
105  if (!(isfinite(_a) && _a >= _b && _b >= _c && _c > 0 &&
106  ab >= 0 && bc >= 0))
107  throw GeographicErr("JacobiConformal: axes are not in order");
108  if (!(ab + bc > 0 && isfinite(_ac2)))
109  throw GeographicErr("JacobiConformal: ab + bc must be positive");
110  }
111  /**
112  * @return the quadrant length in the \e x direction.
113  **********************************************************************/
114  Math::real x() const { return Math::sq(_a / _b) * _ex.Pi(); }
115  /**
116  * The \e x projection.
117  *
118  * @param[in] somg sin(&omega;).
119  * @param[in] comg cos(&omega;).
120  * @return \e x.
121  **********************************************************************/
122  Math::real x(real somg, real comg) const {
123  real somg1 = _b * somg, comg1 = _a * comg; norm(somg1, comg1);
124  return Math::sq(_a / _b)
125  * _ex.Pi(somg1, comg1, _ex.Delta(somg1, comg1));
126  }
127  /**
128  * The \e x projection.
129  *
130  * @param[in] omg &omega; (in degrees).
131  * @return \e x (in degrees).
132  *
133  * &omega; must be in (&minus;180&deg;, 180&deg;].
134  **********************************************************************/
135  Math::real x(real omg) const {
136  real somg, comg;
137  Math::sincosd(omg, somg, comg);
138  return x(somg, comg) / Math::degree();
139  }
140  /**
141  * @return the quadrant length in the \e y direction.
142  **********************************************************************/
143  Math::real y() const { return Math::sq(_c / _b) * _ey.Pi(); }
144  /**
145  * The \e y projection.
146  *
147  * @param[in] sbet sin(&beta;).
148  * @param[in] cbet cos(&beta;).
149  * @return \e y.
150  **********************************************************************/
151  Math::real y(real sbet, real cbet) const {
152  real sbet1 = _b * sbet, cbet1 = _c * cbet; norm(sbet1, cbet1);
153  return Math::sq(_c / _b)
154  * _ey.Pi(sbet1, cbet1, _ey.Delta(sbet1, cbet1));
155  }
156  /**
157  * The \e y projection.
158  *
159  * @param[in] bet &beta; (in degrees).
160  * @return \e y (in degrees).
161  *
162  * &beta; must be in (&minus;180&deg;, 180&deg;].
163  **********************************************************************/
164  Math::real y(real bet) const {
165  real sbet, cbet;
166  Math::sincosd(bet, sbet, cbet);
167  return y(sbet, cbet) / Math::degree();
168  }
169  };
170 
171 } // namespace GeographicLib
JacobiConformal(real a, real b, real c, real ab, real bc)
Mathematical functions needed by GeographicLib.
Definition: Math.hpp:76
Elliptic integrals and functions.
Math::real y(real bet) const
JacobiConformal(real a, real b, real c)
Math::real y(real sbet, real cbet) const
static T sq(T x)
Definition: Math.hpp:171
Namespace for GeographicLib.
Definition: Accumulator.cpp:12
Jacobi&#39;s conformal projection of a triaxial ellipsoid.
Header for GeographicLib::EllipticFunction class.
static T degree()
Definition: Math.hpp:159
Math::real x(real omg) const
Math::real x(real somg, real comg) const
Exception handling for GeographicLib.
Definition: Constants.hpp:315
Math::real Delta(real sn, real cn) const
static void sincosd(T x, T &sinx, T &cosx)
Definition: Math.cpp:126