 # Ignition Math

## API Reference

6.8.0
Vector3< T > Class Template Reference

The Vector3 class represents the generic vector containing 3 elements. Since it's commonly used to keep coordinate system related information, its elements are labeled by x, y, z. More...

#include <ignition/math/Vector3.hh>

## Public Member Functions

Vector3 ()
Constructor. More...

Vector3 (const T &_x, const T &_y, const T &_z)
Constructor. More...

Vector3 (const Vector3< T > &_v)
Copy constructor. More...

virtual ~Vector3 ()
Destructor. More...

Vector3 Abs () const
Get the absolute value of the vector. More...

AbsDot (const Vector3< 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...

Vector3 Cross (const Vector3< T > &_v) const
Return the cross product of this vector with another vector. More...

Distance (const Vector3< T > &_pt) const
Calc distance to the given point. More...

Distance (T _x, T _y, T _z) const
Calc distance to the given point. More...

DistToLine (const Vector3< T > &_pt1, const Vector3 &_pt2)
Get distance to a line. More...

Dot (const Vector3< T > &_v) const
Return the dot product of this vector and another vector. More...

bool Equal (const Vector3 &_v, const T &_tol) const
Equality test with tolerance. More...

bool Equal (const Vector3< T > &_v) const
Equality test. 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 Vector3< 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 Vector3< 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...

Vector3 Normalize ()
Normalize the vector length. More...

Vector3 Normalized () const
Return a normalized vector. More...

bool operator!= (const Vector3< T > &_v) const
Not equal to operator. More...

Vector3< T > operator* (const Vector3< T > &_p) const
Multiplication operator. More...

Vector3< T > operator* (T _s) const
Multiplication operators. More...

const Vector3< T > & operator*= (const Vector3< T > &_v)
Multiplication assignment operators. More...

const Vector3< T > & operator*= (T _v)
Multiplication operator. More...

Vector3 operator+ (const Vector3< T > &_v) const

Vector3< T > operator+ (const T _s) const

const Vector3operator+= (const Vector3< T > &_v)

const Vector3< T > & operator+= (const T _s)

Vector3 operator- () const
Negation operator. More...

Vector3< T > operator- (const Vector3< T > &_pt) const
Subtraction operators. More...

Vector3< T > operator- (const T _s) const
Subtraction operators. More...

const Vector3< T > & operator-= (const Vector3< T > &_pt)
Subtraction assignment operators. More...

const Vector3< T > & operator-= (const T _s)
Subtraction assignment operator. More...

const Vector3< T > operator/ (const Vector3< T > &_pt) const
Division operator. More...

const Vector3< T > operator/ (T _v) const
Division operator. More...

const Vector3< T > & operator/= (const Vector3< T > &_pt)
Division assignment operator. More...

const Vector3< T > & operator/= (T _v)
Division assignment operator. More...

bool operator< (const Vector3< T > &_pt) const
Less than operator. More...

Vector3operator= (const Vector3< T > &_v)
Assignment operator. More...

Vector3operator= (T _v)
Assignment operator. More...

bool operator== (const Vector3< 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...

Vector3 Perpendicular () const
Return a vector that is perpendicular to this one. More...

Vector3 Round ()
Round to near whole number, return the result. More...

void Round (int _precision)
Round all values to _precision decimal places. More...

Vector3 Rounded () const
Get a rounded version of this vector. More...

void Set (T _x=0, T _y=0, T _z=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...

X () const
Get the x value. More...

T & X ()
Get a mutable reference to the x value. More...

void X (const T &_v)
Set the x value. More...

Y () const
Get the y value. More...

T & Y ()
Get a mutable reference to the y value. More...

void Y (const T &_v)
Set the y value. More...

Z () const
Get the z value. More...

T & Z ()
Get a mutable reference to the z value. More...

void Z (const T &_v)
Set the z value. More...

## Static Public Member Functions

static Vector3 Normal (const Vector3< T > &_v1, const Vector3< T > &_v2, const Vector3< T > &_v3)
Get a normal vector to a triangle. More...

## Static Public Attributes

static const Vector3 NaN
math::Vector3(NaN, NaN, NaN) More...

static const Vector3 One
math::Vector3(1, 1, 1) More...

static const Vector3 UnitX
math::Vector3(1, 0, 0) More...

static const Vector3 UnitY
math::Vector3(0, 1, 0) More...

static const Vector3 UnitZ
math::Vector3(0, 0, 1) More...

static const Vector3 Zero
math::Vector3(0, 0, 0) More...

## Friends

Vector3< T > operator* (T _s, const Vector3< T > &_v)
Multiplication operators. More...

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

Vector3< T > operator- (const T _s, const Vector3< T > &_v)
Subtraction operators. More...

std::ostreamoperator<< (std::ostream &_out, const Vector3< T > &_pt)
Stream insertion operator. More...

std::istreamoperator>> (std::istream &_in, Vector3< T > &_pt)
Stream extraction operator. More...

## Detailed Description

### template<typename T> class ignition::math::Vector3< T >

The Vector3 class represents the generic vector containing 3 elements. Since it's commonly used to keep coordinate system related information, its elements are labeled by x, y, z.

## ◆ Vector3() [1/3]

 Vector3 ( )
inline

## ◆ Vector3() [2/3]

 Vector3 ( const T & _x, const T & _y, const T & _z )
inline

Constructor.

Parameters
 [in] _x value along x [in] _y value along y [in] _z value along z

## ◆ Vector3() [3/3]

 Vector3 ( const Vector3< T > & _v )
inline

Copy constructor.

Parameters
 [in] _v a vector

## ◆ ~Vector3()

 virtual ~Vector3 ( )
inlinevirtual

Destructor.

## ◆ Abs()

 Vector3 Abs ( ) const
inline

Get the absolute value of the vector.

Returns
a vector with positive elements

Referenced by Quaternion< Precision >::From2Axes(), and OrientedBox< T >::Size().

## ◆ AbsDot()

 T AbsDot ( const Vector3< 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)

Parameters
 [in] _v the vector
Returns
The absolute dot product

## ◆ Correct()

 void Correct ( )
inline

Corrects any nan values.

## ◆ Cross()

 Vector3 Cross ( const Vector3< T > & _v ) const
inline

Return the cross product of this vector with another vector.

Parameters
 [in] _v a vector
Returns
the cross product

## ◆ Distance() [1/2]

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

Calc distance to the given point.

Parameters
 [in] _pt the point
Returns
the distance

Referenced by Vector3< Precision >::Distance().

## ◆ Distance() [2/2]

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

Calc distance to the given point.

Parameters
 [in] _x value along x [in] _y value along y [in] _z value along z
Returns
the distance

## ◆ DistToLine()

 T DistToLine ( const Vector3< T > & _pt1, const Vector3< T > & _pt2 )
inline

Get distance to a line.

Parameters
 [in] _pt1 first point on the line [in] _pt2 second point on the line
Returns
the minimum distance from this point to the line

## ◆ Dot()

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

Return the dot product of this vector and another vector.

Parameters
 [in] _v the vector
Returns
the dot product

## ◆ Equal() [1/2]

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

Equality test with tolerance.

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

Referenced by Vector3< Precision >::operator==(), and MassMatrix3< T >::PrincipalAxesOffset().

## ◆ Equal() [2/2]

 bool Equal ( const Vector3< T > & _v ) const
inline

Equality test.

Remarks
This is equivalent to the == operator
Parameters
 [in] _v the other vector
Returns
true if the 2 vectors have the same values, false otherwise

## ◆ IsFinite()

 bool IsFinite ( ) const
inline

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

Returns
true if is finite or false otherwise

## ◆ Length()

 T Length ( ) const
inline

Returns the length (magnitude) of the vector.

Returns
the length

Referenced by Vector3< Precision >::DistToLine(), and Vector3< Precision >::Normalize().

## ◆ Max() [1/2]

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

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

Parameters
 [in] _v the maximum clamping vector

## ◆ Max() [2/2]

 T Max ( ) const
inline

Get the maximum value in the vector.

Returns
the maximum element

## ◆ Min() [1/2]

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

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

Parameters
 [in] _v the minimum clamping vector

Referenced by MassMatrix3< T >::SetFromBox().

## ◆ Min() [2/2]

 T Min ( ) const
inline

Get the minimum value in the vector.

Returns
the minimum element

## ◆ Normal()

 static Vector3 Normal ( const Vector3< T > & _v1, const Vector3< T > & _v2, const Vector3< T > & _v3 )
inlinestatic

Get a normal vector to a triangle.

Parameters
 [in] _v1 first vertex of the triangle [in] _v2 second vertex [in] _v3 third vertex
Returns
the normal

Referenced by Triangle3< T >::Normal().

## ◆ Normalize()

 Vector3 Normalize ( )
inline

Normalize the vector length.

Returns
unit length vector

## ◆ Normalized()

 Vector3 Normalized ( ) const
inline

Return a normalized vector.

Returns
unit length vector

## ◆ operator!=()

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

Not equal to operator.

Parameters
 [in] _v The vector to compare against
Returns
false if each component is equal within a default tolerence (1e-3), true otherwise

## ◆ operator*() [1/2]

 Vector3 operator* ( const Vector3< T > & _p ) const
inline

Multiplication operator.

Remarks
this is an element wise multiplication, not a cross product
Parameters
 [in] _p multiplier operator
Returns
a vector

## ◆ operator*() [2/2]

 Vector3 operator* ( T _s ) const
inline

Multiplication operators.

Parameters
 [in] _s the scaling factor
Returns
a scaled vector

## ◆ operator*=() [1/2]

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

Multiplication assignment operators.

Remarks
this is an element wise multiplication, not a cross product
Parameters
 [in] _v a vector
Returns
this

## ◆ operator*=() [2/2]

 const Vector3& operator*= ( T _v )
inline

Multiplication operator.

Parameters
 [in] _v scaling factor
Returns
this

## ◆ operator+() [1/2]

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

Parameters
Returns
the sum vector

## ◆ operator+() [2/2]

 Vector3 operator+ ( const T _s ) const
inline

Parameters
Returns
sum vector

## ◆ operator+=() [1/2]

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

Parameters
Returns
the sum vector

## ◆ operator+=() [2/2]

 const Vector3& operator+= ( const T _s )
inline

Parameters
Returns
this

## ◆ operator-() [1/3]

 Vector3 operator- ( ) const
inline

Negation operator.

Returns
negative of this vector

## ◆ operator-() [2/3]

 Vector3 operator- ( const Vector3< T > & _pt ) const
inline

Subtraction operators.

Parameters
 [in] _pt a vector to substract
Returns
a vector after the substraction

## ◆ operator-() [3/3]

 Vector3 operator- ( const T _s ) const
inline

Subtraction operators.

Parameters
 [in] _s the scalar subtrahend
Returns
difference vector

## ◆ operator-=() [1/2]

 const Vector3& operator-= ( const Vector3< T > & _pt )
inline

Subtraction assignment operators.

Parameters
 [in] _pt subtrahend
Returns
a vector after the substraction

## ◆ operator-=() [2/2]

 const Vector3& operator-= ( const T _s )
inline

Subtraction assignment operator.

Parameters
 [in] _s scalar subtrahend
Returns
this

## ◆ operator/() [1/2]

 const Vector3 operator/ ( const Vector3< T > & _pt ) const
inline

Division operator.

Remarks
this is an element wise division
Parameters
 [in] _pt the vector divisor
Returns
a vector

## ◆ operator/() [2/2]

 const Vector3 operator/ ( T _v ) const
inline

Division operator.

Remarks
this is an element wise division
Parameters
 [in] _v the divisor
Returns
a vector

## ◆ operator/=() [1/2]

 const Vector3& operator/= ( const Vector3< T > & _pt )
inline

Division assignment operator.

Remarks
this is an element wise division
Parameters
 [in] _pt the vector divisor
Returns
a vector

## ◆ operator/=() [2/2]

 const Vector3& operator/= ( T _v )
inline

Division assignment operator.

Remarks
this is an element wise division
Parameters
 [in] _v the divisor
Returns
this

## ◆ operator<()

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

Less than operator.

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

## ◆ operator=() [1/2]

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

Assignment operator.

Parameters
 [in] _v a new value
Returns
this

## ◆ operator=() [2/2]

 Vector3& operator= ( T _v )
inline

Assignment operator.

Parameters
 [in] _v assigned to all elements
Returns
this

## ◆ operator==()

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

Equal to operator.

Parameters
 [in] _v The vector to compare against
Returns
true if each component is equal within a default tolerence (1e-3), false otherwise

## ◆ operator[]() [1/2]

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

Array subscript operator.

Parameters
 [in] _index The index, where 0 == x, 1 == y, 2 == z. The index is clamped to the range [0,2].
Returns
The value.

## ◆ operator[]() [2/2]

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

Const-qualified array subscript operator.

Parameters
 [in] _index The index, where 0 == x, 1 == y, 2 == z. The index is clamped to the range [0,2].
Returns
The value.

## ◆ Perpendicular()

 Vector3 Perpendicular ( ) const
inline

Return a vector that is perpendicular to this one.

Returns
an orthogonal vector

## ◆ Round() [1/2]

 Vector3 Round ( )
inline

Round to near whole number, return the result.

Returns
the result

Referenced by Vector3< Precision >::Rounded().

## ◆ Round() [2/2]

 void Round ( int _precision )
inline

Round all values to _precision decimal places.

Parameters
 [in] _precision the decimal places

## ◆ Rounded()

 Vector3 Rounded ( ) const
inline

Get a rounded version of this vector.

Returns
a rounded vector

## ◆ Set()

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

Set the contents of the vector.

Parameters
 [in] _x value along x [in] _y value along y [in] _z value aling z

## ◆ SquaredLength()

 T SquaredLength ( ) const
inline

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

Returns
the squared length

## ◆ Sum()

 T Sum ( ) const
inline

Return the sum of the values.

Returns
the sum

Referenced by MassMatrix3< T >::Epsilon(), and MassMatrix3< T >::PrincipalMoments().

## ◆ X() [1/3]

 T X ( ) const
inline

## ◆ X() [2/3]

 T& X ( )
inline

Get a mutable reference to 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] _v Value for the x component.

## ◆ Y() [1/3]

 T Y ( ) const
inline

## ◆ Y() [2/3]

 T& Y ( )
inline

Get a mutable reference to 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] _v Value for the y component.

## ◆ Z() [1/3]

 T Z ( ) const
inline

## ◆ Z() [2/3]

 T& Z ( )
inline

Get a mutable reference to 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] _v Value for the z component.

## ◆ operator*

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

Multiplication operators.

Parameters
 [in] _s the scaling factor [in] _v input vector
Returns
a scaled vector

## ◆ operator+

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

Parameters
 [in] _s the scalar addend [in] _v input vector
Returns
sum vector

## ◆ operator-

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

Subtraction operators.

Parameters
 [in] _s the scalar minuend [in] _v vector subtrahend
Returns
difference vector

## ◆ operator<<

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

Stream insertion operator.

Parameters
 _out output stream _pt Vector3 to output
Returns
the stream

## ◆ operator>>

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

Stream extraction operator.

Parameters
 _in input stream _pt vector3 to read values into
Returns
the stream

## ◆ NaN

 const Vector3< T > NaN
static

math::Vector3(NaN, NaN, NaN)

## ◆ One

 const Vector3< T > One
static

math::Vector3(1, 1, 1)

## ◆ UnitX

 const Vector3< T > UnitX
static

math::Vector3(1, 0, 0)

## ◆ UnitY

 const Vector3< T > UnitY
static

math::Vector3(0, 1, 0)

## ◆ UnitZ

 const Vector3< T > UnitZ
static

math::Vector3(0, 0, 1)

## ◆ Zero

 const Vector3< T > Zero
static

math::Vector3(0, 0, 0)

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