Warning: include(php/utility.php): Failed to open stream: No such file or directory in /home/argos/argos3/doc/api/embedded/a02418.php on line 2

Warning: include(): Failed opening 'php/utility.php' for inclusion (include_path='.:/usr/lib64/php') in /home/argos/argos3/doc/api/embedded/a02418.php on line 2
The ARGoS Website

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...
 

Friends

CVector2 operator* (Real f_value, const CVector2 &c_vector2)
 Returns a new vector containing the multiplication between the passed value and the passed vector. More...
 
std::ostream & operator<< (std::ostream &c_os, const CVector2 &c_vector2)
 Serializes the contents of the passed vector onto a stream. More...
 
std::istream & operator>> (std::istream &c_is, CVector2 &c_vector2)
 Deserializes the contents of a stream and stores them into the passed vector. 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 48 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 60 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 72 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 83 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 257 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 184 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_vector3The other vector.
Returns
The cross product between this vector and the passed one.

Definition at line 222 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_vector3The other vector.
Returns
The dot product between this vector and the passed one.

Definition at line 213 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 147 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 93 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 109 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 165 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 175 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 374 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 384 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 279 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 354 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 310 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 332 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 288 of file vector2.h.

◆ operator-() [1/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 343 of file vector2.h.

◆ operator-() [2/2]

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

Definition at line 402 of file vector2.h.

◆ operator-=()

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

Subtracts the passed vector from this vector.

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

Definition at line 299 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 365 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 321 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 269 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 246 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 193 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 235 of file vector2.h.

◆ Set() [1/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 126 of file vector2.h.

◆ Set() [2/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 135 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 101 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 117 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 157 of file vector2.h.

Friends And Related Function Documentation

◆ operator*

CVector2 operator* ( Real  f_value,
const CVector2 c_vector2 
)
friend

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

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

Definition at line 397 of file vector2.h.

◆ operator<<

std::ostream& operator<< ( std::ostream &  c_os,
const CVector2 c_vector2 
)
friend

Serializes the contents of the passed vector onto a stream.

Parameters
c_osThe stream.
c_vector2The vector.
Returns
The new state of the stream.

Definition at line 412 of file vector2.h.

◆ operator>>

std::istream& operator>> ( std::istream &  c_is,
CVector2 c_vector2 
)
friend

Deserializes the contents of a stream and stores them into the passed vector.

Parameters
c_isThe stream.
c_vector2The vector.
Returns
The new state of the stream.

Definition at line 425 of file vector2.h.

Member Data Documentation

◆ X

const CVector2 argos::CVector2::X
static

The x axis.

Definition at line 35 of file vector2.h.

◆ Y

const CVector2 argos::CVector2::Y
static

The y axis.

Definition at line 38 of file vector2.h.

◆ ZERO

const CVector2 argos::CVector2::ZERO
static

The zero vector (0,0)

Definition at line 41 of file vector2.h.