LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Member Functions | Static Public Member Functions | List of all members
lsst::sphgeom::NormalizedAngle Class Reference

NormalizedAngle is an angle that lies in the range [0, 2π), with one exception - a NormalizedAngle can be NaN. More...

#include <NormalizedAngle.h>

Public Member Functions

 NormalizedAngle ()=default
 This constructor creates a NormalizedAngle with a value of zero. More...
 
 NormalizedAngle (NormalizedAngle const &a)=default
 This constructor creates a copy of a. More...
 
 NormalizedAngle (Angle const &a)
 This constructor creates a normalized copy of a. More...
 
 NormalizedAngle (double a)
 This constructor creates a NormalizedAngle with the given value in radians, normalized to be in the range [0, 2π). More...
 
 NormalizedAngle (LonLat const &, LonLat const &)
 This constructor creates a NormalizedAngle equal to the angle between the given points on the unit sphere. More...
 
 NormalizedAngle (Vector3d const &, Vector3d const &)
 This constructor creates a NormalizedAngle equal to the angle between the given 3-vectors, which need not have unit norm. More...
 
 operator Angle const & () const
 This conversion operator returns a const reference to the underlying Angle. More...
 
bool operator== (Angle const &a) const
 
bool operator!= (Angle const &a) const
 
bool operator< (Angle const &a) const
 
bool operator> (Angle const &a) const
 
bool operator<= (Angle const &a) const
 
bool operator>= (Angle const &a) const
 
Angle operator- () const
 
Angle operator+ (Angle const &a) const
 
Angle operator- (Angle const &a) const
 
Angle operator* (double a) const
 
Angle operator/ (double a) const
 
double operator/ (Angle const &a) const
 
double asDegrees () const
 asDegrees returns the value of this angle in units of degrees. More...
 
double asRadians () const
 asRadians returns the value of this angle in units of radians. More...
 
bool isNan () const
 isNan returns true if the angle value is NaN. More...
 
NormalizedAngle getAngleTo (NormalizedAngle const &a) const
 getAngleTo computes the angle α ∈ [0, 2π) such that adding α to this angle and then normalizing the result yields a. More...
 

Static Public Member Functions

static NormalizedAngle nan ()
 
static NormalizedAngle fromDegrees (double a)
 
static NormalizedAngle fromRadians (double a)
 
static NormalizedAngle between (NormalizedAngle const &a, NormalizedAngle const &b)
 For two angles a and b, between(a, b) returns the smaller of a.getAngleTo(b) and b.getAngleTo(a). More...
 
static NormalizedAngle center (NormalizedAngle const &a, NormalizedAngle const &b)
 For two normalized angles a and b, center(a, b) returns the angle m such that a.getAngleTo(m) is equal to m.getAngleTo(b). More...
 

Detailed Description

NormalizedAngle is an angle that lies in the range [0, 2π), with one exception - a NormalizedAngle can be NaN.

Definition at line 43 of file NormalizedAngle.h.

Constructor & Destructor Documentation

◆ NormalizedAngle() [1/6]

lsst::sphgeom::NormalizedAngle::NormalizedAngle ( )
default

This constructor creates a NormalizedAngle with a value of zero.

◆ NormalizedAngle() [2/6]

lsst::sphgeom::NormalizedAngle::NormalizedAngle ( NormalizedAngle const &  a)
default

This constructor creates a copy of a.

◆ NormalizedAngle() [3/6]

lsst::sphgeom::NormalizedAngle::NormalizedAngle ( Angle const &  a)
inlineexplicit

This constructor creates a normalized copy of a.

Definition at line 79 of file NormalizedAngle.h.

79  {
80  *this = NormalizedAngle(a.asRadians());
81  }
table::Key< int > a
NormalizedAngle()=default
This constructor creates a NormalizedAngle with a value of zero.

◆ NormalizedAngle() [4/6]

lsst::sphgeom::NormalizedAngle::NormalizedAngle ( double  a)
inlineexplicit

This constructor creates a NormalizedAngle with the given value in radians, normalized to be in the range [0, 2π).

Definition at line 85 of file NormalizedAngle.h.

85  {
86  // For really large |a|, the error in this reduction can exceed 2*PI
87  // (because PI is only an approximation to π).
88  if (a < 0.0) {
89  _a = Angle(std::fmod(a, 2.0 * PI) + 2.0 * PI);
90  } else if (a > 2 * PI) {
91  _a = Angle(std::fmod(a, 2.0 * PI));
92  } else {
93  _a = Angle(a);
94  }
95  }
T fmod(T... args)
lsst::geom::Angle Angle
Definition: misc.h:33
constexpr double PI
Definition: constants.h:36

◆ NormalizedAngle() [5/6]

lsst::sphgeom::NormalizedAngle::NormalizedAngle ( LonLat const &  p1,
LonLat const &  p2 
)

This constructor creates a NormalizedAngle equal to the angle between the given points on the unit sphere.

Definition at line 59 of file NormalizedAngle.cc.

59  {
60  double x = sin((p1.getLon() - p2.getLon()) * 0.5);
61  x *= x;
62  double y = sin((p1.getLat() - p2.getLat()) * 0.5);
63  y *= y;
64  double z = cos((p1.getLat() + p2.getLat()) * 0.5);
65  z *= z;
66  // Compute the square of the sine of half of the desired angle. This is
67  // easily shown to be be one fourth of the squared Euclidian distance
68  // (chord length) between p1 and p2.
69  double sha2 = (x * (z - y) + y);
70  // Avoid domain errors in asin and sqrt due to rounding errors.
71  if (sha2 < 0.0) {
72  _a = Angle(0.0);
73  } else if (sha2 >= 1.0) {
74  _a = Angle(PI);
75  } else {
76  _a = Angle(2.0 * std::asin(std::sqrt(sha2)));
77  }
78 }
double x
double z
Definition: Match.cc:44
int y
Definition: SpanSet.cc:48
T asin(T... args)
double sin(Angle const &a)
Definition: Angle.h:102
double cos(Angle const &a)
Definition: Angle.h:103
T sqrt(T... args)

◆ NormalizedAngle() [6/6]

lsst::sphgeom::NormalizedAngle::NormalizedAngle ( Vector3d const &  v1,
Vector3d const &  v2 
)

This constructor creates a NormalizedAngle equal to the angle between the given 3-vectors, which need not have unit norm.

Definition at line 80 of file NormalizedAngle.cc.

80  {
81  double s = v1.cross(v2).getNorm();
82  double c = v1.dot(v2);
83  if (s == 0.0 && c == 0.0) {
84  // Avoid the atan2(±0, -0) = ±PI special case.
85  _a = Angle(0.0);
86  } else {
87  _a = Angle(std::atan2(s, c));
88  }
89 }
T atan2(T... args)

Member Function Documentation

◆ asDegrees()

double lsst::sphgeom::NormalizedAngle::asDegrees ( ) const
inline

asDegrees returns the value of this angle in units of degrees.

Definition at line 127 of file NormalizedAngle.h.

127 { return _a.asDegrees(); }
double asDegrees() const
asDegrees returns the value of this angle in units of degrees.
Definition: Angle.h:82

◆ asRadians()

double lsst::sphgeom::NormalizedAngle::asRadians ( ) const
inline

asRadians returns the value of this angle in units of radians.

Definition at line 130 of file NormalizedAngle.h.

130 { return _a.asRadians(); }
double asRadians() const
asRadians returns the value of this angle in units of radians.
Definition: Angle.h:85

◆ between()

NormalizedAngle lsst::sphgeom::NormalizedAngle::between ( NormalizedAngle const &  a,
NormalizedAngle const &  b 
)
static

For two angles a and b, between(a, b) returns the smaller of a.getAngleTo(b) and b.getAngleTo(a).

The result will be in the range [0, π].

If one interprets an angle in [0, 2π) as a point on the unit circle, then between can be thought of as computing the arc length of the shortest unit circle segment between the points for a and b.

Definition at line 35 of file NormalizedAngle.cc.

37 {
39  double a1 = std::fabs(a.asRadians() - b.asRadians());
40  double a2 = 2.0 * PI - a1;
41  x._a = Angle(std::min(a1, a2));
42  return x;
43 }
table::Key< int > b
T fabs(T... args)
T min(T... args)

◆ center()

NormalizedAngle lsst::sphgeom::NormalizedAngle::center ( NormalizedAngle const &  a,
NormalizedAngle const &  b 
)
static

For two normalized angles a and b, center(a, b) returns the angle m such that a.getAngleTo(m) is equal to m.getAngleTo(b).

Definition at line 45 of file NormalizedAngle.cc.

47 {
49  double c = 0.5 * (a.asRadians() + b.asRadians());
50  if (a <= b) {
51  x._a = Angle(c);
52  } else {
53  // The result is (a + b + 2π) / 2, normalized to [0, 2π)
54  x._a = Angle((c < PI) ? (c + PI) : (c - PI));
55  }
56  return x;
57 }

◆ fromDegrees()

static NormalizedAngle lsst::sphgeom::NormalizedAngle::fromDegrees ( double  a)
inlinestatic

Definition at line 49 of file NormalizedAngle.h.

49  {
50  return NormalizedAngle(a * RAD_PER_DEG);
51  }
constexpr double RAD_PER_DEG
Definition: constants.h:38

◆ fromRadians()

static NormalizedAngle lsst::sphgeom::NormalizedAngle::fromRadians ( double  a)
inlinestatic

Definition at line 53 of file NormalizedAngle.h.

53  {
54  return NormalizedAngle(a);
55  }

◆ getAngleTo()

NormalizedAngle lsst::sphgeom::NormalizedAngle::getAngleTo ( NormalizedAngle const &  a) const
inline

getAngleTo computes the angle α ∈ [0, 2π) such that adding α to this angle and then normalizing the result yields a.

If one interprets an angle in [0, 2π) as a point on the unit circle, then this method can be thought of as computing the positive rotation angle required to map this point to a.

Definition at line 141 of file NormalizedAngle.h.

141  {
143  double d = a.asRadians() - asRadians();
144  x._a = Angle((d < 0.0) ? 2.0 * PI + d : d);
145  return x;
146  }
double asRadians() const
asRadians returns the value of this angle in units of radians.

◆ isNan()

bool lsst::sphgeom::NormalizedAngle::isNan ( ) const
inline

isNan returns true if the angle value is NaN.

Definition at line 133 of file NormalizedAngle.h.

133 { return _a.isNan(); }
bool isNan() const
isNan returns true if the angle value is NaN.
Definition: Angle.h:91

◆ nan()

static NormalizedAngle lsst::sphgeom::NormalizedAngle::nan ( )
inlinestatic

Definition at line 45 of file NormalizedAngle.h.

◆ operator Angle const &()

lsst::sphgeom::NormalizedAngle::operator Angle const & ( ) const
inline

This conversion operator returns a const reference to the underlying Angle.

It allows a NormalizedAngle to transparently replace an Angle as an argument in most function calls.

Definition at line 108 of file NormalizedAngle.h.

108 { return _a; }

◆ operator!=()

bool lsst::sphgeom::NormalizedAngle::operator!= ( Angle const &  a) const
inline

Definition at line 112 of file NormalizedAngle.h.

112 { return _a != a; }

◆ operator*()

Angle lsst::sphgeom::NormalizedAngle::operator* ( double  a) const
inline

Definition at line 122 of file NormalizedAngle.h.

122 { return _a * a; }

◆ operator+()

Angle lsst::sphgeom::NormalizedAngle::operator+ ( Angle const &  a) const
inline

Definition at line 120 of file NormalizedAngle.h.

120 { return _a + a; }

◆ operator-() [1/2]

Angle lsst::sphgeom::NormalizedAngle::operator- ( ) const
inline

Definition at line 119 of file NormalizedAngle.h.

119 { return Angle(-_a); }

◆ operator-() [2/2]

Angle lsst::sphgeom::NormalizedAngle::operator- ( Angle const &  a) const
inline

Definition at line 121 of file NormalizedAngle.h.

121 { return _a - a; }

◆ operator/() [1/2]

double lsst::sphgeom::NormalizedAngle::operator/ ( Angle const &  a) const
inline

Definition at line 124 of file NormalizedAngle.h.

124 { return _a / a; }

◆ operator/() [2/2]

Angle lsst::sphgeom::NormalizedAngle::operator/ ( double  a) const
inline

Definition at line 123 of file NormalizedAngle.h.

123 { return _a / a; }

◆ operator<()

bool lsst::sphgeom::NormalizedAngle::operator< ( Angle const &  a) const
inline

Definition at line 113 of file NormalizedAngle.h.

113 { return _a < a; }

◆ operator<=()

bool lsst::sphgeom::NormalizedAngle::operator<= ( Angle const &  a) const
inline

Definition at line 115 of file NormalizedAngle.h.

115 { return _a <= a; }

◆ operator==()

bool lsst::sphgeom::NormalizedAngle::operator== ( Angle const &  a) const
inline

Definition at line 111 of file NormalizedAngle.h.

111 { return _a == a; }

◆ operator>()

bool lsst::sphgeom::NormalizedAngle::operator> ( Angle const &  a) const
inline

Definition at line 114 of file NormalizedAngle.h.

114 { return _a > a; }

◆ operator>=()

bool lsst::sphgeom::NormalizedAngle::operator>= ( Angle const &  a) const
inline

Definition at line 116 of file NormalizedAngle.h.

116 { return _a >= a; }

The documentation for this class was generated from the following files: