Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
PlanarAcceleration.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_PLANAR_ACCELERATION_HPP
26 #define PHQ_PLANAR_ACCELERATION_HPP
27 
28 #include <array>
29 #include <cstddef>
30 #include <functional>
31 #include <ostream>
32 
33 #include "Angle.hpp"
35 #include "Frequency.hpp"
36 #include "PlanarDirection.hpp"
37 #include "PlanarVector.hpp"
38 #include "PlanarVelocity.hpp"
39 #include "ScalarAcceleration.hpp"
40 #include "Time.hpp"
41 #include "Unit/Acceleration.hpp"
42 
43 namespace PhQ {
44 
45 /// \brief Two-dimensional Euclidean acceleration vector in the XY plane. Contains two components in
46 /// Cartesian coordinates: x and y. For a three-dimensional Euclidean acceleration vector, see
47 /// PhQ::Acceleration. For scalar acceleration components or for the magnitude of an acceleration
48 /// vector, see PhQ::ScalarAcceleration.
49 template <typename NumericType = double>
50 class PlanarAcceleration : public DimensionalPlanarVector<Unit::Acceleration, NumericType> {
51 public:
52  /// \brief Default constructor. Constructs a planar acceleration vector with an uninitialized
53  /// value.
54  PlanarAcceleration() = default;
55 
56  /// \brief Constructor. Constructs a planar acceleration vector with a given value expressed in a
57  /// given acceleration unit.
59  : DimensionalPlanarVector<Unit::Acceleration, NumericType>(value, unit) {}
60 
61  /// \brief Constructor. Constructs a planar acceleration vector from a given set of scalar
62  /// acceleration components.
65  : PlanarAcceleration<NumericType>({x.Value(), y.Value()}) {}
66 
67  /// \brief Constructor. Constructs a planar acceleration vector from a given scalar acceleration
68  /// magnitude and planar direction.
69  constexpr PlanarAcceleration(const ScalarAcceleration<NumericType>& scalar_acceleration,
70  const PlanarDirection<NumericType>& planar_direction)
71  : PlanarAcceleration<NumericType>(scalar_acceleration.Value() * planar_direction.Value()) {}
72 
73  /// \brief Constructor. Constructs a planar acceleration vector from a given acceleration vector
74  /// by projecting the acceleration vector onto the XY plane.
75  explicit constexpr PlanarAcceleration(const Acceleration<NumericType>& acceleration);
76 
77  /// \brief Constructor. Constructs a planar acceleration vector from a given planar velocity and
78  /// time using the definition of acceleration.
79  constexpr PlanarAcceleration(
80  const PlanarVelocity<NumericType>& planar_velocity, const Time<NumericType>& time)
81  : PlanarAcceleration<NumericType>(planar_velocity.Value() / time.Value()) {}
82 
83  /// \brief Constructor. Constructs a planar acceleration vector from a given planar velocity and
84  /// frequency using the definition of acceleration.
85  constexpr PlanarAcceleration(
86  const PlanarVelocity<NumericType>& planar_velocity, const Frequency<NumericType>& frequency)
87  : PlanarAcceleration<NumericType>(planar_velocity.Value() * frequency.Value()) {}
88 
89  /// \brief Destructor. Destroys this acceleration vector.
90  ~PlanarAcceleration() noexcept = default;
91 
92  /// \brief Copy constructor. Constructs a planar acceleration vector by copying another one.
93  constexpr PlanarAcceleration(const PlanarAcceleration<NumericType>& other) = default;
94 
95  /// \brief Copy constructor. Constructs a planar acceleration vector by copying another one.
96  template <typename OtherNumericType>
97  explicit constexpr PlanarAcceleration(const PlanarAcceleration<OtherNumericType>& other)
98  : PlanarAcceleration(static_cast<PlanarVector<NumericType>>(other.Value())) {}
99 
100  /// \brief Move constructor. Constructs a planar acceleration vector by moving another one.
101  constexpr PlanarAcceleration(PlanarAcceleration<NumericType>&& other) noexcept = default;
102 
103  /// \brief Copy assignment operator. Assigns this acceleration vector by copying another one.
105  const PlanarAcceleration<NumericType>& other) = default;
106 
107  /// \brief Copy assignment operator. Assigns this acceleration vector by copying another one.
108  template <typename OtherNumericType>
111  this->value = static_cast<PlanarVector<NumericType>>(other.Value());
112  return *this;
113  }
114 
115  /// \brief Move assignment operator. Assigns this acceleration vector by moving another one.
117  PlanarAcceleration<NumericType>&& other) noexcept = default;
118 
119  /// \brief Statically creates a planar acceleration vector of zero.
120  [[nodiscard]] static constexpr PlanarAcceleration<NumericType> Zero() {
122  }
123 
124  /// \brief Statically creates a planar acceleration vector from the given x and y Cartesian
125  /// components expressed in a given acceleration unit.
126  template <Unit::Acceleration Unit>
127  [[nodiscard]] static constexpr PlanarAcceleration<NumericType> Create(
128  const NumericType x, const NumericType y) {
130  ConvertStatically<Unit::Acceleration, Unit, Standard<Unit::Acceleration>>(
132  }
133 
134  /// \brief Statically creates a planar acceleration vector from the given x and y Cartesian
135  /// components expressed in a given acceleration unit.
136  template <Unit::Acceleration Unit>
137  [[nodiscard]] static constexpr PlanarAcceleration<NumericType> Create(
138  const std::array<NumericType, 2>& x_y) {
140  ConvertStatically<Unit::Acceleration, Unit, Standard<Unit::Acceleration>>(
142  }
143 
144  /// \brief Statically creates a planar acceleration vector with a given value expressed in a given
145  /// acceleration unit.
146  template <Unit::Acceleration Unit>
147  [[nodiscard]] static constexpr PlanarAcceleration<NumericType> Create(
150  ConvertStatically<Unit::Acceleration, Unit, Standard<Unit::Acceleration>>(value)};
151  }
152 
153  /// \brief Returns the x Cartesian component of this acceleration vector.
154  [[nodiscard]] constexpr ScalarAcceleration<NumericType> x() const noexcept {
155  return ScalarAcceleration<NumericType>{this->value.x()};
156  }
157 
158  /// \brief Returns the y Cartesian component of this acceleration vector.
159  [[nodiscard]] constexpr ScalarAcceleration<NumericType> y() const noexcept {
160  return ScalarAcceleration<NumericType>{this->value.y()};
161  }
162 
163  /// \brief Returns the magnitude of this acceleration vector.
166  }
167 
168  /// \brief Returns the planar direction of this acceleration vector.
170  return this->value.PlanarDirection();
171  }
172 
173  /// \brief Returns the angle between this acceleration vector and another one.
175  return PhQ::Angle<NumericType>{*this, other};
176  }
177 
179  const PlanarAcceleration<NumericType>& other) const {
180  return PlanarAcceleration<NumericType>{this->value + other.value};
181  }
182 
184  const PlanarAcceleration<NumericType>& other) const {
185  return PlanarAcceleration<NumericType>{this->value - other.value};
186  }
187 
188  constexpr PlanarAcceleration<NumericType> operator*(const NumericType number) const {
189  return PlanarAcceleration<NumericType>{this->value * number};
190  }
191 
193  return PlanarVelocity<NumericType>{*this, time};
194  }
195 
196  constexpr PlanarAcceleration<NumericType> operator/(const NumericType number) const {
197  return PlanarAcceleration<NumericType>{this->value / number};
198  }
199 
201  return PlanarVelocity<NumericType>{*this, frequency};
202  }
203 
204  constexpr void operator+=(const PlanarAcceleration<NumericType>& other) noexcept {
205  this->value += other.value;
206  }
207 
208  constexpr void operator-=(const PlanarAcceleration<NumericType>& other) noexcept {
209  this->value -= other.value;
210  }
211 
212  constexpr void operator*=(const NumericType number) noexcept {
213  this->value *= number;
214  }
215 
216  constexpr void operator/=(const NumericType number) noexcept {
217  this->value /= number;
218  }
219 
220 private:
221  /// \brief Constructor. Constructs a planar acceleration vector with a given value expressed in
222  /// the standard acceleration unit.
224  : DimensionalPlanarVector<Unit::Acceleration, NumericType>(value) {}
225 };
226 
227 template <typename NumericType>
228 inline constexpr bool operator==(const PlanarAcceleration<NumericType>& left,
229  const PlanarAcceleration<NumericType>& right) noexcept {
230  return left.Value() == right.Value();
231 }
232 
233 template <typename NumericType>
234 inline constexpr bool operator!=(const PlanarAcceleration<NumericType>& left,
235  const PlanarAcceleration<NumericType>& right) noexcept {
236  return left.Value() != right.Value();
237 }
238 
239 template <typename NumericType>
240 inline constexpr bool operator<(const PlanarAcceleration<NumericType>& left,
241  const PlanarAcceleration<NumericType>& right) noexcept {
242  return left.Value() < right.Value();
243 }
244 
245 template <typename NumericType>
246 inline constexpr bool operator>(const PlanarAcceleration<NumericType>& left,
247  const PlanarAcceleration<NumericType>& right) noexcept {
248  return left.Value() > right.Value();
249 }
250 
251 template <typename NumericType>
252 inline constexpr bool operator<=(const PlanarAcceleration<NumericType>& left,
253  const PlanarAcceleration<NumericType>& right) noexcept {
254  return left.Value() <= right.Value();
255 }
256 
257 template <typename NumericType>
258 inline constexpr bool operator>=(const PlanarAcceleration<NumericType>& left,
259  const PlanarAcceleration<NumericType>& right) noexcept {
260  return left.Value() >= right.Value();
261 }
262 
263 template <typename NumericType>
264 inline std::ostream& operator<<(
265  std::ostream& stream, const PlanarAcceleration<NumericType>& planar_acceleration) {
266  stream << planar_acceleration.Print();
267  return stream;
268 }
269 
270 template <typename NumericType>
272  const NumericType number, const PlanarAcceleration<NumericType>& planar_acceleration) {
273  return planar_acceleration * number;
274 }
275 
276 template <typename NumericType>
278  const PlanarAcceleration<NumericType>& planar_acceleration)
279  : PlanarDirection<NumericType>(planar_acceleration.Value()) {}
280 
281 template <typename NumericType>
282 inline Angle<NumericType>::Angle(const PlanarAcceleration<NumericType>& planar_acceleration_1,
283  const PlanarAcceleration<NumericType>& planar_acceleration_2)
284  : Angle<NumericType>(planar_acceleration_1.Value(), planar_acceleration_2.Value()) {}
285 
286 template <typename NumericType>
288  const PlanarAcceleration<NumericType>& planar_acceleration, const Time<NumericType>& time)
289  : PlanarVelocity<NumericType>(planar_acceleration.Value() * time.Value()) {}
290 
291 template <typename NumericType>
293  const PlanarAcceleration<NumericType>& planar_acceleration,
294  const Frequency<NumericType>& frequency)
295  : PlanarVelocity<NumericType>(planar_acceleration.Value() / frequency.Value()) {}
296 
297 template <typename NumericType>
299  const ScalarAcceleration<NumericType>& scalar_acceleration) const {
300  return PlanarAcceleration<NumericType>{scalar_acceleration, *this};
301 }
302 
303 template <typename NumericType>
305  const PlanarAcceleration<NumericType>& planar_acceleration) const {
306  return PlanarVelocity<NumericType>{planar_acceleration, *this};
307 }
308 
309 template <typename NumericType>
311  const PlanarDirection<NumericType>& planar_direction) const {
312  return PlanarAcceleration<NumericType>{*this, planar_direction};
313 }
314 
315 template <typename NumericType>
317  const Frequency<NumericType>& frequency) const {
318  return PlanarAcceleration<NumericType>{*this, frequency};
319 }
320 
321 template <typename NumericType>
323  const PlanarVelocity<NumericType>& planar_velocity) const {
324  return PlanarAcceleration<NumericType>{planar_velocity, *this};
325 }
326 
327 template <typename NumericType>
329  const Time<NumericType>& time) const {
330  return PlanarAcceleration<NumericType>{*this, time};
331 }
332 
333 } // namespace PhQ
334 
335 namespace std {
336 
337 template <typename NumericType>
338 struct hash<PhQ::PlanarAcceleration<NumericType>> {
339  inline size_t operator()(const PhQ::PlanarAcceleration<NumericType>& planar_acceleration) const {
340  return hash<PhQ::PlanarVector<NumericType>>()(planar_acceleration.Value());
341  }
342 };
343 
344 } // namespace std
345 
346 #endif // PHQ_PLANAR_ACCELERATION_HPP
Three-dimensional Euclidean acceleration vector. Contains three components in Cartesian coordinates: ...
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.
Abstract base class that represents any dimensional planar vector physical quantity....
PhQ::PlanarVector< double > value
Value of this physical quantity expressed in its standard unit of measure.
constexpr const PhQ::PlanarVector< double > & Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
static constexpr Unit::Acceleration 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
constexpr Frequency< NumericType > operator*(const NumericType number) const
Definition: Frequency.hpp:154
Two-dimensional Euclidean acceleration vector in the XY plane. Contains two components in Cartesian c...
constexpr PlanarAcceleration< NumericType > operator/(const NumericType number) const
constexpr PlanarVelocity< NumericType > operator*(const Time< NumericType > &time) const
constexpr void operator/=(const NumericType number) noexcept
static constexpr PlanarAcceleration< NumericType > Create(const std::array< NumericType, 2 > &x_y)
Statically creates a planar acceleration vector from the given x and y Cartesian components expressed...
PhQ::Angle< NumericType > Angle(const PlanarAcceleration< NumericType > &other) const
Returns the angle between this acceleration vector and another one.
constexpr PlanarAcceleration< NumericType > & operator=(const PlanarAcceleration< OtherNumericType > &other)
Copy assignment operator. Assigns this acceleration vector by copying another one.
constexpr PlanarAcceleration< NumericType > & operator=(const PlanarAcceleration< NumericType > &other)=default
Copy assignment operator. Assigns this acceleration vector by copying another one.
PlanarAcceleration(const PlanarVector< NumericType > &value, const Unit::Acceleration unit)
Constructor. Constructs a planar acceleration vector with a given value expressed in a given accelera...
PlanarAcceleration()=default
Default constructor. Constructs a planar acceleration vector with an uninitialized value.
PlanarAcceleration(const ScalarAcceleration< NumericType > &x, const ScalarAcceleration< NumericType > &y)
Constructor. Constructs a planar acceleration vector from a given set of scalar acceleration componen...
constexpr PlanarAcceleration< NumericType > operator*(const NumericType number) const
static constexpr PlanarAcceleration< NumericType > Create(const PlanarVector< NumericType > &value)
Statically creates a planar acceleration vector with a given value expressed in a given acceleration ...
constexpr ScalarAcceleration< NumericType > y() const noexcept
Returns the y Cartesian component of this acceleration vector.
constexpr PlanarAcceleration(const PlanarVelocity< NumericType > &planar_velocity, const Frequency< NumericType > &frequency)
Constructor. Constructs a planar acceleration vector from a given planar velocity and frequency using...
~PlanarAcceleration() noexcept=default
Destructor. Destroys this acceleration vector.
constexpr PlanarAcceleration(const PlanarVelocity< NumericType > &planar_velocity, const Time< NumericType > &time)
Constructor. Constructs a planar acceleration vector from a given planar velocity and time using the ...
constexpr void operator*=(const NumericType number) noexcept
constexpr void operator+=(const PlanarAcceleration< NumericType > &other) noexcept
constexpr ScalarAcceleration< NumericType > x() const noexcept
Returns the x Cartesian component of this acceleration vector.
constexpr PlanarAcceleration< NumericType > operator-(const PlanarAcceleration< NumericType > &other) const
constexpr void operator-=(const PlanarAcceleration< NumericType > &other) noexcept
static constexpr PlanarAcceleration< NumericType > Zero()
Statically creates a planar acceleration vector of zero.
constexpr PlanarVelocity< NumericType > operator/(const Frequency< NumericType > &frequency) const
constexpr PlanarAcceleration(const PlanarVector< NumericType > &value)
Constructor. Constructs a planar acceleration vector with a given value expressed in the standard acc...
static constexpr PlanarAcceleration< NumericType > Create(const NumericType x, const NumericType y)
Statically creates a planar acceleration vector from the given x and y Cartesian components expressed...
ScalarAcceleration< NumericType > Magnitude() const
Returns the magnitude of this acceleration vector.
constexpr PlanarAcceleration< NumericType > operator+(const PlanarAcceleration< NumericType > &other) const
PhQ::PlanarDirection< NumericType > PlanarDirection() const
Returns the planar direction of this acceleration vector.
constexpr PlanarAcceleration< NumericType > & operator=(PlanarAcceleration< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this acceleration vector by moving another one.
constexpr PlanarAcceleration(const ScalarAcceleration< NumericType > &scalar_acceleration, const PlanarDirection< NumericType > &planar_direction)
Constructor. Constructs a planar acceleration vector from a given scalar acceleration magnitude and p...
constexpr PlanarAcceleration(PlanarAcceleration< NumericType > &&other) noexcept=default
Move constructor. Constructs a planar acceleration vector by moving another one.
two-dimensional Euclidean direction vector in the XY plane. Contains two components in Cartesian coor...
constexpr PlanarAcceleration< NumericType > operator*(const ScalarAcceleration< NumericType > &scalar_acceleration) const
constexpr PlanarDirection()
Default constructor. Initializes a planar direction to the zero planar vector.
Two-dimensional Euclidean vector in the XY plane. Contains two components in Cartesian coordinates: x...
constexpr NumericType x() const noexcept
Returns this two-dimensional planar vector's x Cartesian component.
static constexpr PlanarVector< NumericType > Zero()
Statically creates a two-dimensional planar vector with its x and y Cartesian components initialized ...
PhQ::PlanarDirection< NumericType > PlanarDirection() const
Returns the planar direction of this two-dimensional planar vector.
NumericType Magnitude() const noexcept
Returns the magnitude (also known as the L2 norm) of this two-dimensional planar vector.
constexpr NumericType y() const noexcept
Returns this two-dimensional planar vector's y Cartesian component.
Two-dimensional Euclidean velocity vector in the XY plane. Contains two components in Cartesian coord...
constexpr PlanarVelocity< NumericType > operator/(const NumericType number) const
constexpr PlanarVelocity< NumericType > operator*(const NumericType number) const
PlanarVelocity()=default
Default constructor. Constructs a planar velocity vector with an uninitialized value.
Scalar acceleration component or magnitude of an acceleration vector. For a three-dimensional Euclide...
constexpr ScalarAcceleration< NumericType > operator*(const NumericType number) const
Time. Can represent either a point in time, a time duration, or a period. For the inverse of time,...
Definition: Time.hpp:172
constexpr Time< NumericType > operator*(const NumericType number) const
Definition: Time.hpp:278
Acceleration
Acceleration 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 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 bool operator!=(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
std::ostream & operator<<(std::ostream &stream, const Acceleration< NumericType > &acceleration)