LSST Applications g070148d5b3+33e5256705,g0d53e28543+25c8b88941,g0da5cf3356+2dd1178308,g1081da9e2a+62d12e78cb,g17e5ecfddb+7e422d6136,g1c76d35bf8+ede3a706f7,g295839609d+225697d880,g2e2c1a68ba+cc1f6f037e,g2ffcdf413f+853cd4dcde,g38293774b4+62d12e78cb,g3b44f30a73+d953f1ac34,g48ccf36440+885b902d19,g4b2f1765b6+7dedbde6d2,g5320a0a9f6+0c5d6105b6,g56b687f8c9+ede3a706f7,g5c4744a4d9+ef6ac23297,g5ffd174ac0+0c5d6105b6,g6075d09f38+66af417445,g667d525e37+2ced63db88,g670421136f+2ced63db88,g71f27ac40c+2ced63db88,g774830318a+463cbe8d1f,g7876bc68e5+1d137996f1,g7985c39107+62d12e78cb,g7fdac2220c+0fd8241c05,g96f01af41f+368e6903a7,g9ca82378b8+2ced63db88,g9d27549199+ef6ac23297,gabe93b2c52+e3573e3735,gb065e2a02a+3dfbe639da,gbc3249ced9+0c5d6105b6,gbec6a3398f+0c5d6105b6,gc9534b9d65+35b9f25267,gd01420fc67+0c5d6105b6,geee7ff78d7+a14128c129,gf63283c776+ede3a706f7,gfed783d017+0c5d6105b6,w.2022.47
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_
double x
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.