LSST Applications 26.0.0,g0265f82a02+6660c170cc,g07994bdeae+30b05a742e,g0a0026dc87+17526d298f,g0a60f58ba1+17526d298f,g0e4bf8285c+96dd2c2ea9,g0ecae5effc+c266a536c8,g1e7d6db67d+6f7cb1f4bb,g26482f50c6+6346c0633c,g2bbee38e9b+6660c170cc,g2cc88a2952+0a4e78cd49,g3273194fdb+f6908454ef,g337abbeb29+6660c170cc,g337c41fc51+9a8f8f0815,g37c6e7c3d5+7bbafe9d37,g44018dc512+6660c170cc,g4a941329ef+4f7594a38e,g4c90b7bd52+5145c320d2,g58be5f913a+bea990ba40,g635b316a6c+8d6b3a3e56,g67924a670a+bfead8c487,g6ae5381d9b+81bc2a20b4,g93c4d6e787+26b17396bd,g98cecbdb62+ed2cb6d659,g98ffbb4407+81bc2a20b4,g9ddcbc5298+7f7571301f,ga1e77700b3+99e9273977,gae46bcf261+6660c170cc,gb2715bf1a1+17526d298f,gc86a011abf+17526d298f,gcf0d15dbbd+96dd2c2ea9,gdaeeff99f8+0d8dbea60f,gdb4ec4c597+6660c170cc,ge23793e450+96dd2c2ea9,gf041782ebf+171108ac67
LSST Data Management Base Package
Loading...
Searching...
No Matches
NormalizedAngle.h
Go to the documentation of this file.
1/*
2 * LSST Data Management System
3 * Copyright 2014-2015 AURA/LSST.
4 *
5 * This product includes software developed by the
6 * LSST Project (http://www.lsst.org/).
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the LSST License Statement and
19 * the GNU General Public License along with this program. If not,
20 * see <https://www.lsstcorp.org/LegalNotices/>.
21 */
22
23#ifndef LSST_SPHGEOM_NORMALIZEDANGLE_H_
24#define LSST_SPHGEOM_NORMALIZEDANGLE_H_
25
28
29#include <limits>
30
31#include "Angle.h"
32
33
34namespace lsst {
35namespace sphgeom {
36
37// Forward declarations
38class LonLat;
39class Vector3d;
40
44public:
47 }
48
49 static NormalizedAngle fromDegrees(double a) {
51 }
52
53 static NormalizedAngle fromRadians(double a) {
54 return NormalizedAngle(a);
55 }
56
65 NormalizedAngle const & b);
66
70 NormalizedAngle const & b);
71
73 NormalizedAngle() = default;
74
76 NormalizedAngle(NormalizedAngle const & a) = default;
77
79 explicit NormalizedAngle(Angle const & a) {
80 *this = NormalizedAngle(a.asRadians());
81 }
82
85 explicit NormalizedAngle(double a) {
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 }
96
99 NormalizedAngle(LonLat const &, LonLat const &);
100
103 NormalizedAngle(Vector3d const &, Vector3d const &);
104
108 operator Angle const & () const { return _a; }
109
110 // Comparison operators
111 bool operator==(Angle const & a) const { return _a == a; }
112 bool operator!=(Angle const & a) const { return _a != a; }
113 bool operator<(Angle const & a) const { return _a < a; }
114 bool operator>(Angle const & a) const { return _a > a; }
115 bool operator<=(Angle const & a) const { return _a <= a; }
116 bool operator>=(Angle const & a) const { return _a >= a; }
117
118 // Arithmetic operators
119 Angle operator-() const { return Angle(-_a); }
120 Angle operator+(Angle const & a) const { return _a + a; }
121 Angle operator-(Angle const & a) const { return _a - a; }
122 Angle operator*(double a) const { return _a * a; }
123 Angle operator/(double a) const { return _a / a; }
124 double operator/(Angle const & a) const { return _a / a; }
125
127 double asDegrees() const { return _a.asDegrees(); }
128
130 double asRadians() const { return _a.asRadians(); }
131
133 bool isNan() const { return _a.isNan(); }
134
143 double d = a.asRadians() - asRadians();
144 x._a = Angle((d < 0.0) ? 2.0 * PI + d : d);
145 return x;
146 }
147
148private:
149 Angle _a;
150};
151
152inline NormalizedAngle const & abs(NormalizedAngle const & a) { return a; }
153
154}} // namespace lsst::sphgeom
155
156#endif // LSST_SPHGEOM_NORMALIZEDANGLE_H_
table::Key< int > b
table::Key< int > a
Angle represents an angle in radians.
Definition Angle.h:43
bool isNan() const
isNan returns true if the angle value is NaN.
Definition Angle.h:91
double asDegrees() const
asDegrees returns the value of this angle in units of degrees.
Definition Angle.h:82
double asRadians() const
asRadians returns the value of this angle in units of radians.
Definition Angle.h:85
LonLat represents a spherical coordinate (longitude/latitude angle) pair.
Definition LonLat.h:48
NormalizedAngle is an angle that lies in the range [0, 2π), with one exception - a NormalizedAngle ca...
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 isNan() const
isNan returns true if the angle value is NaN.
NormalizedAngle(double a)
This constructor creates a NormalizedAngle with the given value in radians, normalized to be in the r...
double asRadians() const
asRadians returns the value of this angle in units of radians.
NormalizedAngle getAngleTo(NormalizedAngle const &a) const
getAngleTo computes the angle α ∈ [0, 2π) such that adding α to this angle and then normalizing the r...
static NormalizedAngle fromRadians(double a)
bool operator>(Angle const &a) const
NormalizedAngle(Angle const &a)
This constructor creates a normalized copy of a.
static NormalizedAngle nan()
Angle operator/(double a) const
Angle operator-(Angle const &a) const
NormalizedAngle()=default
This constructor creates a NormalizedAngle with a value of zero.
Angle operator+(Angle const &a) const
double asDegrees() const
asDegrees returns the value of this angle in units of degrees.
static NormalizedAngle fromDegrees(double a)
double operator/(Angle const &a) const
bool operator<(Angle const &a) const
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....
Angle operator*(double a) const
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 equa...
NormalizedAngle(NormalizedAngle const &a)=default
This constructor creates a copy of a.
Vector3d is a vector in ℝ³ with components stored in double precision.
Definition Vector3d.h:44
T fmod(T... args)
Angle abs(Angle const &a)
Definition Angle.h:106
constexpr double RAD_PER_DEG
Definition constants.h:38
constexpr double PI
Definition constants.h:36
This file declares a class for representing angles.