Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
Loading...
Searching...
No Matches
PlanarForce.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_FORCE_HPP
26#define PHQ_PLANAR_FORCE_HPP
27
28#include <array>
29#include <cstddef>
30#include <functional>
31#include <ostream>
32
33#include "Angle.hpp"
35#include "PlanarDirection.hpp"
36#include "PlanarVector.hpp"
37#include "ScalarForce.hpp"
38#include "Unit/Force.hpp"
39
40namespace PhQ {
41
42// Forward declaration for class PhQ::PlanarForce.
43template <typename NumericType>
44class PlanarTraction;
45
46/// \brief Two-dimensional Euclidean force vector in the XY plane. Contains two components in
47/// Cartesian coordinates: x and y. For a three-dimensional Euclidean force vector, see PhQ::Force.
48/// For scalar force components or for the magnitude of a force vector, see PhQ::ScalarForce.
49template <typename NumericType = double>
50class PlanarForce : public DimensionalPlanarVector<Unit::Force, NumericType> {
51public:
52 /// \brief Default constructor. Constructs a planar force vector with an uninitialized value.
53 PlanarForce() = default;
54
55 /// \brief Constructor. Constructs a planar force vector with a given value expressed in a given
56 /// force unit.
59
60 /// \brief Constructor. Constructs a planar force vector from a given set of scalar force
61 /// components.
63 : PlanarForce<NumericType>({x.Value(), y.Value()}) {}
64
65 /// \brief Constructor. Constructs a planar force vector from a given scalar force magnitude and
66 /// planar direction.
67 constexpr PlanarForce(const ScalarForce<NumericType>& scalar_force,
68 const PlanarDirection<NumericType>& planar_direction)
69 : PlanarForce<NumericType>(scalar_force.Value() * planar_direction.Value()) {}
70
71 /// \brief Constructor. Constructs a planar force vector from a given force vector by projecting
72 /// the force vector onto the XY plane.
73 explicit constexpr PlanarForce(const Force<NumericType>& force);
74
75 /// \brief Constructor. Constructs a planar force vector from a given planar traction and area
76 /// using the definition of traction.
77 constexpr PlanarForce(
78 const PlanarTraction<NumericType>& planar_traction, const Area<NumericType>& area);
79
80 /// \brief Destructor. Destroys this planar force vector.
81 ~PlanarForce() noexcept = default;
82
83 /// \brief Copy constructor. Constructs a planar force vector by copying another one.
84 constexpr PlanarForce(const PlanarForce<NumericType>& other) = default;
85
86 /// \brief Copy constructor. Constructs a planar force vector by copying another one.
87 template <typename OtherNumericType>
88 explicit constexpr PlanarForce(const PlanarForce<OtherNumericType>& other)
89 : PlanarForce(static_cast<PlanarVector<NumericType>>(other.Value())) {}
90
91 /// \brief Move constructor. Constructs a planar force vector by moving another one.
92 constexpr PlanarForce(PlanarForce<NumericType>&& other) noexcept = default;
93
94 /// \brief Copy assignment operator. Assigns this planar force vector by copying another one.
96
97 /// \brief Copy assignment operator. Assigns this planar force vector by copying another one.
98 template <typename OtherNumericType>
100 this->value = static_cast<PlanarVector<NumericType>>(other.Value());
101 return *this;
102 }
103
104 /// \brief Move assignment operator. Assigns this planar force vector by moving another one.
106 PlanarForce<NumericType>&& other) noexcept = default;
107
108 /// \brief Statically creates a planar force vector of zero.
109 [[nodiscard]] static constexpr PlanarForce<NumericType> Zero() {
111 }
112
113 /// \brief Statically creates a planar force vector from the given x and y Cartesian components
114 /// expressed in a given force unit.
115 template <Unit::Force Unit>
116 [[nodiscard]] static constexpr PlanarForce<NumericType> Create(
117 const NumericType x, const NumericType y) {
119 ConvertStatically<Unit::Force, Unit, Standard<Unit::Force>>(PlanarVector<NumericType>{x, y})};
120 }
121
122 /// \brief Statically creates a planar force vector from the given x and y Cartesian components
123 /// expressed in a given force unit.
124 template <Unit::Force Unit>
125 [[nodiscard]] static constexpr PlanarForce<NumericType> Create(
126 const std::array<NumericType, 2>& x_y) {
128 ConvertStatically<Unit::Force, Unit, Standard<Unit::Force>>(PlanarVector<NumericType>{x_y})};
129 }
130
131 /// \brief Statically creates a planar force vector with a given value expressed in a given force
132 /// unit.
133 template <Unit::Force Unit>
134 [[nodiscard]] static constexpr PlanarForce<NumericType> Create(
137 ConvertStatically<Unit::Force, Unit, Standard<Unit::Force>>(value)};
138 }
139
140 /// \brief Returns the x Cartesian component of this planar force vector.
141 [[nodiscard]] constexpr ScalarForce<NumericType> x() const noexcept {
142 return ScalarForce<NumericType>{this->value.x()};
143 }
144
145 /// \brief Returns the y Cartesian component of this planar force vector.
146 [[nodiscard]] constexpr ScalarForce<NumericType> y() const noexcept {
147 return ScalarForce<NumericType>{this->value.y()};
148 }
149
150 /// \brief Returns the magnitude of this planar force vector.
151 [[nodiscard]] ScalarForce<NumericType> Magnitude() const {
152 return ScalarForce<NumericType>{this->value.Magnitude()};
153 }
154
155 /// \brief Returns the planar direction of this planar force vector.
157 return this->value.PlanarDirection();
158 }
159
160 /// \brief Returns the angle between this planar force vector and another one.
161 [[nodiscard]] PhQ::Angle<NumericType> Angle(const PlanarForce<NumericType>& planar_force) const {
162 return PhQ::Angle<NumericType>{*this, planar_force};
163 }
164
165 constexpr PlanarForce<NumericType> operator+(const PlanarForce<NumericType>& planar_force) const {
166 return PlanarForce<NumericType>{this->value + planar_force.value};
167 }
168
169 constexpr PlanarForce<NumericType> operator-(const PlanarForce<NumericType>& planar_force) const {
170 return PlanarForce<NumericType>{this->value - planar_force.value};
171 }
172
173 constexpr PlanarForce<NumericType> operator*(const NumericType number) const {
174 return PlanarForce<NumericType>{this->value * number};
175 }
176
177 constexpr PlanarForce<NumericType> operator/(const NumericType number) const {
178 return PlanarForce<NumericType>{this->value / number};
179 }
180
181 constexpr PlanarTraction<NumericType> operator/(const Area<NumericType>& area) const;
182
183 constexpr void operator+=(const PlanarForce<NumericType>& planar_force) noexcept {
184 this->value += planar_force.value;
185 }
186
187 constexpr void operator-=(const PlanarForce<NumericType>& planar_force) noexcept {
188 this->value -= planar_force.value;
189 }
190
191 constexpr void operator*=(const NumericType number) noexcept {
192 this->value *= number;
193 }
194
195 constexpr void operator/=(const NumericType number) noexcept {
196 this->value /= number;
197 }
198
199private:
200 /// \brief Constructor. Constructs a planar force vector with a given value expressed in the
201 /// standard force unit.
202 explicit constexpr PlanarForce(const PlanarVector<NumericType>& value)
203 : DimensionalPlanarVector<Unit::Force, NumericType>(value) {}
204};
205
206template <typename NumericType>
207inline constexpr bool operator==(
208 const PlanarForce<NumericType>& left, const PlanarForce<NumericType>& right) noexcept {
209 return left.Value() == right.Value();
210}
211
212template <typename NumericType>
213inline constexpr bool operator!=(
214 const PlanarForce<NumericType>& left, const PlanarForce<NumericType>& right) noexcept {
215 return left.Value() != right.Value();
216}
217
218template <typename NumericType>
219inline constexpr bool operator<(
220 const PlanarForce<NumericType>& left, const PlanarForce<NumericType>& right) noexcept {
221 return left.Value() < right.Value();
222}
223
224template <typename NumericType>
225inline constexpr bool operator>(
226 const PlanarForce<NumericType>& left, const PlanarForce<NumericType>& right) noexcept {
227 return left.Value() > right.Value();
228}
229
230template <typename NumericType>
231inline constexpr bool operator<=(
232 const PlanarForce<NumericType>& left, const PlanarForce<NumericType>& right) noexcept {
233 return left.Value() <= right.Value();
234}
235
236template <typename NumericType>
237inline constexpr bool operator>=(
238 const PlanarForce<NumericType>& left, const PlanarForce<NumericType>& right) noexcept {
239 return left.Value() >= right.Value();
240}
241
242template <typename NumericType>
243inline std::ostream& operator<<(
244 std::ostream& stream, const PlanarForce<NumericType>& planar_force) {
245 stream << planar_force.Print();
246 return stream;
247}
248
249template <typename NumericType>
251 const NumericType number, const PlanarForce<NumericType>& planar_force) {
252 return planar_force * number;
253}
254
255template <typename NumericType>
257 : PlanarDirection<NumericType>(planar_force.Value()) {}
258
259template <typename NumericType>
261 const PlanarForce<NumericType>& planar_force_1, const PlanarForce<NumericType>& planar_force_2)
262 : Angle<NumericType>(planar_force_1.Value(), planar_force_2.Value()) {}
263
264template <typename NumericType>
266 const ScalarForce<NumericType>& scalar_force) const {
267 return PlanarForce<NumericType>{scalar_force, *this};
268}
269
270template <typename NumericType>
272 const PlanarDirection<NumericType>& planar_direction) const {
273 return PlanarForce<NumericType>{*this, planar_direction};
274}
275
276} // namespace PhQ
277
278namespace std {
279
280template <typename NumericType>
281struct hash<PhQ::PlanarForce<NumericType>> {
282 inline size_t operator()(const PhQ::PlanarForce<NumericType>& planar_force) const {
283 return hash<PhQ::PlanarVector<NumericType>>()(planar_force.Value());
284 }
285};
286
287} // namespace std
288
289#endif // PHQ_PLANAR_FORCE_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.
Surface area or cross-sectional area. Can also represent a scalar component of a vector area or the m...
Definition Area.hpp:71
Abstract base class that represents any dimensional planar vector physical quantity....
PhQ::PlanarVector< NumericType > value
Value of this physical quantity expressed in its standard unit of measure.
static constexpr UnitType Unit()
Standard unit of measure for this physical quantity. This physical quantity's value is stored interna...
constexpr const PhQ::PlanarVector< NumericType > & Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
std::string Print() const
Prints this physical quantity as a string. This physical quantity's value is expressed in its standar...
constexpr const PhQ::Vector< NumericType > & Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
Three-dimensional Euclidean force vector. Contains three components in Cartesian coordinates: x,...
Definition Force.hpp:52
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 force vector in the XY plane. Contains two components in Cartesian coordina...
constexpr PlanarForce< NumericType > & operator=(const PlanarForce< NumericType > &other)=default
Copy assignment operator. Assigns this planar force vector by copying another one.
constexpr void operator+=(const PlanarForce< NumericType > &planar_force) noexcept
static constexpr PlanarForce< NumericType > Create(const PlanarVector< NumericType > &value)
Statically creates a planar force vector with a given value expressed in a given force unit.
PlanarForce(const ScalarForce< NumericType > &x, const ScalarForce< NumericType > &y)
Constructor. Constructs a planar force vector from a given set of scalar force components.
constexpr void operator*=(const NumericType number) noexcept
constexpr PlanarForce< NumericType > operator-(const PlanarForce< NumericType > &planar_force) const
constexpr void operator-=(const PlanarForce< NumericType > &planar_force) noexcept
constexpr PlanarForce< NumericType > & operator=(PlanarForce< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this planar force vector by moving another one.
ScalarForce< NumericType > Magnitude() const
Returns the magnitude of this planar force vector.
PhQ::Angle< NumericType > Angle(const PlanarForce< NumericType > &planar_force) const
Returns the angle between this planar force vector and another one.
constexpr ScalarForce< NumericType > y() const noexcept
Returns the y Cartesian component of this planar force vector.
constexpr PlanarForce(const ScalarForce< NumericType > &scalar_force, const PlanarDirection< NumericType > &planar_direction)
Constructor. Constructs a planar force vector from a given scalar force magnitude and planar directio...
constexpr PlanarForce< NumericType > & operator=(const PlanarForce< OtherNumericType > &other)
Copy assignment operator. Assigns this planar force vector by copying another one.
constexpr PlanarForce< NumericType > operator/(const NumericType number) const
~PlanarForce() noexcept=default
Destructor. Destroys this planar force vector.
PlanarForce()=default
Default constructor. Constructs a planar force vector with an uninitialized value.
constexpr PlanarForce< NumericType > operator+(const PlanarForce< NumericType > &planar_force) const
static constexpr PlanarForce< NumericType > Create(const std::array< NumericType, 2 > &x_y)
Statically creates a planar force vector from the given x and y Cartesian components expressed in a g...
static constexpr PlanarForce< NumericType > Zero()
Statically creates a planar force vector of zero.
PhQ::PlanarDirection< NumericType > PlanarDirection() const
Returns the planar direction of this planar force vector.
constexpr PlanarForce(const PlanarVector< NumericType > &value)
Constructor. Constructs a planar force vector with a given value expressed in the standard force unit...
static constexpr PlanarForce< NumericType > Create(const NumericType x, const NumericType y)
Statically creates a planar force vector from the given x and y Cartesian components expressed in a g...
constexpr PlanarForce< NumericType > operator*(const NumericType number) const
PlanarForce(const PlanarVector< NumericType > &value, const Unit::Force unit)
Constructor. Constructs a planar force vector with a given value expressed in a given force unit.
constexpr PlanarForce(PlanarForce< NumericType > &&other) noexcept=default
Move constructor. Constructs a planar force vector by moving another one.
constexpr ScalarForce< NumericType > x() const noexcept
Returns the x Cartesian component of this planar force vector.
constexpr void operator/=(const NumericType number) noexcept
Two-dimensional Euclidean traction vector in the XY plane. Contains two components in Cartesian coord...
Two-dimensional Euclidean vector in the XY plane. Contains two components in Cartesian coordinates: x...
static constexpr PlanarVector< NumericType > Zero()
Statically creates a two-dimensional planar vector with its x and y Cartesian components initialized ...
Scalar force component or magnitude of a force vector. For a three-dimensional Euclidean force vector...
constexpr ScalarForce< NumericType > operator*(const NumericType number) const
Force
Force units.
Definition Force.hpp:53
Namespace that encompasses all of the Physical Quantities library's content.
std::ostream & operator<<(std::ostream &stream, 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 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