Gazebo Math

API Reference

8.0.0
Vector2< T > Class Template Reference

Two dimensional (x, y) vector. More...

#include <gz/math/Vector2.hh>

Public Member Functions

constexpr Vector2 ()
 Default Constructor.
 
constexpr Vector2 (const T &_x, const T &_y)
 Constructor.
 
Vector2 Abs () const
 Get the absolute value of the vector.
 
AbsDot (const Vector2< 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.
 
double Distance (const Vector2 &_pt) const
 Calc distance to the given point.
 
Dot (const Vector2< T > &_v) const
 Get the dot product of this vector and _v.
 
bool Equal (const Vector2 &_v, const T &_tol) const
 Equality test with tolerance.
 
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 Vector2< T > &_v)
 Set this vector's components to the maximum of itself and the passed in vector.
 
Min () const
 Get the minimum value in the vector.
 
void Min (const Vector2< T > &_v)
 Set this vector's components to the minimum of itself and the passed in vector.
 
void Normalize ()
 Normalize the vector length.
 
Vector2 Normalized () const
 Returns a normalized vector.
 
bool operator!= (const Vector2 &_v) const
 Not equal to operator.
 
const Vector2 operator* (const Vector2 &_v) const
 Multiplication operators.
 
const Vector2 operator* (T _v) const
 Multiplication operators.
 
const Vector2operator*= (const Vector2 &_v)
 Multiplication assignment operator.
 
const Vector2operator*= (T _v)
 Multiplication assignment operator.
 
Vector2< T > operator+ (const T _s) const
 Addition operators.
 
Vector2 operator+ (const Vector2 &_v) const
 Addition operator.
 
const Vector2< T > & operator+= (const T _s)
 Addition assignment operator.
 
const Vector2operator+= (const Vector2 &_v)
 Addition assignment operator.
 
Vector2 operator- () const
 Negation operator.
 
Vector2< T > operator- (const T _s) const
 Subtraction operators.
 
Vector2 operator- (const Vector2 &_v) const
 Subtraction operator.
 
const Vector2operator-= (const Vector2 &_v)
 Subtraction assignment operator.
 
const Vector2< T > & operator-= (T _s)
 Subtraction assignment operator.
 
const Vector2 operator/ (const Vector2 &_v) const
 Division operator.
 
const Vector2 operator/ (T _v) const
 Division operator.
 
const Vector2operator/= (const Vector2 &_v)
 Division operator.
 
const Vector2operator/= (T _v)
 Division operator.
 
bool operator< (const Vector2< T > &_pt) const
 Less than operator.
 
const Vector2operator= (T _v)
 Assignment operator.
 
bool operator== (const Vector2 &_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.
 
Vector2 Round ()
 Round to near whole number, return the result.
 
Vector2 Rounded () const
 Get a rounded version of this vector.
 
void Set (T _x, T _y)
 Set the contents of the vector.
 
SquaredLength () const
 Returns the square of the length (magnitude) of the vector.
 
Sum () const
 Return the sum of the values.
 
T & X ()
 Return a mutable x value.
 
X () const
 Return the x value.
 
void X (const T &_v)
 Set the x value.
 
T & Y ()
 Return a mutable y value.
 
Y () const
 Return the y value.
 
void Y (const T &_v)
 Set the y value.
 

Static Public Attributes

static const Vector2NaN = detail::gVector2NaN<T>
 math::Vector2(NaN, NaN, NaN)
 
static const Vector2< T > & One = detail::gVector2One<T>
 math::Vector2(1, 1)
 
static const Vector2< T > & Zero = detail::gVector2Zero<T>
 math::Vector2(0, 0)
 

Detailed Description

template<typename T>
class gz::math::Vector2< T >

Two dimensional (x, y) vector.

Constructor & Destructor Documentation

◆ Vector2() [1/2]

◆ Vector2() [2/2]

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

Constructor.

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

Member Function Documentation

◆ Abs()

template<typename T >
Vector2 Abs ( ) const
inline

Get the absolute value of the vector.

Returns
a vector with positive elements

References Vector2< T >::Vector2().

◆ AbsDot()

template<typename T >
T AbsDot ( const Vector2< 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)

Parameters
[in]_vThe vector
Returns
The absolute dot product

◆ Correct()

template<typename T >
void Correct ( )
inline

Corrects any nan values.

References std::isfinite().

◆ Distance()

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

Calc distance to the given point.

Parameters
[in]_ptThe point to measure to
Returns
the distance

◆ Dot()

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

Get the dot product of this vector and _v.

Parameters
[in]_vthe vector
Returns
The dot product

◆ Equal()

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

◆ IsFinite()

template<typename T >
bool IsFinite ( ) const
inline

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

Returns
true if finite, false otherwise

References std::isfinite().

◆ Length()

template<typename T >
T Length ( ) const
inline

Returns the length (magnitude) of the vector.

Returns
The length

References Vector2< T >::SquaredLength().

Referenced by Vector2< 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 Vector2< 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().

◆ 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 Vector2< 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().

◆ Normalize()

template<typename T >
void Normalize ( )
inline

Normalize the vector length.

References Vector2< T >::Length().

◆ Normalized()

template<typename T >
Vector2 Normalized ( ) const
inline

Returns a normalized vector.

Returns
unit length vector

◆ operator!=()

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

Not equal to operator.

Returns
true if elements are of diffent values (tolerence 1e-6)

◆ operator*() [1/2]

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

Multiplication operators.

Parameters
[in]_vthe vector
Returns
the result

References Vector2< T >::Vector2().

◆ operator*() [2/2]

template<typename T >
const Vector2 operator* ( _v) const
inline

Multiplication operators.

Parameters
[in]_vthe scaling factor
Returns
a scaled vector

References Vector2< T >::Vector2().

◆ operator*=() [1/2]

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

Multiplication assignment operator.

Remarks
this is an element wise multiplication
Parameters
[in]_vthe vector
Returns
this

◆ operator*=() [2/2]

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

Multiplication assignment operator.

Parameters
[in]_vthe scaling factor
Returns
a scaled vector

◆ operator+() [1/2]

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

Addition operators.

Parameters
[in]_sthe scalar addend
Returns
sum vector

◆ operator+() [2/2]

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

Addition operator.

Parameters
[in]_vvector to add
Returns
sum vector

References Vector2< T >::Vector2().

◆ operator+=() [1/2]

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

Addition assignment operator.

Parameters
[in]_sscalar addend
Returns
this

◆ operator+=() [2/2]

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

Addition assignment operator.

Parameters
[in]_vthe vector to add

◆ operator-() [1/3]

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

Negation operator.

Returns
negative of this vector

References Vector2< T >::Vector2().

◆ operator-() [2/3]

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

Subtraction operators.

Parameters
[in]_sthe scalar subtrahend
Returns
difference vector

◆ operator-() [3/3]

template<typename T >
Vector2 operator- ( const Vector2< T > &  _v) const
inline

Subtraction operator.

Parameters
[in]_vthe vector to substract
Returns
the subtracted vector

References Vector2< T >::Vector2().

◆ operator-=() [1/2]

template<typename T >
const Vector2 & operator-= ( const Vector2< T > &  _v)
inline

Subtraction assignment operator.

Parameters
[in]_vthe vector to substract
Returns
this

◆ operator-=() [2/2]

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

Subtraction assignment operator.

Parameters
[in]_sscalar subtrahend
Returns
this

◆ operator/() [1/2]

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

Division operator.

Remarks
this is an element wise division
Parameters
[in]_va vector
Returns
a result

References Vector2< T >::Vector2().

◆ operator/() [2/2]

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

Division operator.

Parameters
[in]_vthe value
Returns
a vector

References Vector2< T >::Vector2().

◆ operator/=() [1/2]

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

Division operator.

Remarks
this is an element wise division
Parameters
[in]_va vector
Returns
this

◆ operator/=() [2/2]

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

Division operator.

Parameters
[in]_vthe divisor
Returns
a vector

◆ operator<()

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

Less than operator.

Parameters
[in]_ptVector to compare.
Returns
True if this vector's first or second value is less than the given vector's first or second value.

◆ operator=()

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

Assignment operator.

Parameters
[in]_vthe value for x and y element
Returns
this

◆ operator==()

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

Equal to operator.

Parameters
[in]_vthe vector to compare to
Returns
true if the elements of the 2 vectors are equal within a tolerence (1e-6)

References Vector2< 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 and 1 == y. The index is clamped to the range [0,1].

References gz::math::clamp(), gz::math::GZ_ONE_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 and 1 == y. The index is clamped to the range [0,1].

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

◆ Round()

template<typename T >
Vector2 Round ( )
inline

Round to near whole number, return the result.

Returns
the result

References std::nearbyint().

◆ Rounded()

template<typename T >
Vector2 Rounded ( ) const
inline

Get a rounded version of this vector.

Returns
a rounded vector

◆ Set()

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

Set the contents of the vector.

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

◆ SquaredLength()

template<typename T >
T SquaredLength ( ) const
inline

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

Returns
The squared length

Referenced by Vector2< 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

Return a mutable x value.

Returns
Value of the X component.

◆ X() [2/3]

template<typename T >
T X ( ) const
inline

Return the x value.

Returns
Value of the X component.

◆ 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

Return a mutable y value.

Returns
Value of the Y component.

◆ Y() [2/3]

template<typename T >
T Y ( ) const
inline

Return the y value.

Returns
Value of the Y component.

◆ Y() [3/3]

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

Set the y value.

Parameters
[in]_vValue for the y component.

Member Data Documentation

◆ NaN

template<typename T >
const Vector2< T > & NaN = detail::gVector2NaN<T>
static

math::Vector2(NaN, NaN, NaN)

◆ One

template<typename T >
const Vector2< T > & One = detail::gVector2One<T>
static

math::Vector2(1, 1)

◆ Zero

template<typename T >
const Vector2< T > & Zero = detail::gVector2Zero<T>
static

math::Vector2(0, 0)


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