GeographicLib  1.38
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PolarStereographic.hpp
Go to the documentation of this file.
1 /**
2  * \file PolarStereographic.hpp
3  * \brief Header for GeographicLib::PolarStereographic class
4  *
5  * Copyright (c) Charles Karney (2008-2014) <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_POLARSTEREOGRAPHIC_HPP)
11 #define GEOGRAPHICLIB_POLARSTEREOGRAPHIC_HPP 1
12 
14 
15 namespace GeographicLib {
16 
17  /**
18  * \brief Polar stereographic projection
19  *
20  * Implementation taken from the report,
21  * - J. P. Snyder,
22  * <a href="http://pubs.er.usgs.gov/usgspubs/pp/pp1395"> Map Projections: A
23  * Working Manual</a>, USGS Professional Paper 1395 (1987),
24  * pp. 160--163.
25  *
26  * This is a straightforward implementation of the equations in Snyder except
27  * that Newton's method is used to invert the projection.
28  *
29  * Example of use:
30  * \include example-PolarStereographic.cpp
31  **********************************************************************/
33  private:
34  typedef Math::real real;
35  real tol_;
36  // _Cx used to be _C but g++ 3.4 has a macro of that name
37  real _a, _f, _e2, _e, _e2m, _Cx, _c;
38  real _k0;
39  static const int numit_ = 5;
40  static inline real overflow() {
41  // Overflow value s.t. atan(overflow_) = pi/2
42  static const real
43  overflow = 1 / Math::sq(std::numeric_limits<real>::epsilon());
44  return overflow;
45  }
46  // tan(x) for x in [-pi/2, pi/2] ensuring that the sign is right
47  static inline real tanx(real x) {
48  using std::tan;
49  real t = tan(x);
50  // Write the tests this way to ensure that tanx(NaN()) is NaN()
51  return x >= 0 ?
52  (!(t < 0) ? t : overflow()) :
53  (!(t >= 0) ? t : -overflow());
54  }
55  // Return e * atanh(e * x) for f >= 0, else return
56  // - sqrt(-e2) * atan( sqrt(-e2) * x) for f < 0
57  inline real eatanhe(real x) const {
58  using std::atan;
59  return _f >= 0 ? _e * Math::atanh(_e * x) : - _e * atan(_e * x);
60  }
61  public:
62 
63  /**
64  * Constructor for a ellipsoid with
65  *
66  * @param[in] a equatorial radius (meters).
67  * @param[in] f flattening of ellipsoid. Setting \e f = 0 gives a sphere.
68  * Negative \e f gives a prolate ellipsoid. If \e f &gt; 1, set
69  * flattening to 1/\e f.
70  * @param[in] k0 central scale factor.
71  * @exception GeographicErr if \e a, (1 &minus; \e f) \e a, or \e k0 is
72  * not positive.
73  **********************************************************************/
74  PolarStereographic(real a, real f, real k0);
75 
76  /**
77  * Set the scale for the projection.
78  *
79  * @param[in] lat (degrees) assuming \e northp = true.
80  * @param[in] k scale at latitude \e lat (default 1).
81  * @exception GeographicErr \e k is not positive.
82  * @exception GeographicErr if \e lat is not in (&minus;90&deg;,
83  * 90&deg;].
84  **********************************************************************/
85  void SetScale(real lat, real k = real(1));
86 
87  /**
88  * Forward projection, from geographic to polar stereographic.
89  *
90  * @param[in] northp the pole which is the center of projection (true means
91  * north, false means south).
92  * @param[in] lat latitude of point (degrees).
93  * @param[in] lon longitude of point (degrees).
94  * @param[out] x easting of point (meters).
95  * @param[out] y northing of point (meters).
96  * @param[out] gamma meridian convergence at point (degrees).
97  * @param[out] k scale of projection at point.
98  *
99  * No false easting or northing is added. \e lat should be in the range
100  * (&minus;90&deg;, 90&deg;] for \e northp = true and in the range
101  * [&minus;90&deg;, 90&deg;) for \e northp = false; \e lon should
102  * be in the range [&minus;540&deg;, 540&deg;).
103  **********************************************************************/
104  void Forward(bool northp, real lat, real lon,
105  real& x, real& y, real& gamma, real& k) const;
106 
107  /**
108  * Reverse projection, from polar stereographic to geographic.
109  *
110  * @param[in] northp the pole which is the center of projection (true means
111  * north, false means south).
112  * @param[in] x easting of point (meters).
113  * @param[in] y northing of point (meters).
114  * @param[out] lat latitude of point (degrees).
115  * @param[out] lon longitude of point (degrees).
116  * @param[out] gamma meridian convergence at point (degrees).
117  * @param[out] k scale of projection at point.
118  *
119  * No false easting or northing is added. The value of \e lon returned is
120  * in the range [&minus;180&deg;, 180&deg;).
121  **********************************************************************/
122  void Reverse(bool northp, real x, real y,
123  real& lat, real& lon, real& gamma, real& k) const;
124 
125  /**
126  * PolarStereographic::Forward without returning the convergence and scale.
127  **********************************************************************/
128  void Forward(bool northp, real lat, real lon,
129  real& x, real& y) const {
130  real gamma, k;
131  Forward(northp, lat, lon, x, y, gamma, k);
132  }
133 
134  /**
135  * PolarStereographic::Reverse without returning the convergence and scale.
136  **********************************************************************/
137  void Reverse(bool northp, real x, real y,
138  real& lat, real& lon) const {
139  real gamma, k;
140  Reverse(northp, x, y, lat, lon, gamma, k);
141  }
142 
143  /** \name Inspector functions
144  **********************************************************************/
145  ///@{
146  /**
147  * @return \e a the equatorial radius of the ellipsoid (meters). This is
148  * the value used in the constructor.
149  **********************************************************************/
150  Math::real MajorRadius() const { return _a; }
151 
152  /**
153  * @return \e f the flattening of the ellipsoid. This is the value used in
154  * the constructor.
155  **********************************************************************/
156  Math::real Flattening() const { return _f; }
157 
158  /// \cond SKIP
159  /**
160  * <b>DEPRECATED</b>
161  * @return \e r the inverse flattening of the ellipsoid.
162  **********************************************************************/
163  Math::real InverseFlattening() const { return 1/_f; }
164  /// \endcond
165 
166  /**
167  * The central scale for the projection. This is the value of \e k0 used
168  * in the constructor and is the scale at the pole unless overridden by
169  * PolarStereographic::SetScale.
170  **********************************************************************/
171  Math::real CentralScale() const { return _k0; }
172  ///@}
173 
174  /**
175  * A global instantiation of PolarStereographic with the WGS84 ellipsoid
176  * and the UPS scale factor. However, unlike UPS, no false easting or
177  * northing is added.
178  **********************************************************************/
179  static const PolarStereographic& UPS();
180  };
181 
182 } // namespace GeographicLib
183 
184 #endif // GEOGRAPHICLIB_POLARSTEREOGRAPHIC_HPP
void Reverse(bool northp, real x, real y, real &lat, real &lon) const
#define GEOGRAPHICLIB_EXPORT
Definition: Constants.hpp:70
GeographicLib::Math::real real
Definition: GeodSolve.cpp:40
static T atanh(T x)
Definition: Math.hpp:339
static T sq(T x)
Definition: Math.hpp:243
void Forward(bool northp, real lat, real lon, real &x, real &y) const
Namespace for GeographicLib.
Definition: Accumulator.cpp:12
Polar stereographic projection.
Header for GeographicLib::Constants class.