A 2D vector class. More...

#include <vector2.h>

Collaboration diagram for argos::CVector2:

Public Member Functions

 CVector2 ()
 Class constructor. More...
 
 CVector2 (Real f_x, Real f_y)
 Class constructor. More...
 
 CVector2 (const std::array< Real, 2 > &arr_coordinates)
 Class constructor. More...
 
 CVector2 (Real f_length, const CRadians &f_angle)
 Class constructor. More...
 
Real GetX () const
 Returns the x coordinate of this vector. More...
 
void SetX (Real f_x)
 Sets the x coordinate of this vector. More...
 
Real GetY () const
 Returns the y coordinate of this vector. More...
 
void SetY (Real f_y)
 Sets the y coordinate of this vector. More...
 
void Set (Real f_x, Real f_y)
 Sets the vector contents from Cartesian coordinates. More...
 
void Set (const std::array< Real, 2 > &arr_coordinates)
 Sets the vector contents from Cartesian coordinates. More...
 
void FromPolarCoordinates (Real f_length, const CRadians &f_angle)
 Sets the vector contents from polar coordinates. More...
 
Real SquareLength () const
 Returns the square length of this vector. More...
 
Real Length () const
 Returns the length of this vector. More...
 
CVector2Normalize ()
 Normalizes this vector. More...
 
CRadians Angle () const
 Returns the angle of this vector. More...
 
CVector2Rotate (const CRadians &c_angle)
 Rotates this vector by the wanted angle. More...
 
Real DotProduct (const CVector2 &c_vector2) const
 Returns the dot product between this vector and the passed one. More...
 
Real CrossProduct (const CVector2 &c_vector2) const
 Returns the cross product between this vector and the passed one. More...
 
CVector2Scale (Real f_scale_x, Real f_scale_y)
 Scales the vector by the wanted values. More...
 
CVector2Perpendicularize ()
 Transforms this vector into its ortogonal. More...
 
CVector2Absolute ()
 Applies Abs() to the coordinates of this vector. More...
 
bool operator== (const CVector2 &c_vector2) const
 Returns true if this vector and the passed one are equal. More...
 
bool operator!= (const CVector2 &c_vector2) const
 Returns true if this vector and the passed one are not equal. More...
 
CVector2operator+= (const CVector2 &c_vector2)
 Sums the passed vector to this vector. More...
 
CVector2operator-= (const CVector2 &c_vector2)
 Subtracts the passed vector from this vector. More...
 
CVector2operator*= (Real f_value)
 Multiplies this vector by the given value. More...
 
CVector2operator/= (Real f_value)
 Divides this vector by the given value. More...
 
CVector2 operator+ (const CVector2 &c_vector2) const
 Returns a new vector containing the sum between this vector and the passed one. More...
 
CVector2 operator- (const CVector2 &c_vector2) const
 Returns a new vector containing the subtraction between this vector and the passed one. More...
 
CVector2 operator* (Real f_value) const
 Returns a new vector containing the multiplication between this vector and the passed value. More...
 
CVector2 operator/ (Real f_value) const
 Returns a new vector containing the division between this vector and the passed value. More...
 
 operator CMatrix< 1, 2 > () const
 Implict conversion to a row matrix. More...
 
 operator CMatrix< 2, 1 > () const
 Implict conversion to a column matrix. More...
 
CVector2 operator- () const
 

Static Public Attributes

static const CVector2 X
 The x axis. More...
 
static const CVector2 Y
 The y axis. More...
 
static const CVector2 ZERO
 The zero vector (0,0) More...
 

Detailed Description

A 2D vector class.

Definition at line 27 of file vector2.h.

Constructor & Destructor Documentation

◆ CVector2() [1/4]

argos::CVector2::CVector2 ( )
inline

Class constructor.

It initializes the vector to (0,0).

See also
ZERO

Definition at line 49 of file vector2.h.

◆ CVector2() [2/4]

argos::CVector2::CVector2 ( Real  f_x,
Real  f_y 
)
inline

Class constructor.

It initializes the vector from Cartesian coordinates.

Parameters
f_xThe x coordinate.
f_yThe y coordinate.
See also
Set()

Definition at line 61 of file vector2.h.

◆ CVector2() [3/4]

argos::CVector2::CVector2 ( const std::array< Real, 2 > &  arr_coordinates)
inline

Class constructor.

It initializes the vector from Cartesian coordinates.

Parameters
arr_coordinatesThe coordinates.
See also
Set()

Definition at line 73 of file vector2.h.

◆ CVector2() [4/4]

argos::CVector2::CVector2 ( Real  f_length,
const CRadians f_angle 
)
inline

Class constructor.

It initializes the vector coordinates from polar coordinates.

Parameters
f_lengththe vector length.
f_anglethe vector angle.
See also
FromPolarCoordinates()

Definition at line 84 of file vector2.h.

Member Function Documentation

◆ Absolute()

CVector2& argos::CVector2::Absolute ( )
inline

Applies Abs() to the coordinates of this vector.

Returns
A reference to this vector.

Definition at line 258 of file vector2.h.

◆ Angle()

CRadians argos::CVector2::Angle ( ) const
inline

Returns the angle of this vector.

Returns
the angle of this vector.

Definition at line 185 of file vector2.h.

◆ CrossProduct()

Real argos::CVector2::CrossProduct ( const CVector2 c_vector2) const
inline

Returns the cross product between this vector and the passed one.

Parameters
c_vector2The other vector.
Returns
The cross product between this vector and the passed one.

Definition at line 223 of file vector2.h.

◆ DotProduct()

Real argos::CVector2::DotProduct ( const CVector2 c_vector2) const
inline

Returns the dot product between this vector and the passed one.

Parameters
c_vector2The other vector.
Returns
The dot product between this vector and the passed one.

Definition at line 214 of file vector2.h.

◆ FromPolarCoordinates()

void argos::CVector2::FromPolarCoordinates ( Real  f_length,
const CRadians f_angle 
)
inline

Sets the vector contents from polar coordinates.

Parameters
f_lengthThe length of the vector.
c_angleThe angle of the vector (range [0,2pi])
See also
Length()
Angle()

Definition at line 148 of file vector2.h.

◆ GetX()

Real argos::CVector2::GetX ( ) const
inline

Returns the x coordinate of this vector.

Returns
The x coordinate of this vector.

Definition at line 94 of file vector2.h.

◆ GetY()

Real argos::CVector2::GetY ( ) const
inline

Returns the y coordinate of this vector.

Returns
The y coordinate of this vector.

Definition at line 110 of file vector2.h.

◆ Length()

Real argos::CVector2::Length ( ) const
inline

Returns the length of this vector.

Returns
The length of this vector.

Definition at line 166 of file vector2.h.

◆ Normalize()

CVector2& argos::CVector2::Normalize ( )
inline

Normalizes this vector.

After this method is called, the vector has length 1. If the vector is (0,0), this call results in a division by zero error.

Returns
A reference to this vector.

Definition at line 176 of file vector2.h.

◆ operator CMatrix< 1, 2 >()

argos::CVector2::operator CMatrix< 1, 2 > ( ) const
inline

Implict conversion to a row matrix.

Definition at line 375 of file vector2.h.

◆ operator CMatrix< 2, 1 >()

argos::CVector2::operator CMatrix< 2, 1 > ( ) const
inline

Implict conversion to a column matrix.

Definition at line 385 of file vector2.h.

◆ operator!=()

bool argos::CVector2::operator!= ( const CVector2 c_vector2) const
inline

Returns true if this vector and the passed one are not equal.

This method checks all the coordinates for equality.

Parameters
c_vector2The other vector.
Returns
true if this vector and the passed one are not equal.

Definition at line 280 of file vector2.h.

◆ operator*()

CVector2 argos::CVector2::operator* ( Real  f_value) const
inline

Returns a new vector containing the multiplication between this vector and the passed value.

Parameters
f_valueThe wanted value.
Returns
A new vector containing the multiplication between this vector and the passed value.

Definition at line 355 of file vector2.h.

◆ operator*=()

CVector2& argos::CVector2::operator*= ( Real  f_value)
inline

Multiplies this vector by the given value.

Parameters
f_valueThe wanted value.
Returns
A reference to this vector.

Definition at line 311 of file vector2.h.

◆ operator+()

CVector2 argos::CVector2::operator+ ( const CVector2 c_vector2) const
inline

Returns a new vector containing the sum between this vector and the passed one.

Parameters
c_vector2The other vector.
Returns
A new vector containing the sum between this vector and the passed one.

Definition at line 333 of file vector2.h.

◆ operator+=()

CVector2& argos::CVector2::operator+= ( const CVector2 c_vector2)
inline

Sums the passed vector to this vector.

Parameters
c_vector2The other vector.
Returns
A reference to this vector.

Definition at line 289 of file vector2.h.

◆ operator-() [1/2]

CVector2 argos::CVector2::operator- ( ) const
inline

Definition at line 403 of file vector2.h.

◆ operator-() [2/2]

CVector2 argos::CVector2::operator- ( const CVector2 c_vector2) const
inline

Returns a new vector containing the subtraction between this vector and the passed one.

Parameters
c_vector2The other vector.
Returns
A new vector containing the subtraction between this vector and the passed one.

Definition at line 344 of file vector2.h.

◆ operator-=()

CVector2& argos::CVector2::operator-= ( const CVector2 c_vector2)
inline

Subtracts the passed vector from this vector.

Parameters
c_vector2The other vector.
Returns
A reference to this vector.

Definition at line 300 of file vector2.h.

◆ operator/()

CVector2 argos::CVector2::operator/ ( Real  f_value) const
inline

Returns a new vector containing the division between this vector and the passed value.

Parameters
f_valueThe wanted value.
Returns
A new vector containing the division between this vector and the passed value.

Definition at line 366 of file vector2.h.

◆ operator/=()

CVector2& argos::CVector2::operator/= ( Real  f_value)
inline

Divides this vector by the given value.

Parameters
f_valueThe wanted value.
Returns
A reference to this vector.

Definition at line 322 of file vector2.h.

◆ operator==()

bool argos::CVector2::operator== ( const CVector2 c_vector2) const
inline

Returns true if this vector and the passed one are equal.

This method checks all the coordinates for equality.

Parameters
c_vector2The other vector.
Returns
true if this vector and the passed one are equal.

Definition at line 270 of file vector2.h.

◆ Perpendicularize()

CVector2& argos::CVector2::Perpendicularize ( )
inline

Transforms this vector into its ortogonal.

Returns
A reference to this vector.

Definition at line 247 of file vector2.h.

◆ Rotate()

CVector2& argos::CVector2::Rotate ( const CRadians c_angle)
inline

Rotates this vector by the wanted angle.

Parameters
c_angleThe rotation angle.
Returns
A reference to this vector.

Definition at line 194 of file vector2.h.

◆ Scale()

CVector2& argos::CVector2::Scale ( Real  f_scale_x,
Real  f_scale_y 
)
inline

Scales the vector by the wanted values.

This method scales the vector by the wanted values. In practice, this means that it multiplies the x coordinate by f_scale_x and the y coordinate by f_scale_y.

Parameters
f_scale_xthe scale factor for the x coordinate.
f_scale_ythe scale factor for the y coordinate.
Returns
A reference to this vector.

Definition at line 236 of file vector2.h.

◆ Set() [1/2]

void argos::CVector2::Set ( const std::array< Real, 2 > &  arr_coordinates)
inline

Sets the vector contents from Cartesian coordinates.

Parameters
arr_coordinatesThe new coordinates.

Definition at line 136 of file vector2.h.

◆ Set() [2/2]

void argos::CVector2::Set ( Real  f_x,
Real  f_y 
)
inline

Sets the vector contents from Cartesian coordinates.

Parameters
f_xThe new x coordinate of this vector.
f_yThe new y coordinate of this vector.

Definition at line 127 of file vector2.h.

◆ SetX()

void argos::CVector2::SetX ( Real  f_x)
inline

Sets the x coordinate of this vector.

Parameters
f_xThe new x coordinate of this vector.

Definition at line 102 of file vector2.h.

◆ SetY()

void argos::CVector2::SetY ( Real  f_y)
inline

Sets the y coordinate of this vector.

Parameters
f_yThe new y coordinate of this vector.

Definition at line 118 of file vector2.h.

◆ SquareLength()

Real argos::CVector2::SquareLength ( ) const
inline

Returns the square length of this vector.

Returns
The square length of this vector.

Definition at line 158 of file vector2.h.

Member Data Documentation

◆ X

const CVector2 argos::CVector2::X
static

The x axis.

Definition at line 36 of file vector2.h.

◆ Y

const CVector2 argos::CVector2::Y
static

The y axis.

Definition at line 39 of file vector2.h.

◆ ZERO

const CVector2 argos::CVector2::ZERO
static

The zero vector (0,0)

Definition at line 42 of file vector2.h.