Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
PhQ::Vector< NumericType > Class Template Reference

Three-dimensional Euclidean vector. Contains three components in Cartesian coordinates: x, y, and z. For a two-dimensional Euclidean vector in the XY plane, see PhQ::PlanarVector. For a three-dimensional Euclidean dyadic tensor, see PhQ::Dyad. For a three-dimensional symmetric Euclidean dyadic tensor, see PhQ::SymmetricDyad. More...

#include "Vector.hpp"

Public Member Functions

 Vector ()=default
 Default constructor. Constructs a three-dimensional vector with uninitialized x, y, and z Cartesian components. More...
 
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. More...
 
constexpr Vector (const std::array< NumericType, 3 > &x_y_z)
 Constructor. Constructs a three-dimensional vector from a given array representing its x, y, and z Cartesian components. More...
 
constexpr Vector (const PlanarVector< NumericType > &planar_vector)
 Constructor. Constructs a three-dimensional vector from a given two-dimensional planar vector in the XY plane. This vector's z-component is initialized to zero. More...
 
constexpr Vector (NumericType magnitude, const Direction< NumericType > &direction)
 Constructor. Constructs a three-dimensional vector given a magnitude and a direction. More...
 
 ~Vector () noexcept=default
 Destructor. Destroys this three-dimensional vector. More...
 
constexpr Vector (const Vector< NumericType > &other)=default
 Copy constructor. Constructs a three-dimensional vector by copying another one. More...
 
template<typename OtherNumericType >
constexpr Vector (const Vector< OtherNumericType > &other)
 Copy constructor. Constructs a three-dimensional vector by copying another one. More...
 
constexpr Vector (Vector< NumericType > &&other) noexcept=default
 Move constructor. Constructs a three-dimensional vector by moving another one. More...
 
constexpr Vector< NumericType > & operator= (const Vector< NumericType > &other)=default
 Copy assignment operator. Assigns this three-dimensional vector by copying another one. More...
 
template<typename OtherNumericType >
constexpr Vector< NumericType > & operator= (const Vector< OtherNumericType > &other)
 Copy assignment operator. Assigns this three-dimensional vector by copying another one. More...
 
constexpr Vector< NumericType > & operator= (Vector< NumericType > &&other) noexcept=default
 Move assignment operator. Assigns this three-dimensional vector by moving another one. More...
 
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 x, y, and z Cartesian components. More...
 
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. More...
 
constexpr NumericType x () const noexcept
 Returns this three-dimensional vector's x Cartesian component. More...
 
constexpr NumericType y () const noexcept
 Returns this three-dimensional vector's y Cartesian component. More...
 
constexpr NumericType z () const noexcept
 Returns this three-dimensional vector's z Cartesian component. More...
 
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. More...
 
constexpr NumericType & Mutable_x () noexcept
 Returns this three-dimensional vector's x Cartesian component as a mutable value. More...
 
constexpr NumericType & Mutable_y () noexcept
 Returns this three-dimensional vector's y Cartesian component as a mutable value. More...
 
constexpr NumericType & Mutable_z () noexcept
 Returns this three-dimensional vector's z Cartesian component as a mutable value. More...
 
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. More...
 
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. More...
 
constexpr void Set_x (const NumericType x) noexcept
 Sets this three-dimensional vector's x Cartesian component to a given value. More...
 
constexpr void Set_y (const NumericType y) noexcept
 Sets this three-dimensional vector's y Cartesian component to a given value. More...
 
constexpr void Set_z (const NumericType z) noexcept
 Sets this three-dimensional vector's z Cartesian component to a given value. More...
 
constexpr NumericType MagnitudeSquared () const noexcept
 Returns the square of the magnitude of this three-dimensional vector. More...
 
NumericType Magnitude () const noexcept
 Returns the magnitude (also known as the L2 norm) of this three-dimensional vector. More...
 
PhQ::Direction< NumericType > Direction () const
 Returns the direction of this three-dimensional vector. More...
 
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 vector and another one. More...
 
constexpr NumericType Dot (const PhQ::Direction< NumericType > &direction) const noexcept
 Returns the dot product (also known as the inner product or scalar product) of this three-dimensional vector and a given direction. More...
 
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 another one. More...
 
constexpr Vector< NumericType > Cross (const PhQ::Direction< NumericType > &direction) const
 Returns the cross product (also known as the vector product) of this three-dimensional vector and a given direction. More...
 
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 and another one. More...
 
constexpr Dyad< NumericType > Dyadic (const PhQ::Direction< NumericType > &direction) const
 Returns the dyadic tensor product (also known as the outer product) of this three-dimensional vector and a given direction. More...
 
PhQ::Angle< NumericType > Angle (const Vector< NumericType > &other) const
 Returns the angle between this three-dimensional vector and another one. More...
 
PhQ::Angle< NumericType > Angle (const PhQ::Direction< NumericType > &direction) const
 Returns the angle between this three-dimensional vector and a given direction. More...
 
std::string Print () const
 Prints this three-dimensional vector as a string. More...
 
std::string JSON () const
 Serializes this three-dimensional vector as a JSON message. More...
 
std::string XML () const
 Serializes this three-dimensional vector as an XML message. More...
 
std::string YAML () const
 Serializes this three-dimensional vector as a YAML message. More...
 
constexpr void operator+= (const Vector< NumericType > &other) noexcept
 Adds another three-dimensional vector to this one. More...
 
constexpr void operator-= (const Vector< NumericType > &other) noexcept
 Subtracts another three-dimensional vector from this one. More...
 
template<typename OtherNumericType >
constexpr void operator*= (const OtherNumericType number) noexcept
 Multiplies this three-dimensional vector by the given number. More...
 
template<typename OtherNumericType >
constexpr void operator/= (const OtherNumericType number) noexcept
 Divides this three-dimensional vector by the given number. More...
 

Static Public Member Functions

static constexpr Vector< NumericType > Zero ()
 Statically creates a three-dimensional vector with its x, y, and z Cartesian components initialized to zero. More...
 

Private Attributes

std::array< NumericType, 3 > x_y_z_
 Cartesian components of this three-dimensional vector. More...
 

Detailed Description

template<typename NumericType = double>
class PhQ::Vector< NumericType >

Three-dimensional Euclidean vector. Contains three components in Cartesian coordinates: x, y, and z. For a two-dimensional Euclidean vector in the XY plane, see PhQ::PlanarVector. For a three-dimensional Euclidean dyadic tensor, see PhQ::Dyad. For a three-dimensional symmetric Euclidean dyadic tensor, see PhQ::SymmetricDyad.

Template Parameters
NumericTypeFloating-point numeric type: float, double, or long double. Defaults to double if unspecified.

Definition at line 60 of file Vector.hpp.

Constructor & Destructor Documentation

◆ Vector() [1/8]

template<typename NumericType = double>
PhQ::Vector< NumericType >::Vector ( )
default

Default constructor. Constructs a three-dimensional vector with uninitialized x, y, and z Cartesian components.

◆ Vector() [2/8]

template<typename NumericType = double>
constexpr PhQ::Vector< NumericType >::Vector ( const NumericType  x,
const NumericType  y,
const NumericType  z 
)
inlineconstexpr

Constructor. Constructs a three-dimensional vector from the given x, y, and z Cartesian components.

Definition at line 72 of file Vector.hpp.

References PhQ::Vector< NumericType >::x(), PhQ::Vector< NumericType >::y(), and PhQ::Vector< NumericType >::z().

◆ Vector() [3/8]

template<typename NumericType = double>
constexpr PhQ::Vector< NumericType >::Vector ( const std::array< NumericType, 3 > &  x_y_z)
inlineexplicitconstexpr

Constructor. Constructs a three-dimensional vector from a given array representing its x, y, and z Cartesian components.

Definition at line 77 of file Vector.hpp.

◆ Vector() [4/8]

template<typename NumericType = double>
constexpr PhQ::Vector< NumericType >::Vector ( const PlanarVector< NumericType > &  planar_vector)
inlineexplicitconstexpr

Constructor. Constructs a three-dimensional vector from a given two-dimensional planar vector in the XY plane. This vector's z-component is initialized to zero.

Definition at line 81 of file Vector.hpp.

References PhQ::PlanarVector< NumericType >::x(), and PhQ::PlanarVector< NumericType >::y().

◆ Vector() [5/8]

template<typename NumericType >
constexpr PhQ::Vector< NumericType >::Vector ( NumericType  magnitude,
const Direction< NumericType > &  direction 
)
inlineconstexpr

Constructor. Constructs a three-dimensional vector given a magnitude and a direction.

Definition at line 372 of file Direction.hpp.

References PhQ::DimensionlessVector< NumericType >::Value(), and PhQ::Vector< NumericType >::x_y_z_.

◆ ~Vector()

template<typename NumericType = double>
PhQ::Vector< NumericType >::~Vector ( )
defaultnoexcept

Destructor. Destroys this three-dimensional vector.

◆ Vector() [6/8]

template<typename NumericType = double>
constexpr PhQ::Vector< NumericType >::Vector ( const Vector< NumericType > &  other)
constexprdefault

Copy constructor. Constructs a three-dimensional vector by copying another one.

◆ Vector() [7/8]

template<typename NumericType = double>
template<typename OtherNumericType >
constexpr PhQ::Vector< NumericType >::Vector ( const Vector< OtherNumericType > &  other)
inlineexplicitconstexpr

Copy constructor. Constructs a three-dimensional vector by copying another one.

Definition at line 95 of file Vector.hpp.

◆ Vector() [8/8]

template<typename NumericType = double>
constexpr PhQ::Vector< NumericType >::Vector ( Vector< NumericType > &&  other)
constexprdefaultnoexcept

Move constructor. Constructs a three-dimensional vector by moving another one.

Member Function Documentation

◆ Angle() [1/2]

template<typename NumericType >
Angle< NumericType > PhQ::Vector< NumericType >::Angle ( const PhQ::Direction< NumericType > &  direction) const
inline

Returns the angle between this three-dimensional vector and a given direction.

Definition at line 412 of file Direction.hpp.

◆ Angle() [2/2]

template<typename NumericType >
PhQ::Angle< NumericType > PhQ::Vector< NumericType >::Angle ( const Vector< NumericType > &  other) const
inline

Returns the angle between this three-dimensional vector and another one.

Definition at line 400 of file Angle.hpp.

◆ Cross() [1/2]

template<typename NumericType >
constexpr Vector< NumericType > PhQ::Vector< NumericType >::Cross ( const PhQ::Direction< NumericType > &  direction) const
inlineconstexpr

Returns the cross product (also known as the vector product) of this three-dimensional vector and a given direction.

Definition at line 388 of file Direction.hpp.

References PhQ::DimensionlessVector< NumericType >::Value().

◆ Cross() [2/2]

template<typename NumericType = double>
constexpr Vector<NumericType> PhQ::Vector< NumericType >::Cross ( const Vector< NumericType > &  other) const
inlineconstexpr

Returns the cross product (also known as the vector product) of this three-dimensional vector and another one.

Definition at line 229 of file Vector.hpp.

References PhQ::Vector< NumericType >::x_y_z_.

Referenced by PhQ::Direction< NumericType >::Cross().

◆ Direction()

template<typename NumericType >
PhQ::Direction< NumericType > PhQ::Vector< NumericType >::Direction
inline

◆ Dot() [1/2]

template<typename NumericType >
constexpr NumericType PhQ::Vector< NumericType >::Dot ( const PhQ::Direction< NumericType > &  direction) const
inlineconstexprnoexcept

Returns the dot product (also known as the inner product or scalar product) of this three-dimensional vector and a given direction.

Definition at line 382 of file Direction.hpp.

◆ Dot() [2/2]

template<typename NumericType = double>
constexpr NumericType PhQ::Vector< NumericType >::Dot ( const Vector< NumericType > &  other) const
inlineconstexprnoexcept

Returns the dot product (also known as the inner product or scalar product) of this three-dimensional vector and another one.

Definition at line 218 of file Vector.hpp.

References PhQ::Vector< NumericType >::x_y_z_.

Referenced by PhQ::Direction< NumericType >::Dot().

◆ Dyadic() [1/2]

template<typename NumericType >
constexpr Dyad< NumericType > PhQ::Vector< NumericType >::Dyadic ( const PhQ::Direction< NumericType > &  direction) const
inlineconstexpr

Returns the dyadic tensor product (also known as the outer product) of this three-dimensional vector and a given direction.

Definition at line 394 of file Direction.hpp.

References PhQ::DimensionlessVector< NumericType >::Value().

◆ Dyadic() [2/2]

template<typename NumericType >
constexpr Dyad< NumericType > PhQ::Vector< NumericType >::Dyadic ( const Vector< NumericType > &  other) const
inlineconstexpr

Returns the dyadic tensor product (also known as the outer product) of this three-dimensional vector and another one.

Definition at line 733 of file Dyad.hpp.

References PhQ::Vector< NumericType >::x_y_z_.

Referenced by PhQ::Direction< NumericType >::Dyadic().

◆ JSON()

template<typename NumericType = double>
std::string PhQ::Vector< NumericType >::JSON ( ) const
inline

Serializes this three-dimensional vector as a JSON message.

Definition at line 262 of file Vector.hpp.

References PhQ::Print(), and PhQ::Vector< NumericType >::x_y_z_.

◆ Magnitude()

template<typename NumericType = double>
NumericType PhQ::Vector< NumericType >::Magnitude ( ) const
inlinenoexcept

◆ MagnitudeSquared()

template<typename NumericType = double>
constexpr NumericType PhQ::Vector< NumericType >::MagnitudeSquared ( ) const
inlineconstexprnoexcept

Returns the square of the magnitude of this three-dimensional vector.

Definition at line 204 of file Vector.hpp.

References PhQ::Vector< NumericType >::x_y_z_.

Referenced by PhQ::Direction< NumericType >::MagnitudeSquared().

◆ Mutable_x()

template<typename NumericType = double>
constexpr NumericType& PhQ::Vector< NumericType >::Mutable_x ( )
inlineconstexprnoexcept

Returns this three-dimensional vector's x Cartesian component as a mutable value.

Definition at line 160 of file Vector.hpp.

References PhQ::Vector< NumericType >::x_y_z_.

◆ Mutable_x_y_z()

template<typename NumericType = double>
constexpr std::array<NumericType, 3>& PhQ::Vector< NumericType >::Mutable_x_y_z ( )
inlineconstexprnoexcept

Returns this three-dimensional vector's x, y, and z Cartesian components as a mutable array.

Definition at line 155 of file Vector.hpp.

References PhQ::Vector< NumericType >::x_y_z_.

Referenced by PhQ::ConvertInPlace().

◆ Mutable_y()

template<typename NumericType = double>
constexpr NumericType& PhQ::Vector< NumericType >::Mutable_y ( )
inlineconstexprnoexcept

Returns this three-dimensional vector's y Cartesian component as a mutable value.

Definition at line 165 of file Vector.hpp.

References PhQ::Vector< NumericType >::x_y_z_.

◆ Mutable_z()

template<typename NumericType = double>
constexpr NumericType& PhQ::Vector< NumericType >::Mutable_z ( )
inlineconstexprnoexcept

Returns this three-dimensional vector's z Cartesian component as a mutable value.

Definition at line 170 of file Vector.hpp.

References PhQ::Vector< NumericType >::x_y_z_.

◆ operator*=()

template<typename NumericType = double>
template<typename OtherNumericType >
constexpr void PhQ::Vector< NumericType >::operator*= ( const OtherNumericType  number)
inlineconstexprnoexcept

Multiplies this three-dimensional vector by the given number.

Template Parameters
OtherNumericTypeFloating-point numeric type of the given number. Deduced automatically.

Definition at line 297 of file Vector.hpp.

References PhQ::Vector< NumericType >::x_y_z_.

◆ operator+=()

template<typename NumericType = double>
constexpr void PhQ::Vector< NumericType >::operator+= ( const Vector< NumericType > &  other)
inlineconstexprnoexcept

Adds another three-dimensional vector to this one.

Definition at line 280 of file Vector.hpp.

References PhQ::Vector< NumericType >::x_y_z_.

◆ operator-=()

template<typename NumericType = double>
constexpr void PhQ::Vector< NumericType >::operator-= ( const Vector< NumericType > &  other)
inlineconstexprnoexcept

Subtracts another three-dimensional vector from this one.

Definition at line 287 of file Vector.hpp.

References PhQ::Vector< NumericType >::x_y_z_.

◆ operator/=()

template<typename NumericType = double>
template<typename OtherNumericType >
constexpr void PhQ::Vector< NumericType >::operator/= ( const OtherNumericType  number)
inlineconstexprnoexcept

Divides this three-dimensional vector by the given number.

Template Parameters
OtherNumericTypeFloating-point numeric type of the given number. Deduced automatically.

Definition at line 307 of file Vector.hpp.

References PhQ::Vector< NumericType >::x_y_z_.

◆ operator=() [1/4]

template<typename NumericType = double>
constexpr Vector<NumericType>& PhQ::Vector< NumericType >::operator= ( const std::array< NumericType, 3 > &  x_y_z)
inlineconstexpr

Assignment operator. Assigns this three-dimensional vector by copying a given array representing its x, y, and z Cartesian components.

Definition at line 119 of file Vector.hpp.

References PhQ::Vector< NumericType >::x_y_z(), and PhQ::Vector< NumericType >::x_y_z_.

◆ operator=() [2/4]

template<typename NumericType = double>
constexpr Vector<NumericType>& PhQ::Vector< NumericType >::operator= ( const Vector< NumericType > &  other)
constexprdefault

Copy assignment operator. Assigns this three-dimensional vector by copying another one.

◆ operator=() [3/4]

template<typename NumericType = double>
template<typename OtherNumericType >
constexpr Vector<NumericType>& PhQ::Vector< NumericType >::operator= ( const Vector< OtherNumericType > &  other)
inlineconstexpr

Copy assignment operator. Assigns this three-dimensional vector by copying another one.

Definition at line 107 of file Vector.hpp.

References PhQ::Vector< NumericType >::x(), PhQ::Vector< NumericType >::x_y_z_, PhQ::Vector< NumericType >::y(), and PhQ::Vector< NumericType >::z().

◆ operator=() [4/4]

template<typename NumericType = double>
constexpr Vector<NumericType>& PhQ::Vector< NumericType >::operator= ( Vector< NumericType > &&  other)
constexprdefaultnoexcept

Move assignment operator. Assigns this three-dimensional vector by moving another one.

◆ Print()

template<typename NumericType = double>
std::string PhQ::Vector< NumericType >::Print ( ) const
inline

Prints this three-dimensional vector as a string.

Definition at line 256 of file Vector.hpp.

References PhQ::Print(), and PhQ::Vector< NumericType >::x_y_z_.

Referenced by PhQ::operator<<().

◆ Set_x()

template<typename NumericType = double>
constexpr void PhQ::Vector< NumericType >::Set_x ( const NumericType  x)
inlineconstexprnoexcept

Sets this three-dimensional vector's x Cartesian component to a given value.

Definition at line 189 of file Vector.hpp.

References PhQ::Vector< NumericType >::x(), and PhQ::Vector< NumericType >::x_y_z_.

◆ Set_x_y_z() [1/2]

template<typename NumericType = double>
constexpr void PhQ::Vector< NumericType >::Set_x_y_z ( const NumericType  x,
const NumericType  y,
const NumericType  z 
)
inlineconstexprnoexcept

Sets this three-dimensional vector's x, y, and z Cartesian components to the given values.

Definition at line 182 of file Vector.hpp.

References PhQ::Vector< NumericType >::x(), PhQ::Vector< NumericType >::x_y_z_, PhQ::Vector< NumericType >::y(), and PhQ::Vector< NumericType >::z().

◆ Set_x_y_z() [2/2]

template<typename NumericType = double>
constexpr void PhQ::Vector< NumericType >::Set_x_y_z ( const std::array< NumericType, 3 > &  x_y_z)
inlineconstexprnoexcept

Sets this three-dimensional vector's x, y, and z Cartesian components to the given values.

Definition at line 176 of file Vector.hpp.

References PhQ::Vector< NumericType >::x_y_z(), and PhQ::Vector< NumericType >::x_y_z_.

◆ Set_y()

template<typename NumericType = double>
constexpr void PhQ::Vector< NumericType >::Set_y ( const NumericType  y)
inlineconstexprnoexcept

Sets this three-dimensional vector's y Cartesian component to a given value.

Definition at line 194 of file Vector.hpp.

References PhQ::Vector< NumericType >::x_y_z_, and PhQ::Vector< NumericType >::y().

◆ Set_z()

template<typename NumericType = double>
constexpr void PhQ::Vector< NumericType >::Set_z ( const NumericType  z)
inlineconstexprnoexcept

Sets this three-dimensional vector's z Cartesian component to a given value.

Definition at line 199 of file Vector.hpp.

References PhQ::Vector< NumericType >::x_y_z_, and PhQ::Vector< NumericType >::z().

◆ x()

template<typename NumericType = double>
constexpr NumericType PhQ::Vector< NumericType >::x ( ) const
inlineconstexprnoexcept

◆ x_y_z()

template<typename NumericType = double>
constexpr const std::array<NumericType, 3>& PhQ::Vector< NumericType >::x_y_z ( ) const
inlineconstexprnoexcept

Returns this three-dimensional vector's x, y, and z Cartesian components as an array.

Definition at line 134 of file Vector.hpp.

References PhQ::Vector< NumericType >::x_y_z_.

Referenced by PhQ::Convert(), PhQ::ConvertStatically(), PhQ::Vector< NumericType >::operator=(), PhQ::Direction< NumericType >::Set(), and PhQ::Vector< NumericType >::Set_x_y_z().

◆ XML()

template<typename NumericType = double>
std::string PhQ::Vector< NumericType >::XML ( ) const
inline

Serializes this three-dimensional vector as an XML message.

Definition at line 268 of file Vector.hpp.

References PhQ::Print(), and PhQ::Vector< NumericType >::x_y_z_.

◆ y()

template<typename NumericType = double>
constexpr NumericType PhQ::Vector< NumericType >::y ( ) const
inlineconstexprnoexcept

◆ YAML()

template<typename NumericType = double>
std::string PhQ::Vector< NumericType >::YAML ( ) const
inline

Serializes this three-dimensional vector as a YAML message.

Definition at line 274 of file Vector.hpp.

References PhQ::Print(), and PhQ::Vector< NumericType >::x_y_z_.

◆ z()

template<typename NumericType = double>
constexpr NumericType PhQ::Vector< NumericType >::z ( ) const
inlineconstexprnoexcept

◆ Zero()

template<typename NumericType = double>
static constexpr Vector<NumericType> PhQ::Vector< NumericType >::Zero ( )
inlinestaticconstexpr

Member Data Documentation

◆ x_y_z_

template<typename NumericType = double>
std::array<NumericType, 3> PhQ::Vector< NumericType >::x_y_z_
private

The documentation for this class was generated from the following files: