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
Vector.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_VECTOR_HPP
26#define PHQ_VECTOR_HPP
27
28#include <array>
29#include <cmath>
30#include <cstddef>
31#include <functional>
32#include <ostream>
33#include <string>
34#include <type_traits>
35
36#include "Base.hpp"
37#include "PlanarVector.hpp"
38
39namespace PhQ {
40
41// Forward declarations for class PhQ::Vector.
42template <typename NumericType>
43class Angle;
44
45// Forward declaration for class PhQ::Vector.
46template <typename NumericType>
47class Direction;
48
49// Forward declaration for class PhQ::Vector.
50template <typename>
51class Dyad;
52
53/// \brief Three-dimensional Euclidean vector. Contains three components in Cartesian coordinates:
54/// x, y, and z. For a two-dimensional Euclidean vector in the XY plane, see PhQ::PlanarVector. For
55/// a three-dimensional Euclidean dyadic tensor, see PhQ::Dyad. For a three-dimensional symmetric
56/// Euclidean dyadic tensor, see PhQ::SymmetricDyad.
57/// \tparam NumericType Floating-point numeric type: float, double, or long double. Defaults to
58/// double if unspecified.
59template <typename NumericType = double>
60class Vector {
61 static_assert(std::is_floating_point<NumericType>::value,
62 "The NumericType template parameter of PhQ::Vector<NumericType> must be a numeric "
63 "floating-point type: float, double, or long double.");
64
65public:
66 /// \brief Default constructor. Constructs a three-dimensional vector with uninitialized x, y, and
67 /// z Cartesian components.
68 Vector() = default;
69
70 /// \brief Constructor. Constructs a three-dimensional vector from the given x, y, and z Cartesian
71 /// components.
72 constexpr Vector(const NumericType x, const NumericType y, const NumericType z)
73 : x_y_z_({x, y, z}) {}
74
75 /// \brief Constructor. Constructs a three-dimensional vector from a given array representing its
76 /// x, y, and z Cartesian components.
77 explicit constexpr Vector(const std::array<NumericType, 3>& x_y_z) : x_y_z_(x_y_z) {}
78
79 /// \brief Constructor. Constructs a three-dimensional vector from a given two-dimensional planar
80 /// vector in the XY plane. This vector's z-component is initialized to zero.
81 explicit constexpr Vector(const PlanarVector<NumericType>& planar_vector)
82 : x_y_z_({planar_vector.x(), planar_vector.y(), static_cast<NumericType>(0)}) {}
84 /// \brief Constructor. Constructs a three-dimensional vector given a magnitude and a direction.
85 constexpr Vector(NumericType magnitude, const Direction<NumericType>& direction);
86
87 /// \brief Destructor. Destroys this three-dimensional vector.
88 ~Vector() noexcept = default;
89
90 /// \brief Copy constructor. Constructs a three-dimensional vector by copying another one.
91 constexpr Vector(const Vector<NumericType>& other) = default;
92
93 /// \brief Copy constructor. Constructs a three-dimensional vector by copying another one.
94 template <typename OtherNumericType>
95 explicit constexpr Vector(const Vector<OtherNumericType>& other)
96 : x_y_z_({static_cast<NumericType>(other.x()), static_cast<NumericType>(other.y()),
97 static_cast<NumericType>(other.z())}) {}
98
99 /// \brief Move constructor. Constructs a three-dimensional vector by moving another one.
100 constexpr Vector(Vector<NumericType>&& other) noexcept = default;
101
102 /// \brief Copy assignment operator. Assigns this three-dimensional vector by copying another one.
103 constexpr Vector<NumericType>& operator=(const Vector<NumericType>& other) = default;
104
105 /// \brief Copy assignment operator. Assigns this three-dimensional vector by copying another one.
106 template <typename OtherNumericType>
108 x_y_z_[0] = static_cast<NumericType>(other.x());
109 x_y_z_[1] = static_cast<NumericType>(other.y());
110 x_y_z_[2] = static_cast<NumericType>(other.z());
111 return *this;
112 }
113
114 /// \brief Move assignment operator. Assigns this three-dimensional vector by moving another one.
115 constexpr Vector<NumericType>& operator=(Vector<NumericType>&& other) noexcept = default;
116
117 /// \brief Assignment operator. Assigns this three-dimensional vector by copying a given array
118 /// representing its x, y, and z Cartesian components.
119 constexpr Vector<NumericType>& operator=(const std::array<NumericType, 3>& x_y_z) {
120 x_y_z_ = x_y_z;
121 return *this;
122 }
123
124 /// \brief Statically creates a three-dimensional vector with its x, y, and z Cartesian components
125 /// initialized to zero.
126 [[nodiscard]] static constexpr Vector<NumericType> Zero() {
127 return Vector<NumericType>{
128 std::array<NumericType, 3>{
129 static_cast<NumericType>(0), static_cast<NumericType>(0), static_cast<NumericType>(0)}
130 };
131 }
132
133 /// \brief Returns this three-dimensional vector's x, y, and z Cartesian components as an array.
134 [[nodiscard]] constexpr const std::array<NumericType, 3>& x_y_z() const noexcept {
135 return x_y_z_;
136 }
137
138 /// \brief Returns this three-dimensional vector's x Cartesian component.
139 [[nodiscard]] constexpr NumericType x() const noexcept {
140 return x_y_z_[0];
141 }
142
143 /// \brief Returns this three-dimensional vector's y Cartesian component.
144 [[nodiscard]] constexpr NumericType y() const noexcept {
145 return x_y_z_[1];
146 }
147
148 /// \brief Returns this three-dimensional vector's z Cartesian component.
149 [[nodiscard]] constexpr NumericType z() const noexcept {
150 return x_y_z_[2];
151 }
152
153 /// \brief Returns this three-dimensional vector's x, y, and z Cartesian components as a mutable
154 /// array.
155 [[nodiscard]] constexpr std::array<NumericType, 3>& Mutable_x_y_z() noexcept {
156 return x_y_z_;
157 }
158
159 /// \brief Returns this three-dimensional vector's x Cartesian component as a mutable value.
160 [[nodiscard]] constexpr NumericType& Mutable_x() noexcept {
161 return x_y_z_[0];
162 }
163
164 /// \brief Returns this three-dimensional vector's y Cartesian component as a mutable value.
165 [[nodiscard]] constexpr NumericType& Mutable_y() noexcept {
166 return x_y_z_[1];
167 }
168
169 /// \brief Returns this three-dimensional vector's z Cartesian component as a mutable value.
170 [[nodiscard]] constexpr NumericType& Mutable_z() noexcept {
171 return x_y_z_[2];
172 }
173
174 /// \brief Sets this three-dimensional vector's x, y, and z Cartesian components to the given
175 /// values.
176 constexpr void Set_x_y_z(const std::array<NumericType, 3>& x_y_z) noexcept {
177 x_y_z_ = x_y_z;
178 }
179
180 /// \brief Sets this three-dimensional vector's x, y, and z Cartesian components to the given
181 /// values.
182 constexpr void Set_x_y_z(const NumericType x, const NumericType y, const NumericType z) noexcept {
183 x_y_z_[0] = x;
184 x_y_z_[1] = y;
185 x_y_z_[2] = z;
186 }
187
188 /// \brief Sets this three-dimensional vector's x Cartesian component to a given value.
189 constexpr void Set_x(const NumericType x) noexcept {
190 x_y_z_[0] = x;
191 }
192
193 /// \brief Sets this three-dimensional vector's y Cartesian component to a given value.
194 constexpr void Set_y(const NumericType y) noexcept {
195 x_y_z_[1] = y;
196 }
197
198 /// \brief Sets this three-dimensional vector's z Cartesian component to a given value.
199 constexpr void Set_z(const NumericType z) noexcept {
200 x_y_z_[2] = z;
201 }
202
203 /// \brief Returns the square of the magnitude of this three-dimensional vector.
204 [[nodiscard]] constexpr NumericType MagnitudeSquared() const noexcept {
205 return x_y_z_[0] * x_y_z_[0] + x_y_z_[1] * x_y_z_[1] + x_y_z_[2] * x_y_z_[2];
206 }
207
208 /// \brief Returns the magnitude (also known as the L2 norm) of this three-dimensional vector.
209 [[nodiscard]] NumericType Magnitude() const noexcept {
210 return std::sqrt(MagnitudeSquared());
211 }
212
213 /// \brief Returns the direction of this three-dimensional vector.
214 [[nodiscard]] PhQ::Direction<NumericType> Direction() const;
215
216 /// \brief Returns the dot product (also known as the inner product or scalar product) of this
217 /// three-dimensional vector and another one.
218 [[nodiscard]] constexpr NumericType Dot(const Vector<NumericType>& other) const noexcept {
219 return x_y_z_[0] * other.x_y_z_[0] + x_y_z_[1] * other.x_y_z_[1] + x_y_z_[2] * other.x_y_z_[2];
220 }
221
222 /// \brief Returns the dot product (also known as the inner product or scalar product) of this
223 /// three-dimensional vector and a given direction.
224 [[nodiscard]] constexpr NumericType Dot(
225 const PhQ::Direction<NumericType>& direction) const noexcept;
226
227 /// \brief Returns the cross product (also known as the vector product) of this three-dimensional
228 /// vector and another one.
229 [[nodiscard]] constexpr Vector<NumericType> Cross(const Vector<NumericType>& other) const {
230 return Vector<NumericType>{x_y_z_[1] * other.x_y_z_[2] - x_y_z_[2] * other.x_y_z_[1],
231 x_y_z_[2] * other.x_y_z_[0] - x_y_z_[0] * other.x_y_z_[2],
232 x_y_z_[0] * other.x_y_z_[1] - x_y_z_[1] * other.x_y_z_[0]};
233 }
234
235 /// \brief Returns the cross product (also known as the vector product) of this three-dimensional
236 /// vector and a given direction.
237 [[nodiscard]] constexpr Vector<NumericType> Cross(
238 const PhQ::Direction<NumericType>& direction) const;
239
240 /// \brief Returns the dyadic tensor product (also known as the outer product) of this
241 /// three-dimensional vector and another one.
242 [[nodiscard]] constexpr Dyad<NumericType> Dyadic(const Vector<NumericType>& other) const;
243
244 /// \brief Returns the dyadic tensor product (also known as the outer product) of this
245 /// three-dimensional vector and a given direction.
246 [[nodiscard]] constexpr Dyad<NumericType> Dyadic(
247 const PhQ::Direction<NumericType>& direction) const;
248
249 /// \brief Returns the angle between this three-dimensional vector and another one.
250 [[nodiscard]] PhQ::Angle<NumericType> Angle(const Vector<NumericType>& other) const;
251
252 /// \brief Returns the angle between this three-dimensional vector and a given direction.
253 [[nodiscard]] PhQ::Angle<NumericType> Angle(const PhQ::Direction<NumericType>& direction) const;
254
255 /// \brief Prints this three-dimensional vector as a string.
256 [[nodiscard]] std::string Print() const {
257 return "(" + PhQ::Print(x_y_z_[0]) + ", " + PhQ::Print(x_y_z_[1]) + ", " + PhQ::Print(x_y_z_[2])
258 + ")";
259 }
260
261 /// \brief Serializes this three-dimensional vector as a JSON message.
262 [[nodiscard]] std::string JSON() const {
263 return "{\"x\":" + PhQ::Print(x_y_z_[0]) + ",\"y\":" + PhQ::Print(x_y_z_[1])
264 + ",\"z\":" + PhQ::Print(x_y_z_[2]) + "}";
265 }
266
267 /// \brief Serializes this three-dimensional vector as an XML message.
268 [[nodiscard]] std::string XML() const {
269 return "<x>" + PhQ::Print(x_y_z_[0]) + "</x><y>" + PhQ::Print(x_y_z_[1]) + "</y><z>"
270 + PhQ::Print(x_y_z_[2]) + "</z>";
271 }
272
273 /// \brief Serializes this three-dimensional vector as a YAML message.
274 [[nodiscard]] std::string YAML() const {
275 return "{x:" + PhQ::Print(x_y_z_[0]) + ",y:" + PhQ::Print(x_y_z_[1])
276 + ",z:" + PhQ::Print(x_y_z_[2]) + "}";
277 }
278
279 /// \brief Adds another three-dimensional vector to this one.
280 constexpr void operator+=(const Vector<NumericType>& other) noexcept {
281 x_y_z_[0] += other.x_y_z_[0];
282 x_y_z_[1] += other.x_y_z_[1];
283 x_y_z_[2] += other.x_y_z_[2];
284 }
285
286 /// \brief Subtracts another three-dimensional vector from this one.
287 constexpr void operator-=(const Vector<NumericType>& other) noexcept {
288 x_y_z_[0] -= other.x_y_z_[0];
289 x_y_z_[1] -= other.x_y_z_[1];
290 x_y_z_[2] -= other.x_y_z_[2];
291 }
292
293 /// \brief Multiplies this three-dimensional vector by the given number.
294 /// \tparam OtherNumericType Floating-point numeric type of the given number. Deduced
295 /// automatically.
296 template <typename OtherNumericType>
297 constexpr void operator*=(const OtherNumericType number) noexcept {
298 x_y_z_[0] *= static_cast<NumericType>(number);
299 x_y_z_[1] *= static_cast<NumericType>(number);
300 x_y_z_[2] *= static_cast<NumericType>(number);
301 }
302
303 /// \brief Divides this three-dimensional vector by the given number.
304 /// \tparam OtherNumericType Floating-point numeric type of the given number. Deduced
305 /// automatically.
306 template <typename OtherNumericType>
307 constexpr void operator/=(const OtherNumericType number) noexcept {
308 x_y_z_[0] /= static_cast<NumericType>(number);
309 x_y_z_[1] /= static_cast<NumericType>(number);
310 x_y_z_[2] /= static_cast<NumericType>(number);
311 }
312
313private:
314 /// \brief Cartesian components of this three-dimensional vector.
315 std::array<NumericType, 3> x_y_z_;
316};
317
318template <typename NumericType>
319inline constexpr bool operator==(
320 const Vector<NumericType>& left, const Vector<NumericType>& right) noexcept {
321 return left.x() == right.x() && left.y() == right.y() && left.z() == right.z();
322}
323
324template <typename NumericType>
325inline constexpr bool operator!=(
326 const Vector<NumericType>& left, const Vector<NumericType>& right) noexcept {
327 return left.x() != right.x() || left.y() != right.y() || left.z() != right.z();
328}
329
330template <typename NumericType>
331inline constexpr bool operator<(
332 const Vector<NumericType>& left, const Vector<NumericType>& right) noexcept {
333 if (left.x() != right.x()) {
334 return left.x() < right.x();
335 }
336 if (left.y() != right.y()) {
337 return left.y() < right.y();
338 }
339 return left.z() < right.z();
340}
341
342template <typename NumericType>
343inline constexpr bool operator>(
344 const Vector<NumericType>& left, const Vector<NumericType>& right) noexcept {
345 if (left.x() != right.x()) {
346 return left.x() > right.x();
347 }
348 if (left.y() != right.y()) {
349 return left.y() > right.y();
350 }
351 return left.z() > right.z();
352}
353
354template <typename NumericType>
355inline constexpr bool operator<=(
356 const Vector<NumericType>& left, const Vector<NumericType>& right) noexcept {
357 return !(left > right);
358}
359
360template <typename NumericType>
361inline constexpr bool operator>=(
362 const Vector<NumericType>& left, const Vector<NumericType>& right) noexcept {
363 return !(left < right);
364}
365
366template <typename NumericType>
368 const Vector<NumericType>& left, const Vector<NumericType>& right) {
369 return Vector<NumericType>{left.x() + right.x(), left.y() + right.y(), left.z() + right.z()};
370}
371
372template <typename NumericType>
374 const Vector<NumericType>& left, const Vector<NumericType>& right) {
375 return Vector<NumericType>{left.x() - right.x(), left.y() - right.y(), left.z() - right.z()};
376}
377
378template <typename NumericType, typename OtherNumericType>
380 const Vector<NumericType>& vector, const OtherNumericType number) {
381 return Vector<NumericType>{
382 vector.x() * static_cast<NumericType>(number), vector.y() * static_cast<NumericType>(number),
383 vector.z() * static_cast<NumericType>(number)};
384}
385
386template <typename NumericType, typename OtherNumericType>
388 const OtherNumericType number, const Vector<NumericType>& vector) {
389 return Vector<NumericType>{vector * number};
390}
391
392template <typename NumericType, typename OtherNumericType>
394 const Vector<NumericType>& vector, const OtherNumericType number) {
395 return Vector<NumericType>{
396 vector.x() / static_cast<NumericType>(number), vector.y() / static_cast<NumericType>(number),
397 vector.z() / static_cast<NumericType>(number)};
398}
399
400template <typename NumericType>
401inline std::ostream& operator<<(std::ostream& stream, const Vector<NumericType>& vector) {
402 stream << vector.Print();
403 return stream;
404}
405
406template <typename NumericType>
408 : x_y_({vector.x(), vector.y()}) {}
409
410template <typename NumericType>
412 const PlanarVector<NumericType>& other) const {
413 return Vector<NumericType>{static_cast<NumericType>(0), static_cast<NumericType>(0),
414 x_y_[0] * other.x_y_[1] - x_y_[1] * other.x_y_[0]};
415}
416
417} // namespace PhQ
418
419namespace std {
420
421template <typename NumericType>
422struct hash<PhQ::Vector<NumericType>> {
423 inline size_t operator()(const PhQ::Vector<NumericType>& vector) const {
424 size_t result{17};
425 result = static_cast<size_t>(31) * result + hash<NumericType>()(vector.x());
426 result = static_cast<size_t>(31) * result + hash<NumericType>()(vector.y());
427 result = static_cast<size_t>(31) * result + hash<NumericType>()(vector.z());
428 return result;
429 }
430};
431
432} // namespace std
433
434#endif // PHQ_VECTOR_HPP
Plane angle between two lines or dihedral angle between two planes.
Definition Angle.hpp:130
Three-dimensional Euclidean direction vector. Contains three components in Cartesian coordinates: x,...
Three-dimensional Euclidean dyadic tensor. Contains nine components in Cartesian coordinates: xx,...
Definition Dyad.hpp:51
Two-dimensional Euclidean vector in the XY plane. Contains two components in Cartesian coordinates: x...
constexpr Vector< NumericType > Cross(const PlanarVector< NumericType > &other) const
Returns the cross product (also known as the vector product) of this two-dimensional planar vector an...
Definition Vector.hpp:411
constexpr NumericType x() const noexcept
Returns this two-dimensional planar vector's x Cartesian component.
PlanarVector()=default
Default constructor. Constructs a two-dimensional planar vector with uninitialized x and y Cartesian ...
std::array< NumericType, 2 > x_y_
Cartesian components of this two-dimensional planar vector.
constexpr NumericType y() const noexcept
Returns this two-dimensional planar vector's y Cartesian component.
Three-dimensional Euclidean vector. Contains three components in Cartesian coordinates: x,...
Definition Vector.hpp:60
constexpr const std::array< NumericType, 3 > & x_y_z() const noexcept
Returns this three-dimensional vector's x, y, and z Cartesian components as an array.
Definition Vector.hpp:134
constexpr void Set_z(const NumericType z) noexcept
Sets this three-dimensional vector's z Cartesian component to a given value.
Definition Vector.hpp:199
std::string XML() const
Serializes this three-dimensional vector as an XML message.
Definition Vector.hpp:268
NumericType Magnitude() const noexcept
Returns the magnitude (also known as the L2 norm) of this three-dimensional vector.
Definition Vector.hpp:209
constexpr Vector< NumericType > Cross(const Vector< NumericType > &other) const
Returns the cross product (also known as the vector product) of this three-dimensional vector and ano...
Definition Vector.hpp:229
std::string JSON() const
Serializes this three-dimensional vector as a JSON message.
Definition Vector.hpp:262
std::string Print() const
Prints this three-dimensional vector as a string.
Definition Vector.hpp:256
constexpr Vector< NumericType > & operator=(Vector< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this three-dimensional vector by moving another one.
constexpr void Set_x(const NumericType x) noexcept
Sets this three-dimensional vector's x Cartesian component to a given value.
Definition Vector.hpp:189
constexpr NumericType Dot(const Vector< NumericType > &other) const noexcept
Returns the dot product (also known as the inner product or scalar product) of this three-dimensional...
Definition Vector.hpp:218
constexpr NumericType & Mutable_z() noexcept
Returns this three-dimensional vector's z Cartesian component as a mutable value.
Definition Vector.hpp:170
constexpr Vector(const std::array< NumericType, 3 > &x_y_z)
Constructor. Constructs a three-dimensional vector from a given array representing its x,...
Definition Vector.hpp:77
~Vector() noexcept=default
Destructor. Destroys this three-dimensional vector.
constexpr NumericType & Mutable_y() noexcept
Returns this three-dimensional vector's y Cartesian component as a mutable value.
Definition Vector.hpp:165
constexpr Vector(Vector< NumericType > &&other) noexcept=default
Move constructor. Constructs a three-dimensional vector by moving another one.
constexpr NumericType MagnitudeSquared() const noexcept
Returns the square of the magnitude of this three-dimensional vector.
Definition Vector.hpp:204
constexpr void Set_x_y_z(const NumericType x, const NumericType y, const NumericType z) noexcept
Sets this three-dimensional vector's x, y, and z Cartesian components to the given values.
Definition Vector.hpp:182
std::string YAML() const
Serializes this three-dimensional vector as a YAML message.
Definition Vector.hpp:274
constexpr void Set_y(const NumericType y) noexcept
Sets this three-dimensional vector's y Cartesian component to a given value.
Definition Vector.hpp:194
constexpr NumericType & Mutable_x() noexcept
Returns this three-dimensional vector's x Cartesian component as a mutable value.
Definition Vector.hpp:160
constexpr void operator-=(const Vector< NumericType > &other) noexcept
Subtracts another three-dimensional vector from this one.
Definition Vector.hpp:287
constexpr NumericType x() const noexcept
Returns this three-dimensional vector's x Cartesian component.
Definition Vector.hpp:139
std::array< NumericType, 3 > x_y_z_
Cartesian components of this three-dimensional vector.
Definition Vector.hpp:315
constexpr void Set_x_y_z(const std::array< NumericType, 3 > &x_y_z) noexcept
Sets this three-dimensional vector's x, y, and z Cartesian components to the given values.
Definition Vector.hpp:176
constexpr Vector< NumericType > & operator=(const Vector< NumericType > &other)=default
Copy assignment operator. Assigns this three-dimensional vector by copying another one.
Vector()=default
Default constructor. Constructs a three-dimensional vector with uninitialized x, y,...
PhQ::Direction< NumericType > Direction() const
Returns the direction of this three-dimensional vector.
constexpr Vector< NumericType > & operator=(const Vector< OtherNumericType > &other)
Copy assignment operator. Assigns this three-dimensional vector by copying another one.
Definition Vector.hpp:107
constexpr void operator+=(const Vector< NumericType > &other) noexcept
Adds another three-dimensional vector to this one.
Definition Vector.hpp:280
constexpr Vector(const PlanarVector< NumericType > &planar_vector)
Constructor. Constructs a three-dimensional vector from a given two-dimensional planar vector in the ...
Definition Vector.hpp:81
constexpr Dyad< NumericType > Dyadic(const Vector< NumericType > &other) const
Returns the dyadic tensor product (also known as the outer product) of this three-dimensional vector ...
Definition Dyad.hpp:731
constexpr NumericType y() const noexcept
Returns this three-dimensional vector's y Cartesian component.
Definition Vector.hpp:144
constexpr void operator/=(const OtherNumericType number) noexcept
Divides this three-dimensional vector by the given number.
Definition Vector.hpp:307
constexpr std::array< NumericType, 3 > & Mutable_x_y_z() noexcept
Returns this three-dimensional vector's x, y, and z Cartesian components as a mutable array.
Definition Vector.hpp:155
constexpr Vector< NumericType > & operator=(const std::array< NumericType, 3 > &x_y_z)
Assignment operator. Assigns this three-dimensional vector by copying a given array representing its ...
Definition Vector.hpp:119
constexpr void operator*=(const OtherNumericType number) noexcept
Multiplies this three-dimensional vector by the given number.
Definition Vector.hpp:297
constexpr Vector(const NumericType x, const NumericType y, const NumericType z)
Constructor. Constructs a three-dimensional vector from the given x, y, and z Cartesian components.
Definition Vector.hpp:72
constexpr NumericType z() const noexcept
Returns this three-dimensional vector's z Cartesian component.
Definition Vector.hpp:149
static constexpr Vector< NumericType > Zero()
Statically creates a three-dimensional vector with its x, y, and z Cartesian components initialized t...
Definition Vector.hpp:126
Angle
Angle units.
Definition Angle.hpp:53
Namespace that encompasses all of the Physical Quantities library's content.
std::ostream & operator<<(std::ostream &stream, const Acceleration< NumericType > &acceleration)
constexpr Dyad< NumericType > operator+(const Dyad< NumericType > &left, const Dyad< NumericType > &right)
Definition Dyad.hpp:568
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 Dyad< NumericType > operator-(const Dyad< NumericType > &left, const Dyad< NumericType > &right)
Definition Dyad.hpp:576
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
std::string Print(const NumericType value)
Prints a given floating-point number as a string. Prints enough digits to represent the number exactl...
Definition Base.hpp:170