Ignition Math

API Reference

6.10.0
Vector4< T > Class Template Reference

T Generic x, y, z, w vector. More...

#include <ignition/math/Vector4.hh>

Public Member Functions

 Vector4 ()
 Constructor. More...
 
 Vector4 (const T &_x, const T &_y, const T &_z, const T &_w)
 Constructor with component values. More...
 
 Vector4 (const Vector4< T > &_v)
 Copy constructor. More...
 
virtual ~Vector4 ()
 Destructor. More...
 
Vector4 Abs () const
 Get the absolute value of the vector. More...
 
AbsDot (const Vector4< T > &_v) const
 Return the absolute dot product of this vector and another vector. This is similar to the Dot function, except the absolute value of each component of the vector is used. More...
 
void Correct ()
 Corrects any nan values. More...
 
Distance (const Vector4< T > &_pt) const
 Calc distance to the given point. More...
 
Distance (T _x, T _y, T _z, T _w) const
 Calc distance to the given point. More...
 
Dot (const Vector4< T > &_v) const
 Return the dot product of this vector and another vector. More...
 
bool Equal (const Vector4 &_v, const T &_tol) const
 Equality test with tolerance. More...
 
bool IsFinite () const
 See if a point is finite (e.g., not nan) More...
 
Length () const
 Returns the length (magnitude) of the vector. More...
 
void Max (const Vector4< T > &_v)
 Set this vector's components to the maximum of itself and the passed in vector. More...
 
Max () const
 Get the maximum value in the vector. More...
 
void Min (const Vector4< T > &_v)
 Set this vector's components to the minimum of itself and the passed in vector. More...
 
Min () const
 Get the minimum value in the vector. More...
 
void Normalize ()
 Normalize the vector length. More...
 
Vector4 Normalized () const
 Return a normalized vector. More...
 
bool operator!= (const Vector4< T > &_pt) const
 Not equal to operator. More...
 
const Vector4< T > operator* (const Vector4< T > &_pt) const
 Multiplication operator. More...
 
const Vector4< T > operator* (const Matrix4< T > &_m) const
 Matrix multiplication operator. More...
 
const Vector4< T > operator* (T _v) const
 Multiplication operators. More...
 
const Vector4< T > & operator*= (const Vector4< T > &_pt)
 Multiplication assignment operator. More...
 
const Vector4< T > & operator*= (T _v)
 Multiplication assignment operator. More...
 
Vector4< T > operator+ (const Vector4< T > &_v) const
 Addition operator. More...
 
Vector4< T > operator+ (const T _s) const
 Addition operators. More...
 
const Vector4< T > & operator+= (const Vector4< T > &_v)
 Addition operator. More...
 
const Vector4< T > & operator+= (const T _s)
 Addition assignment operator. More...
 
Vector4 operator- () const
 Negation operator. More...
 
Vector4< T > operator- (const Vector4< T > &_v) const
 Subtraction operator. More...
 
Vector4< T > operator- (const T _s) const
 Subtraction operators. More...
 
const Vector4< T > & operator-= (const Vector4< T > &_v)
 Subtraction assigment operators. More...
 
const Vector4< T > & operator-= (const T _s)
 Subtraction assignment operator. More...
 
const Vector4< T > operator/ (const Vector4< T > &_v) const
 Division assignment operator. More...
 
const Vector4< T > operator/ (T _v) const
 Division assignment operator. More...
 
const Vector4< T > & operator/= (const Vector4< T > &_v)
 Division assignment operator. More...
 
const Vector4< T > & operator/= (T _v)
 Division operator. More...
 
bool operator< (const Vector4< T > &_pt) const
 Less than operator. More...
 
Vector4< T > & operator= (const Vector4< T > &_v)
 Assignment operator. More...
 
Vector4< T > & operator= (T _value)
 Assignment operator. More...
 
bool operator== (const Vector4< T > &_v) const
 Equal to operator. More...
 
T & operator[] (const std::size_t _index)
 Array subscript operator. More...
 
operator[] (const std::size_t _index) const
 Const-qualified array subscript operator. More...
 
void Round ()
 Round to near whole number. More...
 
Vector4 Rounded () const
 Get a rounded version of this vector. More...
 
void Set (T _x=0, T _y=0, T _z=0, T _w=0)
 Set the contents of the vector. More...
 
SquaredLength () const
 Return the square of the length (magnitude) of the vector. More...
 
Sum () const
 Return the sum of the values. More...
 
T & W ()
 Return a mutable w value. More...
 
W () const
 Get the w value. More...
 
void W (const T &_v)
 Set the w value. More...
 
T & X ()
 Return a mutable x value. More...
 
X () const
 Get the x value. More...
 
void X (const T &_v)
 Set the x value. More...
 
T & Y ()
 Return a mutable y value. More...
 
Y () const
 Get the y value. More...
 
void Y (const T &_v)
 Set the y value. More...
 
T & Z ()
 Return a mutable z value. More...
 
Z () const
 Get the z value. More...
 
void Z (const T &_v)
 Set the z value. More...
 

Static Public Attributes

static const Vector4 NaN
 math::Vector4(NaN, NaN, NaN, NaN) More...
 
static const Vector4< T > One
 math::Vector4(1, 1, 1, 1) More...
 
static const Vector4< T > Zero
 math::Vector4(0, 0, 0, 0) More...
 

Friends

const Vector4 operator* (const T _s, const Vector4 &_v)
 Scalar left multiplication operators. More...
 
Vector4< T > operator+ (const T _s, const Vector4< T > &_v)
 Addition operators. More...
 
Vector4< T > operator- (const T _s, const Vector4< T > &_v)
 Subtraction operators. More...
 
std::ostreamoperator<< (std::ostream &_out, const Vector4< T > &_pt)
 Stream insertion operator. More...
 
std::istreamoperator>> (std::istream &_in, Vector4< T > &_pt)
 Stream extraction operator. More...
 

Detailed Description

template<typename T>
class ignition::math::Vector4< T >

T Generic x, y, z, w vector.

Constructor & Destructor Documentation

◆ Vector4() [1/3]

Vector4 ( )
inline

◆ Vector4() [2/3]

Vector4 ( const T &  _x,
const T &  _y,
const T &  _z,
const T &  _w 
)
inline

Constructor with component values.

Parameters
[in]_xvalue along x axis
[in]_yvalue along y axis
[in]_zvalue along z axis
[in]_wvalue along w axis

◆ Vector4() [3/3]

Vector4 ( const Vector4< T > &  _v)
inline

Copy constructor.

Parameters
[in]_vvector

◆ ~Vector4()

virtual ~Vector4 ( )
inlinevirtual

Destructor.

Member Function Documentation

◆ Abs()

Vector4 Abs ( ) const
inline

Get the absolute value of the vector.

Returns
a vector with positive elements

References Vector4< T >::Vector4().

◆ AbsDot()

T AbsDot ( const Vector4< T > &  _v) const
inline

Return the absolute dot product of this vector and another vector. This is similar to the Dot function, except the absolute value of each component of the vector is used.

result = abs(x1 * x2) + abs(y1 * y2) + abs(z1 * z2) + abs(w1 * w2)

Parameters
[in]_vthe vector
Returns
The absolute dot product

◆ Correct()

void Correct ( )
inline

Corrects any nan values.

References std::isfinite().

◆ Distance() [1/2]

T Distance ( const Vector4< T > &  _pt) const
inline

Calc distance to the given point.

Parameters
[in]_ptthe point
Returns
the distance

Referenced by Vector4< T >::Distance().

◆ Distance() [2/2]

T Distance ( _x,
_y,
_z,
_w 
) const
inline

Calc distance to the given point.

Parameters
[in]_xvalue along x
[in]_yvalue along y
[in]_zvalue along z
[in]_wvalue along w
Returns
the distance

References Vector4< T >::Distance(), and Vector4< T >::Vector4().

◆ Dot()

T Dot ( const Vector4< T > &  _v) const
inline

Return the dot product of this vector and another vector.

Parameters
[in]_vthe vector
Returns
the dot product

◆ Equal()

bool Equal ( const Vector4< T > &  _v,
const T &  _tol 
) const
inline

Equality test with tolerance.

Parameters
[in]_vthe vector to compare to
[in]_tolequality tolerance.
Returns
true if the elements of the vectors are equal within the tolerence specified by _tol.

Referenced by Vector4< T >::operator==().

◆ IsFinite()

bool IsFinite ( ) const
inline

See if a point is finite (e.g., not nan)

Returns
true if finite, false otherwise

References std::isfinite().

◆ Length()

T Length ( ) const
inline

Returns the length (magnitude) of the vector.

Returns
The length

References Vector4< T >::SquaredLength().

Referenced by Vector4< T >::Normalize().

◆ Max() [1/2]

void Max ( const Vector4< T > &  _v)
inline

Set this vector's components to the maximum of itself and the passed in vector.

Parameters
[in]_vthe maximum clamping vector

References std::max().

◆ Max() [2/2]

T Max ( ) const
inline

Get the maximum value in the vector.

Returns
the maximum element

References std::max_element().

◆ Min() [1/2]

void Min ( const Vector4< T > &  _v)
inline

Set this vector's components to the minimum of itself and the passed in vector.

Parameters
[in]_vthe minimum clamping vector

References std::min().

◆ Min() [2/2]

T Min ( ) const
inline

Get the minimum value in the vector.

Returns
the minimum element

References std::min_element().

◆ Normalize()

void Normalize ( )
inline

Normalize the vector length.

References Vector4< T >::Length().

Referenced by Vector4< T >::Normalized().

◆ Normalized()

Vector4 Normalized ( ) const
inline

Return a normalized vector.

Returns
unit length vector

References Vector4< T >::Normalize().

◆ operator!=()

bool operator!= ( const Vector4< T > &  _pt) const
inline

Not equal to operator.

Parameters
[in]_ptthe other vector
Returns
false if each component is equal within a default tolerence (1e-6), true otherwise

◆ operator*() [1/3]

const Vector4<T> operator* ( const Vector4< T > &  _pt) const
inline

Multiplication operator.

Remarks
Performs element wise multiplication, which has limited use.
Parameters
[in]_ptanother vector
Returns
result vector

◆ operator*() [2/3]

const Vector4<T> operator* ( const Matrix4< T > &  _m) const
inline

Matrix multiplication operator.

Parameters
[in]_mmatrix
Returns
the vector multiplied by _m

◆ operator*() [3/3]

const Vector4<T> operator* ( _v) const
inline

Multiplication operators.

Parameters
[in]_vscaling factor
Returns
a scaled vector

◆ operator*=() [1/2]

const Vector4<T>& operator*= ( const Vector4< T > &  _pt)
inline

Multiplication assignment operator.

Remarks
Performs element wise multiplication, which has limited use.
Parameters
[in]_pta vector
Returns
this

◆ operator*=() [2/2]

const Vector4<T>& operator*= ( _v)
inline

Multiplication assignment operator.

Parameters
[in]_vscaling factor
Returns
this

◆ operator+() [1/2]

Vector4<T> operator+ ( const Vector4< T > &  _v) const
inline

Addition operator.

Parameters
[in]_vthe vector to add
Returns
a sum vector

◆ operator+() [2/2]

Vector4<T> operator+ ( const T  _s) const
inline

Addition operators.

Parameters
[in]_sthe scalar addend
Returns
sum vector

◆ operator+=() [1/2]

const Vector4<T>& operator+= ( const Vector4< T > &  _v)
inline

Addition operator.

Parameters
[in]_vthe vector to add
Returns
this vector

◆ operator+=() [2/2]

const Vector4<T>& operator+= ( const T  _s)
inline

Addition assignment operator.

Parameters
[in]_sscalar addend
Returns
this

◆ operator-() [1/3]

Vector4 operator- ( ) const
inline

Negation operator.

Returns
negative of this vector

References Vector4< T >::Vector4().

◆ operator-() [2/3]

Vector4<T> operator- ( const Vector4< T > &  _v) const
inline

Subtraction operator.

Parameters
[in]_vthe vector to substract
Returns
a vector

◆ operator-() [3/3]

Vector4<T> operator- ( const T  _s) const
inline

Subtraction operators.

Parameters
[in]_sthe scalar subtrahend
Returns
difference vector

◆ operator-=() [1/2]

const Vector4<T>& operator-= ( const Vector4< T > &  _v)
inline

Subtraction assigment operators.

Parameters
[in]_vthe vector to substract
Returns
this vector

◆ operator-=() [2/2]

const Vector4<T>& operator-= ( const T  _s)
inline

Subtraction assignment operator.

Parameters
[in]_sscalar subtrahend
Returns
this

◆ operator/() [1/2]

const Vector4<T> operator/ ( const Vector4< T > &  _v) const
inline

Division assignment operator.

Remarks
Performs element wise division, which has limited use.
Parameters
[in]_vthe vector to perform element wise division with
Returns
a result vector

◆ operator/() [2/2]

const Vector4<T> operator/ ( _v) const
inline

Division assignment operator.

Remarks
Performs element wise division, which has limited use.
Parameters
[in]_vanother vector
Returns
a result vector

◆ operator/=() [1/2]

const Vector4<T>& operator/= ( const Vector4< T > &  _v)
inline

Division assignment operator.

Remarks
Performs element wise division, which has limited use.
Parameters
[in]_vthe vector to perform element wise division with
Returns
this

◆ operator/=() [2/2]

const Vector4<T>& operator/= ( _v)
inline

Division operator.

Parameters
[in]_vscaling factor
Returns
a vector

◆ operator<()

bool operator< ( const Vector4< T > &  _pt) const
inline

Less than operator.

Parameters
[in]_ptVector to compare.
Returns
True if this vector's X(), Y(), Z() or W() value is less than the given vector's corresponding values.

◆ operator=() [1/2]

Vector4<T>& operator= ( const Vector4< T > &  _v)
inline

Assignment operator.

Parameters
[in]_vthe vector
Returns
a reference to this vector

◆ operator=() [2/2]

Vector4<T>& operator= ( _value)
inline

Assignment operator.

Parameters
[in]_value

◆ operator==()

bool operator== ( const Vector4< T > &  _v) const
inline

Equal to operator.

Parameters
[in]_vthe other vector
Returns
true if each component is equal within a default tolerence (1e-6), false otherwise

References Vector4< T >::Equal().

◆ operator[]() [1/2]

T& operator[] ( const std::size_t  _index)
inline

Array subscript operator.

Parameters
[in]_indexThe index, where 0 == x, 1 == y, 2 == z, 3 == w. The index is clamped to the range (0,3).
Returns
The value.

References ignition::math::clamp(), ignition::math::IGN_THREE_SIZE_T, and ignition::math::IGN_ZERO_SIZE_T.

◆ operator[]() [2/2]

T operator[] ( const std::size_t  _index) const
inline

Const-qualified array subscript operator.

Parameters
[in]_indexThe index, where 0 == x, 1 == y, 2 == z, 3 == w. The index is clamped to the range (0,3).
Returns
The value.

References ignition::math::clamp(), ignition::math::IGN_THREE_SIZE_T, and ignition::math::IGN_ZERO_SIZE_T.

◆ Round()

void Round ( )
inline

Round to near whole number.

References std::nearbyint().

Referenced by Vector4< T >::Rounded().

◆ Rounded()

Vector4 Rounded ( ) const
inline

Get a rounded version of this vector.

Returns
a rounded vector

References Vector4< T >::Round().

◆ Set()

void Set ( _x = 0,
_y = 0,
_z = 0,
_w = 0 
)
inline

Set the contents of the vector.

Parameters
[in]_xvalue along x axis
[in]_yvalue along y axis
[in]_zvalue along z axis
[in]_wvalue along w axis

◆ SquaredLength()

T SquaredLength ( ) const
inline

Return the square of the length (magnitude) of the vector.

Returns
the length

Referenced by Vector4< T >::Length().

◆ Sum()

T Sum ( ) const
inline

Return the sum of the values.

Returns
the sum

◆ W() [1/3]

T& W ( )
inline

Return a mutable w value.

Returns
The w component of the vector

◆ W() [2/3]

T W ( ) const
inline

Get the w value.

Returns
The w component of the vector

◆ W() [3/3]

void W ( const T &  _v)
inline

Set the w value.

Parameters
[in]_vValue for the w component.

◆ X() [1/3]

T& X ( )
inline

Return a mutable x value.

Returns
The x component of the vector

◆ X() [2/3]

T X ( ) const
inline

Get the x value.

Returns
The x component of the vector

◆ X() [3/3]

void X ( const T &  _v)
inline

Set the x value.

Parameters
[in]_vValue for the x component.

◆ Y() [1/3]

T& Y ( )
inline

Return a mutable y value.

Returns
The y component of the vector

◆ Y() [2/3]

T Y ( ) const
inline

Get the y value.

Returns
The y component of the vector

◆ Y() [3/3]

void Y ( const T &  _v)
inline

Set the y value.

Parameters
[in]_vValue for the y component.

◆ Z() [1/3]

T& Z ( )
inline

Return a mutable z value.

Returns
The z component of the vector

◆ Z() [2/3]

T Z ( ) const
inline

Get the z value.

Returns
The z component of the vector

◆ Z() [3/3]

void Z ( const T &  _v)
inline

Set the z value.

Parameters
[in]_vValue for the z component.

Friends And Related Function Documentation

◆ operator*

const Vector4 operator* ( const T  _s,
const Vector4< T > &  _v 
)
friend

Scalar left multiplication operators.

Parameters
[in]_sthe scaling factor
[in]_vthe vector to scale
Returns
a scaled vector

◆ operator+

Vector4<T> operator+ ( const T  _s,
const Vector4< T > &  _v 
)
friend

Addition operators.

Parameters
[in]_sthe scalar addend
[in]_vinput vector
Returns
sum vector

◆ operator-

Vector4<T> operator- ( const T  _s,
const Vector4< T > &  _v 
)
friend

Subtraction operators.

Parameters
[in]_sthe scalar minuend
[in]_vvector subtrahend
Returns
difference vector

◆ operator<<

std::ostream& operator<< ( std::ostream _out,
const Vector4< T > &  _pt 
)
friend

Stream insertion operator.

Parameters
[in]_outoutput stream
[in]_ptVector4 to output
Returns
The stream

◆ operator>>

std::istream& operator>> ( std::istream _in,
Vector4< T > &  _pt 
)
friend

Stream extraction operator.

Parameters
[in]_ininput stream
[in]_ptVector4 to read values into
Returns
the stream

Member Data Documentation

◆ NaN

const Vector4< T > NaN
static

math::Vector4(NaN, NaN, NaN, NaN)

◆ One

const Vector4< T > One
static

math::Vector4(1, 1, 1, 1)

◆ Zero

const Vector4< T > Zero
static

math::Vector4(0, 0, 0, 0)


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