Efficient, generic implementation of a 3-dimensional vector.
The Vector3 class is the representation of a 3D vector with a total of 3 statically allocated elements of arbitrary type. The naming convention of the elements is as follows:
\f[\left(\begin{array}{*{3}{c}} x & y & z \\ \end{array}\right)\f]
These elements can be accessed directly with the subscript operator. The numbering of the vector elements is
\f[\left(\begin{array}{*{3}{c}} 0 & 1 & 2 \\ \end{array}\right)\f]
#include <Types.h>
Public Types | |
using | Length = typename SqrtTrait< Type >::Type |
Return type of the Vector3<Type>::length function. More... | |
using | value_type = Type |
Public Member Functions | |
constexpr | Vector3 ()=default |
constexpr | Vector3 (Type init) |
Constructor for a homogenous initialization of all elements. More... | |
template<typename Other > | |
constexpr | Vector3 (Other init) |
constexpr | Vector3 (Type x, Type y, Type z) |
Constructor for a direct initialization of all vector elements. More... | |
constexpr | Vector3 (const Type *init) |
Constructor for an array initializer. More... | |
constexpr | Vector3 (const Vector3 &v)=default |
template<typename Other > | |
constexpr | Vector3 (const Vector3< Other > &v) |
Conversion constructor from different Vector3 instances. More... | |
template<typename Other > | |
Vector3< Type > & | operator= (const Vector3< Other > &v) |
template<typename Other > | |
Vector3< Type > & | operator%= (const Vector3< Other > &rhs) |
template<typename Other > | |
Vector3< Type > & | operator+= (const Vector3< Other > &rhs) |
template<typename Other > | |
Vector3< Type > & | operator-= (const Vector3< Other > &rhs) |
template<typename Other > | |
Vector3< Type > & | operator*= (Other rhs) |
template<typename Other > | |
Vector3< Type > & | operator/= (Other rhs) |
Operators | |
Vector3 & | operator= (const Vector3 &v)=default |
template<typename Other > | |
Vector3 & | operator= (const Vector3< Other > &v) |
Assignment operator for different Vector3 instances. More... | |
template<typename Other > | |
bool | operator== (Other rhs) const |
Equality operator for the comparison of a vector and a scalar value. More... | |
template<typename Other > | |
bool | operator== (const Vector3< Other > &rhs) const |
Equality operator for the comparison of two vectors. More... | |
template<typename Other > | |
bool | operator!= (Other rhs) const |
Inequality operator for the comparison of a vector and a scalar value. More... | |
template<typename Other > | |
bool | operator!= (const Vector3< Other > &rhs) const |
Inequality operator for the comparison of two vectors. More... | |
Type & | operator[] (uint_t index) |
Subscript operator for the direct access to the vector elements. More... | |
const Type & | operator[] (uint_t index) const |
Subscript operator for the direct access to the vector elements. More... | |
Arithmetic operators | |
The return type of the arithmetic operators depends on the involved data types of the vectors. HIGH denotes the more significant data type of the arithmetic operation (for further detail see the MathTrait class description). | |
Vector3 | operator- () const |
Unary minus operator for the inversion of a vector ( \( \vec{a} = -\vec{b} \)). More... | |
template<typename Other > | |
Vector3 & | operator%= (const Vector3< Other > &rhs) |
Cross product (outer product) of two vectors ( \( \vec{a}=\vec{b}\times\vec{c} \)). More... | |
template<typename Other > | |
Vector3 & | operator+= (const Vector3< Other > &rhs) |
Addition assignment operator for the addition of two vectors ( \( \vec{a}+=\vec{b} \)). More... | |
template<typename Other > | |
Vector3 & | operator-= (const Vector3< Other > &rhs) |
Subtraction assignment operator for the subtraction of two vectors. More... | |
template<typename Other > | |
Vector3 & | operator*= (Other rhs) |
Multiplication assignment operator for the multiplication between a vector and. More... | |
template<typename Other > | |
Vector3 & | operator/= (Other rhs) |
Division assignment operator for the division of a vector by a scalar value. More... | |
template<typename Other > | |
Vector3< typename MathTrait< Type, Other >::High > | operator% (const Vector3< Other > &rhs) const |
Cross product (outer product) of two vectors ( \( \vec{a}=\vec{b}\times\vec{c} \)). More... | |
template<typename Other > | |
Vector3< typename MathTrait< Type, Other >::High > | operator+ (const Vector3< Other > &rhs) const |
Addition operator for the addition of two vectors ( \( \vec{a}=\vec{b}+\vec{c} \)). More... | |
template<typename Other > | |
Vector3< typename MathTrait< Type, Other >::High > | operator- (const Vector3< Other > &rhs) const |
Subtraction operator for the subtraction of two vectors ( \( \vec{a}=\vec{b}-\vec{c} \)). More... | |
template<typename Other > | |
Vector3< typename MathTrait< Type, Other >::High > | operator* (Other rhs) const |
Multiplication operator for the multiplication of a vector and a scalar value. More... | |
template<typename Other > | |
MathTrait< Type, Other >::High | operator* (const Vector3< Other > &rhs) const |
Multiplication operator for the scalar product (inner product) of two vectors. More... | |
template<typename Other > | |
Vector3< typename MathTrait< Type, Other >::High > | operator/ (Other rhs) const |
Division operator for the division of a vector by a scalar value. More... | |
Utility functions | |
uint_t | indexOfMax () const |
Returns index of absolute maximum value. More... | |
uint_t | indexOfMin () const |
Returns index of absolute minimum value. More... | |
Type | max () const |
Returns maximum value. More... | |
Type | min () const |
Returns minimum value. More... | |
void | set (Type x, Type y, Type z) |
Set function for a direct assignment of all vector elements. More... | |
Length | length () const |
Calculation of the vector length \(|\vec{a}|\). More... | |
Type | sqrLength () const |
Calculation of the vector square length \(|\vec{a}|^2\). More... | |
Vector3< Length > | getNormalized () const |
Calculation of the normalized vector ( \(|\vec{a}|=1\)). More... | |
Vector3< Length > | getNormalizedOrZero () const |
Calculation of the normalized vector ( \(|\vec{a}|=1\)) without precondition. More... | |
Vector3< Length > | getNormalizedIfNotZero () const |
Calculation of the normalized vector ( \(|\vec{a}|=1\)) without precondition. More... | |
void | reset () |
Sets all components of the vector to 0. More... | |
Type * | data () |
const Type * | data () const |
Private Attributes | |
Member variables | |
Type | v_ [3] = {Type(), Type(), Type()} |
The three statically allocated vector elements. More... | |
using walberla::math::Vector3< Type >::Length = typename SqrtTrait<Type>::Type |
Return type of the Vector3<Type>::length function.
using walberla::math::Vector3< Type >::value_type = Type |
|
inlineexplicitconstexprdefault |
|
inlineexplicitconstexpr |
Constructor for a homogenous initialization of all elements.
init | Initial value for all vector elements. |
|
inlineexplicitconstexpr |
|
inlineexplicitconstexpr |
Constructor for a direct initialization of all vector elements.
x | The initial value for the x-component. |
y | The initial value for the y-component. |
z | The initial value for the z-component. |
|
inlineexplicitconstexpr |
Constructor for an array initializer.
init | Pointer to the initialization array. |
The array is assumed to have at least three valid elements.
|
inlineconstexprdefault |
|
inlineconstexpr |
Conversion constructor from different Vector3 instances.
v | Vector to be copied. |
|
inline |
|
inline |
|
inline |
Calculation of the normalized vector ( \(|\vec{a}|=1\)).
The function returns the normalized vector.
|
inline |
Calculation of the normalized vector ( \(|\vec{a}|=1\)) without precondition.
|
inline |
Calculation of the normalized vector ( \(|\vec{a}|=1\)) without precondition.
|
inline |
Returns index of absolute maximum value.
|
inline |
Returns index of absolute minimum value.
|
inline |
Calculation of the vector length \(|\vec{a}|\).
The return type of the length function depends on the actual type of the vector instance:
Type | Length |
float | float |
integral data types and double | double |
long double | long double |
|
inline |
Returns maximum value.
|
inline |
Returns minimum value.
|
inline |
Inequality operator for the comparison of two vectors.
rhs | The right-hand-side vector for the comparison. |
|
inline |
Inequality operator for the comparison of a vector and a scalar value.
rhs | The right-hand-side scalar value for the comparison. |
If one value of the vector is inequal to the scalar value, the inequality test returns true, otherwise false.
|
inline |
Cross product (outer product) of two vectors ( \( \vec{a}=\vec{b}\times\vec{c} \)).
rhs | The right-hand-side vector for the cross product. |
|
inline |
Cross product (outer product) of two vectors ( \( \vec{a}=\vec{b}\times\vec{c} \)).
rhs | The right-hand-side vector for the cross product. |
|
inline |
|
inline |
Multiplication operator for the scalar product (inner product) of two vectors.
( \( s=\vec{a}*\vec{b} \)).
rhs | The right-hand-side vector for the inner product. |
The operator returns a scalar value of the higher-order data type of the two involved data types (in fact the two template arguments Type and Other ).
|
inline |
Multiplication operator for the multiplication of a vector and a scalar value.
( \( \vec{a}=\vec{b}*s \)).
rhs | The right-hand-side scalar value for the multiplication. |
The operator returns a vector of the higher-order data type of the two involved data types (in fact the two template arguments Type and Other ).
|
inline |
Multiplication assignment operator for the multiplication between a vector and.
a scalar value ( \( \vec{a}*=s \)).
rhs | The right-hand-side scalar value for the multiplication. |
|
inline |
|
inline |
Addition operator for the addition of two vectors ( \( \vec{a}=\vec{b}+\vec{c} \)).
rhs | The right-hand-side vector to be added to the vector. |
The operator returns a vector of the higher-order data type of the two involved vector data types (in fact the two template arguments Type and Other ).
|
inline |
Addition assignment operator for the addition of two vectors ( \( \vec{a}+=\vec{b} \)).
rhs | The right-hand-side vector to be added to the vector. |
|
inline |
|
inline |
Unary minus operator for the inversion of a vector ( \( \vec{a} = -\vec{b} \)).
|
inline |
Subtraction operator for the subtraction of two vectors ( \( \vec{a}=\vec{b}-\vec{c} \)).
rhs | The right-hand-side vector to be subtracted from the vector. |
The operator returns a vector of the higher-order data type of the two involved vector data types (in fact the two template arguments Type and Other ).
|
inline |
Subtraction assignment operator for the subtraction of two vectors.
( \( \vec{a}-=\vec{b} \)).
rhs | The right-hand-side vector to be subtracted from the vector. |
|
inline |
|
inline |
Division operator for the division of a vector by a scalar value.
( \( \vec{a}=\vec{b}/s \)).
rhs | The right-hand-side scalar value for the division. |
The operator returns a vector of the higher-order data type of the two involved data types (in fact the two template arguments Type and Other ).
Note: No check for 0 is applied.
|
inline |
Division assignment operator for the division of a vector by a scalar value.
( \( \vec{a}/=s \)).
rhs | The right-hand-side scalar value for the division. |
Note: No check for 0 is applied.
|
inline |
|
inlinedefault |
|
inline |
Assignment operator for different Vector3 instances.
v | Vector to be copied. |
|
inline |
|
inline |
Equality operator for the comparison of two vectors.
rhs | The right-hand-side vector for the comparison. |
|
inline |
Equality operator for the comparison of a vector and a scalar value.
rhs | The right-hand-side scalar value for the comparison. |
If all values of the vector are equal to the scalar value, the equality test returns true, otherwise false.
|
inline |
Subscript operator for the direct access to the vector elements.
index | Access index. The index has to be in the range \([0..2]\). |
|
inline |
Subscript operator for the direct access to the vector elements.
index | Access index. The index has to be in the range \([0..2]\). |
|
inline |
Sets all components of the vector to 0.
|
inline |
Set function for a direct assignment of all vector elements.
x | The initial value for the x-component. |
y | The initial value for the y-component. |
z | The initial value for the z-component. |
|
inline |
Calculation of the vector square length \(|\vec{a}|^2\).
|
private |
The three statically allocated vector elements.
Access to the vector values is gained via the subscript operator. The order of the elements is
\[\left(\begin{array}{*{3}{c}} 0 & 1 & 2 \\ \end{array}\right)\]