GeographicLib 2.2
AuxAngle.cpp
Go to the documentation of this file.
1/**
2 * \file AuxAngle.cpp
3 * \brief Implementation for the GeographicLib::AuxAngle class.
4 *
5 * \note This is just sample code. It is not part of GeographicLib itself.
6 *
7 * This file is an implementation of the methods described in
8 * - C. F. F. Karney,
9 * On auxiliary latitudes,
10 * Technical Report, SRI International, December 2022.
11 * https://arxiv.org/abs/2212.05818
12 * .
13 * Copyright (c) Charles Karney (2022-2023) <charles@karney.com> and licensed
14 * under the MIT/X11 License. For more information, see
15 * https://geographiclib.sourceforge.io/
16 **********************************************************************/
17
19
20namespace GeographicLib {
21
22 using namespace std;
23
25 return AuxAngle(numeric_limits<real>::quiet_NaN(),
26 numeric_limits<real>::quiet_NaN());
27 }
28
30 using std::isnan; // Needed for Centos 7, ubuntu 14
31 if ( isnan( tan() ) ||
32 (fabs(_y) > numeric_limits<real>::max()/2 &&
33 fabs(_x) > numeric_limits<real>::max()/2) )
34 // deal with
35 // (0,0), (inf,inf), (nan,nan), (nan,x), (y,nan), (toobig,toobig)
36 return NaN();
37 real r = hypot(_y, _x),
38 y = _y/r, x = _x/r;
39 // deal with r = inf, then one of y,x becomes 1
40 if (isnan(y)) y = copysign(real(1), _y);
41 if (isnan(x)) x = copysign(real(1), _x);
42 return AuxAngle(y, x);
43 }
44
46 return AuxAngle(copysign(y(), p.y()), copysign(x(), p.x()));
47 }
48
50 // Do nothing if p.tan() == 0 to preserve signs of y() and x()
51 if (p.tan() != 0) {
52 real x = _x * p._x - _y * p._y;
53 _y = _y * p._x + _x * p._y;
54 _x = x;
55 }
56 return *this;
57 }
58
59} // namespace GeographicLib
Header for the GeographicLib::AuxAngle class.
An accurate representation of angles.
Definition: AuxAngle.hpp:43
Math::real y() const
Definition: AuxAngle.hpp:66
Math::real x() const
Definition: AuxAngle.hpp:71
AuxAngle normalized() const
Definition: AuxAngle.cpp:29
AuxAngle & operator+=(const AuxAngle &p)
Definition: AuxAngle.cpp:49
static AuxAngle NaN()
Definition: AuxAngle.cpp:24
Math::real tan() const
Definition: AuxAngle.hpp:109
AuxAngle copyquadrant(const AuxAngle &p) const
Definition: AuxAngle.cpp:45
AuxAngle(real y=0, real x=1)
Definition: AuxAngle.hpp:61
Namespace for GeographicLib.
Definition: Accumulator.cpp:12