Ignition Math

API Reference

5.1.0
Vector2< T > Class Template Reference

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

#include <ignition/math/Vector2.hh>

Public Member Functions

 Vector2 ()
 Default Constructor. More...
 
 Vector2 (const T &_x, const T &_y)
 Constructor. More...
 
 Vector2 (const Vector2< T > &_v)
 Copy constructor. More...
 
virtual ~Vector2 ()
 Destructor. More...
 
double Distance (const Vector2 &_pt) const
 Calc distance to the given point. More...
 
Dot (const Vector2< T > &_v) const
 Get the dot product of this vector and _v. More...
 
bool Equal (const Vector2 &_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 Normalize ()
 Normalize the vector length. More...
 
bool operator!= (const Vector2 &_v) const
 Not equal to operator. More...
 
const Vector2 operator* (const Vector2 &_v) const
 Multiplication operators. More...
 
const Vector2 operator* (T _v) const
 Multiplication operators. More...
 
const Vector2operator*= (const Vector2 &_v)
 Multiplication assignment operator. More...
 
const Vector2operator*= (T _v)
 Multiplication assignment operator. More...
 
Vector2 operator+ (const Vector2 &_v) const
 Addition operator. More...
 
Vector2< T > operator+ (const T _s) const
 Addition operators. More...
 
const Vector2operator+= (const Vector2 &_v)
 Addition assignment operator. More...
 
const Vector2< T > & operator+= (const T _s)
 Addition assignment operator. More...
 
Vector2 operator- () const
 Negation operator. More...
 
Vector2 operator- (const Vector2 &_v) const
 Subtraction operator. More...
 
Vector2< T > operator- (const T _s) const
 Subtraction operators. More...
 
const Vector2operator-= (const Vector2 &_v)
 Subtraction assignment operator. More...
 
const Vector2< T > & operator-= (T _s)
 Subtraction assignment operator. More...
 
const Vector2 operator/ (const Vector2 &_v) const
 Division operator. More...
 
const Vector2 operator/ (T _v) const
 Division operator. More...
 
const Vector2operator/= (const Vector2 &_v)
 Division operator. More...
 
const Vector2operator/= (T _v)
 Division operator. More...
 
bool operator< (const Vector2< T > &_pt) const
 Less than operator. More...
 
Vector2operator= (const Vector2 &_v)
 Assignment operator. More...
 
const Vector2operator= (T _v)
 Assignment operator. More...
 
bool operator== (const Vector2 &_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 Set (T _x, T _y)
 Set the contents of the vector. More...
 
SquaredLength () const
 Returns the square of the length (magnitude) of the vector. More...
 
X () const
 Return the x value. More...
 
T & X ()
 Return a mutable x value. More...
 
void X (const T &_v)
 Set the x value. More...
 
Y () const
 Return the y value. More...
 
T & Y ()
 Return a mutable y value. More...
 
void Y (const T &_v)
 Set the y value. More...
 

Static Public Attributes

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

Friends

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

Detailed Description

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

Two dimensional (x, y) vector.

Constructor & Destructor Documentation

◆ Vector2() [1/3]

◆ Vector2() [2/3]

Vector2 ( const T &  _x,
const T &  _y 
)
inline

Constructor.

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

◆ Vector2() [3/3]

Vector2 ( const Vector2< T > &  _v)
inline

Copy constructor.

Parameters
[in]_vthe value

◆ ~Vector2()

virtual ~Vector2 ( )
inlinevirtual

Destructor.

Member Function Documentation

◆ Distance()

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()

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

Referenced by Triangle< T >::Contains().

◆ Equal()

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()

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 Vector2< T >::SquaredLength().

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

◆ Normalize()

void Normalize ( )
inline

Normalize the vector length.

References Vector2< T >::Length().

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

◆ operator!=()

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]

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]

const Vector2 operator* ( _v) const
inline

Multiplication operators.

Parameters
[in]_vthe scaling factor
Returns
a scaled vector

References Vector2< T >::Vector2().

◆ operator*=() [1/2]

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]

const Vector2& operator*= ( _v)
inline

Multiplication assignment operator.

Parameters
[in]_vthe scaling factor
Returns
a scaled vector

◆ operator+() [1/2]

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

Addition operator.

Parameters
[in]_vvector to add
Returns
sum vector

References Vector2< T >::Vector2().

◆ operator+() [2/2]

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

Addition operators.

Parameters
[in]_sthe scalar addend
Returns
sum vector

◆ operator+=() [1/2]

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

Addition assignment operator.

Parameters
[in]_vthe vector to add

◆ operator+=() [2/2]

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

Addition assignment operator.

Parameters
[in]_sscalar addend
Returns
this

◆ operator-() [1/3]

Vector2 operator- ( ) const
inline

Negation operator.

Returns
negative of this vector

References Vector2< T >::Vector2().

◆ operator-() [2/3]

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-() [3/3]

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

Subtraction operators.

Parameters
[in]_sthe scalar subtrahend
Returns
difference vector

◆ operator-=() [1/2]

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

Subtraction assignment operator.

Parameters
[in]_vthe vector to substract
Returns
this

◆ operator-=() [2/2]

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

Subtraction assignment operator.

Parameters
[in]_sscalar subtrahend
Returns
this

◆ operator/() [1/2]

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]

const Vector2 operator/ ( _v) const
inline

Division operator.

Parameters
[in]_vthe value
Returns
a vector

References Vector2< T >::Vector2().

◆ operator/=() [1/2]

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]

const Vector2& operator/= ( _v)
inline

Division operator.

Parameters
[in]_vthe divisor
Returns
a vector

◆ operator<()

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=() [1/2]

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

Assignment operator.

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

◆ operator=() [2/2]

const Vector2& operator= ( _v)
inline

Assignment operator.

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

◆ operator==()

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]

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

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

◆ Set()

void Set ( _x,
_y 
)
inline

Set the contents of the vector.

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

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

◆ SquaredLength()

T SquaredLength ( ) const
inline

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

Returns
The squared length

References std::pow().

Referenced by Vector2< T >::Length(), MassMatrix3< T >::PrincipalAxesOffset(), and MassMatrix3< T >::SetFromSphere().

◆ X() [1/3]

T X ( ) const
inline

Return the x value.

Returns
Value of the X component.

Referenced by Line2< T >::CrossProduct(), Line2< T >::Intersect(), and Line2< T >::Within().

◆ X() [2/3]

T& X ( )
inline

Return a mutable x value.

Returns
Value of the X component.

◆ 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 ( ) const
inline

Return the y value.

Returns
Value of the Y component.

Referenced by Line2< T >::CrossProduct(), Line2< T >::Intersect(), and Line2< T >::Within().

◆ Y() [2/3]

T& Y ( )
inline

Return a mutable y value.

Returns
Value of the Y component.

◆ Y() [3/3]

void Y ( const T &  _v)
inline

Set the y value.

Parameters
[in]_vValue for the y component.

Friends And Related Function Documentation

◆ operator*

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

Scalar left multiplication operators.

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

◆ operator+

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

Addition operators.

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

◆ operator-

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

Subtraction operators.

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

◆ operator<<

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

Stream extraction operator.

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

◆ operator>>

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

Stream extraction operator.

Parameters
[in]_ininput stream
[in]_ptVector2 to read values into
Returns
The stream

Member Data Documentation

◆ One

const Vector2< T > One
static

math::Vector2(1, 1)

◆ Zero

const Vector2< T > Zero
static

math::Vector2(0, 0)


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