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 (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 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...
 
CVector2 operator- () const
 

Static Public Attributes

static const CVector2 X
 The x axis. More...
 
static const CVector2 Y
 The y axis. 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 25 of file vector2.h.

Constructor & Destructor Documentation

argos::CVector2::CVector2 ( )
inline

Class constructor.

It initializes the vector to (0,0).

See also
ZERO

Definition at line 43 of file vector2.h.

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 55 of file vector2.h.

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 68 of file vector2.h.

Member Function Documentation

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

Applies Abs() to the coordinates of this vector.

Returns
A reference to this vector.

Definition at line 233 of file vector2.h.

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

Returns the angle of this vector.

Returns
the angle of this vector.

Definition at line 160 of file vector2.h.

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 198 of file vector2.h.

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 189 of file vector2.h.

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 123 of file vector2.h.

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

Returns the x coordinate of this vector.

Returns
The x coordinate of this vector.

Definition at line 78 of file vector2.h.

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

Returns the y coordinate of this vector.

Returns
The y coordinate of this vector.

Definition at line 94 of file vector2.h.

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

Returns the length of this vector.

Returns
The length of this vector.

Definition at line 141 of file vector2.h.

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 151 of file vector2.h.

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 255 of file vector2.h.

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 330 of file vector2.h.

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 286 of file vector2.h.

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 308 of file vector2.h.

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 264 of file vector2.h.

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 319 of file vector2.h.

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

Definition at line 358 of file vector2.h.

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 275 of file vector2.h.

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 341 of file vector2.h.

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 297 of file vector2.h.

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 245 of file vector2.h.

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

Transforms this vector into its ortogonal.

Returns
A reference to this vector.

Definition at line 222 of file vector2.h.

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 169 of file vector2.h.

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 211 of file vector2.h.

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 111 of file vector2.h.

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 86 of file vector2.h.

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 102 of file vector2.h.

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

Returns the square length of this vector.

Returns
The square length of this vector.

Definition at line 133 of file vector2.h.

Friends And Related Function Documentation

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 353 of file vector2.h.

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 368 of file vector2.h.

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 381 of file vector2.h.

Member Data Documentation

const CVector2 argos::CVector2::X
static

The x axis.

Definition at line 33 of file vector2.h.

const CVector2 argos::CVector2::Y
static

The y axis.

Definition at line 36 of file vector2.h.