Gazebo Math

API Reference

8.0.0

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 <gz/math/Vector3.hh>

Public Member Functions

constexpr Vector3 ()
 Constructor.
 
constexpr Vector3 (const T &_x, const T &_y, const T &_z)
 Constructor.
 
Vector3 Abs () const
 Get the absolute value of the vector.
 
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.
 
void Correct ()
 Corrects any nan values.
 
Vector3 Cross (const Vector3< T > &_v) const
 Return the cross product of this vector with another vector.
 
Distance (const Vector3< T > &_pt) const
 Calc distance to the given point.
 
Distance (T _x, T _y, T _z) const
 Calc distance to the given point.
 
DistToLine (const Vector3< T > &_pt1, const Vector3 &_pt2)
 Get distance to an infinite line defined by 2 points.
 
Dot (const Vector3< T > &_v) const
 Return the dot product of this vector and another vector.
 
bool Equal (const Vector3 &_v, const T &_tol) const
 Equality test with tolerance.
 
bool Equal (const Vector3< T > &_v) const
 Equality test.
 
bool IsFinite () const
 See if a point is finite (e.g., not nan)
 
Length () const
 Returns the length (magnitude) of the vector.
 
Max () const
 Get the maximum value in the vector.
 
void Max (const Vector3< T > &_v)
 Set this vector's components to the maximum of itself and the passed in vector.
 
MaxAbs () const
 Get the number with the maximum absolute value in the vector.
 
Min () const
 Get the minimum value in the vector.
 
void Min (const Vector3< T > &_v)
 Set this vector's components to the minimum of itself and the passed in vector.
 
MinAbs () const
 Get the number with the maximum absolute value in the vector.
 
Vector3 Normalize ()
 Normalize the vector length.
 
Vector3 Normalized () const
 Return a normalized vector.
 
bool operator!= (const Vector3< T > &_v) const
 Not equal to operator.
 
Vector3< T > operator* (const Vector3< T > &_p) const
 Multiplication operator.
 
Vector3< T > operator* (T _s) const
 Multiplication operators.
 
const Vector3< T > & operator*= (const Vector3< T > &_v)
 Multiplication assignment operators.
 
const Vector3< T > & operator*= (T _v)
 Multiplication operator.
 
Vector3< T > operator+ (const T _s) const
 Addition operators.
 
Vector3 operator+ (const Vector3< T > &_v) const
 Addition operator.
 
const Vector3< T > & operator+= (const T _s)
 Addition assignment operator.
 
const Vector3operator+= (const Vector3< T > &_v)
 Addition assignment operator.
 
Vector3 operator- () const
 Negation operator.
 
Vector3< T > operator- (const T _s) const
 Subtraction operators.
 
Vector3< T > operator- (const Vector3< T > &_pt) const
 Subtraction operators.
 
const Vector3< T > & operator-= (const T _s)
 Subtraction assignment operator.
 
const Vector3< T > & operator-= (const Vector3< T > &_pt)
 Subtraction assignment operators.
 
const Vector3< T > operator/ (const Vector3< T > &_pt) const
 Division operator.
 
const Vector3< T > operator/ (T _v) const
 Division operator.
 
const Vector3< T > & operator/= (const Vector3< T > &_pt)
 Division assignment operator.
 
const Vector3< T > & operator/= (T _v)
 Division assignment operator.
 
bool operator< (const Vector3< T > &_pt) const
 Less than operator.
 
Vector3operator= (T _v)
 Assignment operator.
 
bool operator== (const Vector3< T > &_v) const
 Equal to operator.
 
T & operator[] (const std::size_t _index)
 Array subscript operator.
 
operator[] (const std::size_t _index) const
 Const-qualified array subscript operator.
 
Vector3 Perpendicular () const
 Return a vector that is perpendicular to this one.
 
Vector3 Round ()
 Round to near whole number, return the result.
 
void Round (int _precision)
 Round all values to _precision decimal places.
 
Vector3 Rounded () const
 Get a rounded version of this vector.
 
void Set (T _x=0, T _y=0, T _z=0)
 Set the contents of the vector.
 
SquaredLength () const
 Return the square of the length (magnitude) of the vector.
 
Sum () const
 Return the sum of the values.
 
T & X ()
 Get a mutable reference to the x value.
 
X () const
 Get the x value.
 
void X (const T &_v)
 Set the x value.
 
T & Y ()
 Get a mutable reference to the y value.
 
Y () const
 Get the y value.
 
void Y (const T &_v)
 Set the y value.
 
T & Z ()
 Get a mutable reference to the z value.
 
Z () const
 Get the z value.
 
void Z (const T &_v)
 Set the z value.
 

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.
 

Static Public Attributes

static const Vector3NaN = detail::gVector3NaN<T>
 math::Vector3(NaN, NaN, NaN)
 
static const Vector3One = detail::gVector3One<T>
 math::Vector3(1, 1, 1)
 
static const Vector3UnitX = detail::gVector3UnitX<T>
 math::Vector3(1, 0, 0)
 
static const Vector3UnitY = detail::gVector3UnitY<T>
 math::Vector3(0, 1, 0)
 
static const Vector3UnitZ = detail::gVector3UnitZ<T>
 math::Vector3(0, 0, 1)
 
static const Vector3Zero = detail::gVector3Zero<T>
 math::Vector3(0, 0, 0)
 

Detailed Description

template<typename T>
class gz::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.

Constructor & Destructor Documentation

◆ Vector3() [1/2]

◆ Vector3() [2/2]

template<typename T >
constexpr Vector3 ( const T &  _x,
const T &  _y,
const T &  _z 
)
inlineconstexpr

Constructor.

Parameters
[in]_xvalue along x
[in]_yvalue along y
[in]_zvalue along z

Member Function Documentation

◆ Abs()

template<typename T >
Vector3 Abs ( ) const
inline

Get the absolute value of the vector.

Returns
a vector with positive elements

References Vector3< T >::Vector3().

◆ AbsDot()

template<typename T >
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]_vthe vector
Returns
The absolute dot product

◆ Correct()

template<typename T >
void Correct ( )
inline

Corrects any nan values.

References std::isfinite().

◆ Cross()

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

Return the cross product of this vector with another vector.

Parameters
[in]_va vector
Returns
the cross product

References Vector3< T >::Vector3().

Referenced by Vector3< T >::DistToLine(), Plane< T >::Intersection(), and Vector3< T >::Perpendicular().

◆ Distance() [1/2]

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

Calc distance to the given point.

Parameters
[in]_ptthe point
Returns
the distance

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

◆ Distance() [2/2]

template<typename T >
T Distance ( _x,
_y,
_z 
) const
inline

Calc distance to the given point.

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

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

◆ DistToLine()

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

Get distance to an infinite line defined by 2 points.

Parameters
[in]_pt1first point on the line
[in]_pt2second point on the line
Returns
the minimum distance from this point to the line

References Vector3< T >::Cross(), and Vector3< T >::Length().

◆ Dot()

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

Return the dot product of this vector and another vector.

Parameters
[in]_vthe vector
Returns
the dot product

Referenced by Plane< T >::Intersection().

◆ Equal() [1/2]

template<typename T >
bool Equal ( const Vector3< 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 Vector3< T >::operator==().

◆ Equal() [2/2]

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

Equality test.

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

◆ IsFinite()

template<typename T >
bool IsFinite ( ) const
inline

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

Returns
true if is finite or false otherwise

References std::isfinite().

◆ Length()

template<typename T >
T Length ( ) const
inline

Returns the length (magnitude) of the vector.

Returns
the length

References Vector3< T >::SquaredLength().

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

◆ Max() [1/2]

template<typename T >
T Max ( ) const
inline

Get the maximum value in the vector.

Returns
the maximum element

References std::max().

◆ Max() [2/2]

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

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

Parameters
[in]_vthe maximum clamping vector

◆ MaxAbs()

template<typename T >
T MaxAbs ( ) const
inline

Get the number with the maximum absolute value in the vector.

Returns
the element with maximum absolute value

References gz::math::max(), and std::max().

◆ Min() [1/2]

template<typename T >
T Min ( ) const
inline

Get the minimum value in the vector.

Returns
the minimum element

References std::min().

◆ Min() [2/2]

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

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

Parameters
[in]_vthe minimum clamping vector

◆ MinAbs()

template<typename T >
T MinAbs ( ) const
inline

Get the number with the maximum absolute value in the vector.

Returns
the element with minimum absolute value

References gz::math::min(), and std::min().

◆ Normal()

template<typename T >
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]_v1first vertex of the triangle
[in]_v2second vertex
[in]_v3third vertex
Returns
the normal

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

◆ Normalize()

template<typename T >
Vector3 Normalize ( )
inline

Normalize the vector length.

Returns
unit length vector

References Vector3< T >::Length().

Referenced by Matrix4< T >::LookAt().

◆ Normalized()

template<typename T >
Vector3 Normalized ( ) const
inline

Return a normalized vector.

Returns
unit length vector

◆ operator!=()

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

Not equal to operator.

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

◆ operator*() [1/2]

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

Multiplication operator.

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

References Vector3< T >::Vector3().

◆ operator*() [2/2]

template<typename T >
Vector3< T > operator* ( _s) const
inline

Multiplication operators.

Parameters
[in]_sthe scaling factor
Returns
a scaled vector

◆ operator*=() [1/2]

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

Multiplication assignment operators.

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

◆ operator*=() [2/2]

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

Multiplication operator.

Parameters
[in]_vscaling factor
Returns
this

◆ operator+() [1/2]

template<typename T >
Vector3< T > operator+ ( const _s) const
inline

Addition operators.

Parameters
[in]_sthe scalar addend
Returns
sum vector

◆ operator+() [2/2]

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

Addition operator.

Parameters
[in]_vvector to add
Returns
the sum vector

References Vector3< T >::Vector3().

◆ operator+=() [1/2]

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

Addition assignment operator.

Parameters
[in]_sscalar addend
Returns
this

◆ operator+=() [2/2]

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

Addition assignment operator.

Parameters
[in]_vvector to add
Returns
the sum vector

◆ operator-() [1/3]

template<typename T >
Vector3 operator- ( ) const
inline

Negation operator.

Returns
negative of this vector

References Vector3< T >::Vector3().

◆ operator-() [2/3]

template<typename T >
Vector3< T > operator- ( const _s) const
inline

Subtraction operators.

Parameters
[in]_sthe scalar subtrahend
Returns
difference vector

◆ operator-() [3/3]

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

Subtraction operators.

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

References Vector3< T >::Vector3().

◆ operator-=() [1/2]

template<typename T >
const Vector3< T > & operator-= ( const _s)
inline

Subtraction assignment operator.

Parameters
[in]_sscalar subtrahend
Returns
this

◆ operator-=() [2/2]

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

Subtraction assignment operators.

Parameters
[in]_ptsubtrahend
Returns
a vector after the substraction

◆ operator/() [1/2]

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

Division operator.

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

References Vector3< T >::Vector3().

◆ operator/() [2/2]

template<typename T >
const Vector3< T > operator/ ( _v) const
inline

Division operator.

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

References Vector3< T >::Vector3().

◆ operator/=() [1/2]

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

Division assignment operator.

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

◆ operator/=() [2/2]

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

Division assignment operator.

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

◆ operator<()

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

Less than operator.

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

◆ operator=()

template<typename T >
Vector3 & operator= ( _v)
inline

Assignment operator.

Parameters
[in]_vassigned to all elements
Returns
this

◆ operator==()

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

Equal to operator.

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

References Vector3< T >::Equal().

◆ operator[]() [1/2]

template<typename T >
T & operator[] ( const std::size_t  _index)
inline

Array subscript operator.

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

References gz::math::clamp(), gz::math::GZ_TWO_SIZE_T, and gz::math::GZ_ZERO_SIZE_T.

◆ operator[]() [2/2]

template<typename T >
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. The index is clamped to the range [0,2].
Returns
The value.

References gz::math::clamp(), gz::math::GZ_TWO_SIZE_T, and gz::math::GZ_ZERO_SIZE_T.

◆ Perpendicular()

template<typename T >
Vector3 Perpendicular ( ) const
inline

Return a vector that is perpendicular to this one.

Returns
an orthogonal vector

References Vector3< T >::Vector3(), and Vector3< T >::Cross().

◆ Round() [1/2]

template<typename T >
Vector3 Round ( )
inline

Round to near whole number, return the result.

Returns
the result

References std::nearbyint().

◆ Round() [2/2]

template<typename T >
void Round ( int  _precision)
inline

Round all values to _precision decimal places.

Parameters
[in]_precisionthe decimal places

References gz::math::precision().

◆ Rounded()

template<typename T >
Vector3 Rounded ( ) const
inline

Get a rounded version of this vector.

Returns
a rounded vector

◆ Set()

template<typename T >
void Set ( _x = 0,
_y = 0,
_z = 0 
)
inline

Set the contents of the vector.

Parameters
[in]_xvalue along x
[in]_yvalue along y
[in]_zvalue aling z

◆ SquaredLength()

template<typename T >
T SquaredLength ( ) const
inline

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

Returns
the squared length

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

◆ Sum()

template<typename T >
T Sum ( ) const
inline

Return the sum of the values.

Returns
the sum

◆ X() [1/3]

template<typename T >
T & X ( )
inline

Get a mutable reference to the x value.

Returns
The x component of the vector

◆ X() [2/3]

template<typename T >
T X ( ) const
inline

Get the x value.

Returns
The x component of the vector

◆ X() [3/3]

template<typename T >
void X ( const T &  _v)
inline

Set the x value.

Parameters
[in]_vValue for the x component.

◆ Y() [1/3]

template<typename T >
T & Y ( )
inline

Get a mutable reference to the y value.

Returns
The y component of the vector

◆ Y() [2/3]

template<typename T >
T Y ( ) const
inline

Get the y value.

Returns
The y component of the vector

◆ Y() [3/3]

template<typename T >
void Y ( const T &  _v)
inline

Set the y value.

Parameters
[in]_vValue for the y component.

◆ Z() [1/3]

template<typename T >
T & Z ( )
inline

Get a mutable reference to the z value.

Returns
The z component of the vector

◆ Z() [2/3]

template<typename T >
T Z ( ) const
inline

Get the z value.

Returns
The z component of the vector

◆ Z() [3/3]

template<typename T >
void Z ( const T &  _v)
inline

Set the z value.

Parameters
[in]_vValue for the z component.

Member Data Documentation

◆ NaN

template<typename T >
const Vector3< T > & NaN = detail::gVector3NaN<T>
static

math::Vector3(NaN, NaN, NaN)

◆ One

template<typename T >
const Vector3< T > & One = detail::gVector3One<T>
static

math::Vector3(1, 1, 1)

◆ UnitX

template<typename T >
const Vector3< T > & UnitX = detail::gVector3UnitX<T>
static

math::Vector3(1, 0, 0)

◆ UnitY

template<typename T >
const Vector3< T > & UnitY = detail::gVector3UnitY<T>
static

math::Vector3(0, 1, 0)

◆ UnitZ

template<typename T >
const Vector3< T > & UnitZ = detail::gVector3UnitZ<T>
static

math::Vector3(0, 0, 1)

◆ Zero

template<typename T >
const Vector3< T > & Zero = detail::gVector3Zero<T>
static

math::Vector3(0, 0, 0)


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