Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
AngularSpeed.hpp
Go to the documentation of this file.
1 // Copyright © 2020-2024 Alexandre Coderre-Chabot
2 //
3 // This file is part of Physical Quantities (PhQ), a C++ library of physical quantities, physical
4 // models, and units of measure for scientific computing.
5 //
6 // Physical Quantities is hosted at:
7 // https://github.com/acodcha/phq
8 //
9 // Physical Quantities is licensed under the MIT License:
10 // https://mit-license.org
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
13 // associated documentation files (the "Software"), to deal in the Software without restriction,
14 // including without limitation the rights to use, copy, modify, merge, publish, distribute,
15 // sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
16 // furnished to do so, subject to the following conditions:
17 // - The above copyright notice and this permission notice shall be included in all copies or
18 // substantial portions of the Software.
19 // - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
20 // BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
22 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 
25 #ifndef PHQ_ANGULAR_SPEED_HPP
26 #define PHQ_ANGULAR_SPEED_HPP
27 
28 #include <cstddef>
29 #include <functional>
30 #include <ostream>
31 
32 #include "Angle.hpp"
33 #include "DimensionalScalar.hpp"
34 #include "Frequency.hpp"
35 #include "Time.hpp"
36 #include "Unit/AngularSpeed.hpp"
37 
38 namespace PhQ {
39 
40 // Forward declaration for class PhQ::AngularSpeed.
41 template <typename NumericType>
42 class ScalarAngularAcceleration;
43 
44 /// @brief Angular speed, also known as angular rate or angular frequency. Represents the time rate
45 /// of change of an angle; see also PhQ::Angle, PhQ::ScalarAngularAcceleration, PhQ::Time, and
46 /// PhQ::Frequency. Can also represent a component or the magnitude of an angular velocity
47 /// pseudovector.
48 template <typename NumericType = double>
49 class AngularSpeed : public DimensionalScalar<Unit::AngularSpeed, NumericType> {
50 public:
51  /// \brief Default constructor. Constructs an angular speed with an uninitialized value.
52  AngularSpeed() = default;
53 
54  /// \brief Constructor. Constructs an angular speed with a given value expressed in a given
55  /// angular speed unit.
56  AngularSpeed(const NumericType value, const Unit::AngularSpeed unit)
57  : DimensionalScalar<Unit::AngularSpeed, NumericType>(value, unit) {}
58 
59  /// \brief Constructor. Constructs an angular speed from a given angle and time using the
60  /// definition of angular speed.
61  constexpr AngularSpeed(const Angle<NumericType>& angle, const Time<NumericType>& time)
62  : AngularSpeed<NumericType>(angle.Value() / time.Value()) {}
63 
64  /// \brief Constructor. Constructs an angular speed from a given angle and frequency using the
65  /// definition of angular speed.
66  constexpr AngularSpeed(const Angle<NumericType>& angle, const Frequency<NumericType>& frequency)
67  : AngularSpeed<NumericType>(angle.Value() * frequency.Value()) {}
68 
69  /// \brief Constructor. Constructs an angular speed from a given scalar angular acceleration and
70  /// time using the definition of angular acceleration.
71  constexpr AngularSpeed(const ScalarAngularAcceleration<NumericType>& scalar_angular_acceleration,
72  const Time<NumericType>& time);
73 
74  /// \brief Constructor. Constructs an angular speed from a given scalar angular acceleration and
75  /// frequency using the definition of angular acceleration.
76  constexpr AngularSpeed(const ScalarAngularAcceleration<NumericType>& scalar_angular_acceleration,
77  const Frequency<NumericType>& frequency);
78 
79  /// \brief Destructor. Destroys this angular speed.
80  ~AngularSpeed() noexcept = default;
81 
82  /// \brief Copy constructor. Constructs an angular speed by copying another one.
83  constexpr AngularSpeed(const AngularSpeed<NumericType>& other) = default;
84 
85  /// \brief Copy constructor. Constructs an angular speed by copying another one.
86  template <typename OtherNumericType>
87  explicit constexpr AngularSpeed(const AngularSpeed<OtherNumericType>& other)
88  : AngularSpeed(static_cast<NumericType>(other.Value())) {}
89 
90  /// \brief Move constructor. Constructs an angular speed by moving another one.
91  constexpr AngularSpeed(AngularSpeed<NumericType>&& other) noexcept = default;
92 
93  /// \brief Copy assignment operator. Assigns this angular speed by copying another one.
95 
96  /// \brief Copy assignment operator. Assigns this angular speed by copying another one.
97  template <typename OtherNumericType>
99  this->value = static_cast<NumericType>(other.Value());
100  return *this;
101  }
102 
103  /// \brief Move assignment operator. Assigns this angular speed by moving another one.
105  AngularSpeed<NumericType>&& other) noexcept = default;
106 
107  /// \brief Statically creates an angular speed of zero.
108  [[nodiscard]] static constexpr AngularSpeed<NumericType> Zero() {
109  return AngularSpeed<NumericType>{static_cast<NumericType>(0)};
110  }
111 
112  /// \brief Statically creates an angular speed with a given value expressed in a given angular
113  /// speed unit.
114  template <Unit::AngularSpeed Unit>
115  [[nodiscard]] static constexpr AngularSpeed<NumericType> Create(const NumericType value) {
117  ConvertStatically<Unit::AngularSpeed, Unit, Standard<Unit::AngularSpeed>>(value)};
118  }
119 
121  const AngularSpeed<NumericType>& angular_speed) const {
122  return AngularSpeed<NumericType>{this->value + angular_speed.value};
123  }
124 
126  const AngularSpeed<NumericType>& angular_speed) const {
127  return AngularSpeed<NumericType>{this->value - angular_speed.value};
128  }
129 
130  constexpr AngularSpeed<NumericType> operator*(const NumericType number) const {
131  return AngularSpeed<NumericType>{this->value * number};
132  }
133 
134  constexpr Angle<NumericType> operator*(const Time<NumericType>& time) const {
135  return Angle<NumericType>{*this, time};
136  }
137 
139  const Frequency<NumericType>& frequency) const;
140 
141  constexpr AngularSpeed<NumericType> operator/(const NumericType number) const {
142  return AngularSpeed<NumericType>{this->value / number};
143  }
144 
145  constexpr Angle<NumericType> operator/(const Frequency<NumericType>& frequency) const {
146  return Angle<NumericType>{*this, frequency};
147  }
148 
149  constexpr Frequency<NumericType> operator/(const Angle<NumericType>& angle) const {
150  return Frequency<NumericType>{*this, angle};
151  }
152 
154 
156  const ScalarAngularAcceleration<NumericType>& scalar_angular_acceleration) const;
157 
158  constexpr NumericType operator/(const AngularSpeed<NumericType>& angular_speed) const noexcept {
159  return this->value / angular_speed.value;
160  }
161 
162  constexpr void operator+=(const AngularSpeed<NumericType>& angular_speed) noexcept {
163  this->value += angular_speed.value;
164  }
165 
166  constexpr void operator-=(const AngularSpeed<NumericType>& angular_speed) noexcept {
167  this->value -= angular_speed.value;
168  }
169 
170  constexpr void operator*=(const NumericType number) noexcept {
171  this->value *= number;
172  }
173 
174  constexpr void operator/=(const NumericType number) noexcept {
175  this->value /= number;
176  }
177 
178 private:
179  /// \brief Constructor. Constructs an angular speed with a given value expressed in the standard
180  /// angular speed unit.
181  explicit constexpr AngularSpeed(const NumericType value)
182  : DimensionalScalar<Unit::AngularSpeed, NumericType>(value) {}
183 };
184 
185 template <typename NumericType>
186 inline constexpr bool operator==(
187  const AngularSpeed<NumericType>& left, const AngularSpeed<NumericType>& right) noexcept {
188  return left.Value() == right.Value();
189 }
190 
191 template <typename NumericType>
192 inline constexpr bool operator!=(
193  const AngularSpeed<NumericType>& left, const AngularSpeed<NumericType>& right) noexcept {
194  return left.Value() != right.Value();
195 }
196 
197 template <typename NumericType>
198 inline constexpr bool operator<(
199  const AngularSpeed<NumericType>& left, const AngularSpeed<NumericType>& right) noexcept {
200  return left.Value() < right.Value();
201 }
202 
203 template <typename NumericType>
204 inline constexpr bool operator>(
205  const AngularSpeed<NumericType>& left, const AngularSpeed<NumericType>& right) noexcept {
206  return left.Value() > right.Value();
207 }
208 
209 template <typename NumericType>
210 inline constexpr bool operator<=(
211  const AngularSpeed<NumericType>& left, const AngularSpeed<NumericType>& right) noexcept {
212  return left.Value() <= right.Value();
213 }
214 
215 template <typename NumericType>
216 inline constexpr bool operator>=(
217  const AngularSpeed<NumericType>& left, const AngularSpeed<NumericType>& right) noexcept {
218  return left.Value() >= right.Value();
219 }
220 
221 template <typename NumericType>
222 inline std::ostream& operator<<(
223  std::ostream& stream, const AngularSpeed<NumericType>& angular_speed) {
224  stream << angular_speed.Print();
225  return stream;
226 }
227 
228 template <typename NumericType>
230  const NumericType number, const AngularSpeed<NumericType>& angular_speed) {
231  return angular_speed * number;
232 }
233 
234 template <typename NumericType>
235 inline constexpr Angle<NumericType>::Angle(
236  const AngularSpeed<NumericType>& angular_speed, const Time<NumericType>& time)
237  : Angle<NumericType>(angular_speed.Value() * time.Value()) {}
238 
239 template <typename NumericType>
240 inline constexpr Angle<NumericType>::Angle(
241  const AngularSpeed<NumericType>& angular_speed, const Frequency<NumericType>& frequency)
242  : Angle<NumericType>(angular_speed.Value() / frequency.Value()) {}
243 
244 template <typename NumericType>
245 inline constexpr Time<NumericType>::Time(
246  const Angle<NumericType>& angle, const AngularSpeed<NumericType>& angular_speed)
247  : Time<NumericType>(angle.Value() / angular_speed.Value()) {}
248 
249 template <typename NumericType>
250 inline constexpr Frequency<NumericType>::Frequency(
251  const AngularSpeed<NumericType>& angular_speed, const Angle<NumericType>& angle)
252  : Frequency<NumericType>(angular_speed.Value() / angle.Value()) {}
253 
254 template <typename NumericType>
255 inline constexpr Angle<NumericType> Time<NumericType>::operator*(
256  const AngularSpeed<NumericType>& angular_speed) const {
257  return Angle<NumericType>(angular_speed, *this);
258 }
259 
260 template <typename NumericType>
261 inline constexpr AngularSpeed<NumericType> Angle<NumericType>::operator*(
262  const Frequency<NumericType>& frequency) const {
263  return AngularSpeed<NumericType>{*this, frequency};
264 }
265 
266 template <typename NumericType>
267 inline constexpr AngularSpeed<NumericType> Frequency<NumericType>::operator*(
268  const Angle<NumericType>& angle) const {
269  return AngularSpeed<NumericType>{angle, *this};
270 }
271 
272 template <typename NumericType>
273 inline constexpr AngularSpeed<NumericType> Angle<NumericType>::operator/(
274  const Time<NumericType>& time) const {
275  return AngularSpeed<NumericType>{*this, time};
276 }
277 
278 template <typename NumericType>
279 inline constexpr Time<NumericType> Angle<NumericType>::operator/(
280  const AngularSpeed<NumericType>& angular_speed) const {
281  return Time<NumericType>{*this, angular_speed};
282 }
283 
284 } // namespace PhQ
285 
286 namespace std {
287 
288 template <typename NumericType>
289 struct hash<PhQ::AngularSpeed<NumericType>> {
290  inline size_t operator()(const PhQ::AngularSpeed<NumericType>& angular_speed) const {
291  return hash<NumericType>()(angular_speed.Value());
292  }
293 };
294 
295 } // namespace std
296 
297 #endif // PHQ_ANGULAR_SPEED_HPP
Plane angle between two lines or dihedral angle between two planes.
Definition: Angle.hpp:130
Angle()=default
Default constructor. Constructs an angle with an uninitialized value.
Angular speed, also known as angular rate or angular frequency. Represents the time rate of change of...
constexpr void operator*=(const NumericType number) noexcept
constexpr void operator/=(const NumericType number) noexcept
constexpr AngularSpeed< NumericType > & operator=(const AngularSpeed< NumericType > &other)=default
Copy assignment operator. Assigns this angular speed by copying another one.
constexpr Time< NumericType > operator/(const ScalarAngularAcceleration< NumericType > &scalar_angular_acceleration) const
AngularSpeed(const NumericType value, const Unit::AngularSpeed unit)
Constructor. Constructs an angular speed with a given value expressed in a given angular speed unit.
constexpr AngularSpeed(const Angle< NumericType > &angle, const Frequency< NumericType > &frequency)
Constructor. Constructs an angular speed from a given angle and frequency using the definition of ang...
constexpr AngularSpeed< NumericType > & operator=(const AngularSpeed< OtherNumericType > &other)
Copy assignment operator. Assigns this angular speed by copying another one.
constexpr AngularSpeed< NumericType > operator-(const AngularSpeed< NumericType > &angular_speed) const
constexpr Angle< NumericType > operator/(const Frequency< NumericType > &frequency) const
constexpr AngularSpeed(const NumericType value)
Constructor. Constructs an angular speed with a given value expressed in the standard angular speed u...
constexpr AngularSpeed< NumericType > operator*(const NumericType number) const
constexpr Frequency< NumericType > operator/(const Angle< NumericType > &angle) const
~AngularSpeed() noexcept=default
Destructor. Destroys this angular speed.
constexpr AngularSpeed(const ScalarAngularAcceleration< NumericType > &scalar_angular_acceleration, const Time< NumericType > &time)
Constructor. Constructs an angular speed from a given scalar angular acceleration and time using the ...
constexpr NumericType operator/(const AngularSpeed< NumericType > &angular_speed) const noexcept
constexpr AngularSpeed< NumericType > & operator=(AngularSpeed< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this angular speed by moving another one.
constexpr void operator-=(const AngularSpeed< NumericType > &angular_speed) noexcept
static constexpr AngularSpeed< NumericType > Zero()
Statically creates an angular speed of zero.
constexpr Angle< NumericType > operator*(const Time< NumericType > &time) const
constexpr void operator+=(const AngularSpeed< NumericType > &angular_speed) noexcept
static constexpr AngularSpeed< NumericType > Create(const NumericType value)
Statically creates an angular speed with a given value expressed in a given angular speed unit.
constexpr ScalarAngularAcceleration< NumericType > operator/(const Time< NumericType > &time) const
constexpr AngularSpeed< NumericType > operator/(const NumericType number) const
constexpr ScalarAngularAcceleration< NumericType > operator*(const Frequency< NumericType > &frequency) const
constexpr AngularSpeed(const Angle< NumericType > &angle, const Time< NumericType > &time)
Constructor. Constructs an angular speed from a given angle and time using the definition of angular ...
constexpr AngularSpeed< NumericType > operator+(const AngularSpeed< NumericType > &angular_speed) const
AngularSpeed()=default
Default constructor. Constructs an angular speed with an uninitialized value.
constexpr AngularSpeed(const ScalarAngularAcceleration< NumericType > &scalar_angular_acceleration, const Frequency< NumericType > &frequency)
Constructor. Constructs an angular speed from a given scalar angular acceleration and frequency using...
constexpr AngularSpeed(AngularSpeed< NumericType > &&other) noexcept=default
Move constructor. Constructs an angular speed by moving another one.
Abstract base class that represents any dimensional scalar physical quantity. Such a physical quantit...
double value
Value of this physical quantity expressed in its standard unit of measure.
constexpr double Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
static constexpr Unit::AngularSpeed Unit()
Standard unit of measure for this physical quantity. This physical quantity's value is stored interna...
std::string Print() const
Prints this physical quantity as a string. This physical quantity's value is expressed in its standar...
Frequency. Inverse of a time duration. See also PhQ::Time.
Definition: Frequency.hpp:40
Scalar angular acceleration. Represents the time rate of change of an angular speed; see also PhQ::An...
Time. Can represent either a point in time, a time duration, or a period. For the inverse of time,...
Definition: Time.hpp:172
Frequency
Frequency units.
Definition: Frequency.hpp:53
Angle
Angle units.
Definition: Angle.hpp:53
Time
Time units.
Definition: Time.hpp:53
AngularSpeed
Angular speed units.
Namespace that encompasses all of the Physical Quantities library's content.
constexpr bool operator<(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
constexpr AngularSpeed< NumericType > operator*(const NumericType number, const AngularSpeed< NumericType > &angular_speed)
constexpr bool operator<=(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
constexpr Acceleration< NumericType > operator*(const NumericType number, const Acceleration< NumericType > &acceleration)
constexpr bool operator>(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
constexpr bool operator==(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
constexpr bool operator>=(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
constexpr Dyad< NumericType > operator/(const Dyad< NumericType > &dyad, const OtherNumericType number)
Definition: Dyad.hpp:696
constexpr bool operator!=(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
std::ostream & operator<<(std::ostream &stream, const Acceleration< NumericType > &acceleration)