A 3D vector class. More...

#include <vector3.h>

Collaboration diagram for argos::CVector3:

Public Member Functions

 CVector3 ()
 Class constructor. More...
 
 CVector3 (Real f_x, Real f_y, Real f_z)
 Class constructor. More...
 
 CVector3 (const std::array< Real, 3 > &arr_coordinates)
 Class constructor. More...
 
 CVector3 (Real f_length, const CRadians &c_inclination, const CRadians &c_azimuth)
 Class constructor. More...
 
Real GetX () const
 Returns the x coordinate of this vector. More...
 
void SetX (const Real f_x)
 Sets the x coordinate of this vector. More...
 
Real GetY () const
 Returns the y coordinate of this vector. More...
 
void SetY (const Real f_y)
 Sets the y coordinate of this vector. More...
 
Real GetZ () const
 Returns the z coordinate of this vector. More...
 
void SetZ (const Real f_z)
 Sets the z coordinate of this vector. More...
 
void Set (const Real f_x, const Real f_y, const Real f_z)
 Sets the vector contents from Cartesian coordinates. More...
 
void Set (const std::array< Real, 3 > &arr_coordinates)
 Sets the vector contents from Cartesian coordinates. More...
 
CVector3FromSphericalCoords (Real f_length, const CRadians &c_inclination, const CRadians &c_azimuth)
 Sets the vector contents from spherical coordinates. More...
 
void ToSphericalCoords (Real &f_radius, CRadians &c_inclination, CRadians &c_azimuth) const
 Returns the vector contents as spherical coordinates. More...
 
Real SquareLength () const
 Returns the square length of this vector. More...
 
Real Length () const
 Returns the length of this vector. More...
 
CVector3Normalize ()
 Normalizes this vector. More...
 
CVector3RotateX (const CRadians &c_angle)
 Rotates this vector wrt the x axis. More...
 
CVector3RotateY (const CRadians &c_angle)
 Rotates this vector wrt the y axis. More...
 
CVector3RotateZ (const CRadians &c_angle)
 Rotates this vector wrt the z axis. More...
 
CVector3RotateZ (const CVector2 &c_vector)
 Rotates this vector wrt the z axis. More...
 
CVector3Rotate (const CQuaternion &c_quaternion)
 Rotates this vector by the given quaternion. More...
 
CRadians GetAngleWith (const CVector3 &c_other)
 Returns the angle between this vector and the passed vector. More...
 
CRadians GetXAngle () const
 Returns the angle between this vector and the x axis. More...
 
CRadians GetYAngle () const
 Returns the angle between this vector and the y axis. More...
 
CRadians GetZAngle () const
 Returns the angle between this vector and the z axis. More...
 
Real DotProduct (const CVector3 &c_vector3) const
 Returns the dot product between this vector and the passed one. More...
 
CVector3CrossProduct (const CVector3 &c_vector3)
 Calculates the cross product between this vector and the passed one. More...
 
CVector2ProjectOntoXY (CVector2 &c_proj) const
 Calculates the projection of this vector onto the xy plane. More...
 
CVector2ProjectOntoYZ (CVector2 &c_proj) const
 Calculates the projection of this vector onto the yz plane. More...
 
CVector2ProjectOntoXZ (CVector2 &c_proj) const
 Calculates the projection of this vector onto the xz plane. More...
 
CVector3Negate ()
 Negates this vector. More...
 
Real operator[] (UInt32 un_index) const
 Returns a Cartesian coordinate of this vector. More...
 
Realoperator[] (UInt32 un_index)
 Returns a Cartesian coordinate of this vector. More...
 
bool operator== (const CVector3 &c_vector3) const
 Returns true if this vector and the passed one are equal. More...
 
bool operator!= (const CVector3 &c_vector3) const
 Returns true if this vector and the passed one are not equal. More...
 
bool operator< (const CVector3 &c_vector3) const
 Returns true if this vector is smaller than the passed one. More...
 
bool operator<= (const CVector3 &c_vector3) const
 Returns true if this vector is smaller than or equal to the passed one. More...
 
bool operator> (const CVector3 &c_vector3) const
 Returns true if this vector is greater than the passed one. More...
 
bool operator>= (const CVector3 &c_vector3) const
 Returns true if this vector is greater than or equal to the passed one. More...
 
CVector3 operator- () const
 Returns a negated copy of this vector. More...
 
CVector3operator+= (const CVector3 &c_vector3)
 Sums the passed vector to this vector. More...
 
CVector3operator-= (const CVector3 &c_vector3)
 Subtracts the passed vector from this vector. More...
 
CVector3operator*= (Real f_value)
 Multiplies this vector by the given value. More...
 
CVector3operator/= (Real f_value)
 Divides this vector by the given value. More...
 
CVector3 operator+ (const CVector3 &c_vector3) const
 Returns a new vector containing the sum between this vector and the passed one. More...
 
CVector3 operator- (const CVector3 &c_vector3) const
 Returns a new vector containing the subtraction between this vector and the passed one. More...
 
CVector3 operator* (Real f_value) const
 Returns a new vector containing the multiplication between this vector and the passed value. More...
 
CVector3 operator/ (const Real f_value) const
 Returns a new vector containing the division between this vector and the passed value. More...
 
 operator CMatrix< 1, 3 > () const
 Implict conversion to a row matrix. More...
 
 operator CMatrix< 3, 1 > () const
 Implict conversion to a column matrix. More...
 

Static Public Attributes

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

Detailed Description

A 3D vector class.

Definition at line 31 of file vector3.h.

Constructor & Destructor Documentation

◆ CVector3() [1/4]

argos::CVector3::CVector3 ( )
inline

Class constructor.

It initializes the vector to (0,0,0).

See also
ZERO

Definition at line 54 of file vector3.h.

◆ CVector3() [2/4]

argos::CVector3::CVector3 ( Real  f_x,
Real  f_y,
Real  f_z 
)
inline

Class constructor.

It initializes the vector from Cartesian coordinates.

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

Definition at line 68 of file vector3.h.

◆ CVector3() [3/4]

argos::CVector3::CVector3 ( const std::array< Real, 3 > &  arr_coordinates)
inline

Class constructor.

It initializes the vector from Cartesian coordinates.

Parameters
arr_coordinatesThe coordinates.
See also
Set()

Definition at line 82 of file vector3.h.

◆ CVector3() [4/4]

argos::CVector3::CVector3 ( Real  f_length,
const CRadians c_inclination,
const CRadians c_azimuth 
)
inline

Class constructor.

It initializes the vector from spherical coordinates.

Parameters
f_lengthThe length of the vector.
c_inclinationThe angle between the z axis and the vector (range [-pi,pi])
c_azimuthThe angle on the xy plane (range [0,2pi])
See also
FromSphericalCoords()
ToSphericalCoords()

Definition at line 95 of file vector3.h.

Member Function Documentation

◆ CrossProduct()

CVector3& argos::CVector3::CrossProduct ( const CVector3 c_vector3)
inline

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

This method modifies this vector.

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

Definition at line 382 of file vector3.h.

◆ DotProduct()

Real argos::CVector3::DotProduct ( const CVector3 c_vector3) 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 369 of file vector3.h.

◆ FromSphericalCoords()

CVector3& argos::CVector3::FromSphericalCoords ( Real  f_length,
const CRadians c_inclination,
const CRadians c_azimuth 
)
inline

Sets the vector contents from spherical coordinates.

Parameters
f_lengthThe length of the vector.
c_inclinationThe angle between the z axis and the vector (range [-pi,pi])
c_azimuthThe angle on the xy plane (range [0,2pi])
See also
ToSphericalCoords()

Definition at line 180 of file vector3.h.

◆ GetAngleWith()

CRadians argos::CVector3::GetAngleWith ( const CVector3 c_other)
inline

Returns the angle between this vector and the passed vector.

Parameters
c_otherThe other vector.
Returns
The angle between this vector and the passed vector.

Definition at line 335 of file vector3.h.

◆ GetX()

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

Returns the x coordinate of this vector.

Returns
The x coordinate of this vector.

Definition at line 105 of file vector3.h.

◆ GetXAngle()

CRadians argos::CVector3::GetXAngle ( ) const
inline

Returns the angle between this vector and the x axis.

Returns
The angle between this vector and the x axis.

Definition at line 344 of file vector3.h.

◆ GetY()

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

Returns the y coordinate of this vector.

Returns
The y coordinate of this vector.

Definition at line 121 of file vector3.h.

◆ GetYAngle()

CRadians argos::CVector3::GetYAngle ( ) const
inline

Returns the angle between this vector and the y axis.

Returns
The angle between this vector and the y axis.

Definition at line 352 of file vector3.h.

◆ GetZ()

Real argos::CVector3::GetZ ( ) const
inline

Returns the z coordinate of this vector.

Returns
The z coordinate of this vector.

Definition at line 137 of file vector3.h.

◆ GetZAngle()

CRadians argos::CVector3::GetZAngle ( ) const
inline

Returns the angle between this vector and the z axis.

Returns
The angle between this vector and the z axis.

Definition at line 360 of file vector3.h.

◆ Length()

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

Returns the length of this vector.

Returns
The length of this vector.

Definition at line 227 of file vector3.h.

◆ Negate()

CVector3& argos::CVector3::Negate ( )
inline

Negates this vector.

After this method is called, this vector contains (-x,-y,-z).

Returns
A reference to this vector.

Definition at line 428 of file vector3.h.

◆ Normalize()

CVector3& argos::CVector3::Normalize ( )
inline

Normalizes this vector.

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

Returns
A reference to this vector.

Definition at line 237 of file vector3.h.

◆ operator CMatrix< 1, 3 >()

argos::CVector3::operator CMatrix< 1, 3 > ( ) const
inline

Implict conversion to a row matrix.

Definition at line 634 of file vector3.h.

◆ operator CMatrix< 3, 1 >()

argos::CVector3::operator CMatrix< 3, 1 > ( ) const
inline

Implict conversion to a column matrix.

Definition at line 645 of file vector3.h.

◆ operator!=()

bool argos::CVector3::operator!= ( const CVector3 c_vector3) const
inline

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

This method checks all the coordinates for equality.

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

Definition at line 483 of file vector3.h.

◆ operator*()

CVector3 argos::CVector3::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 614 of file vector3.h.

◆ operator*=()

CVector3& argos::CVector3::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 568 of file vector3.h.

◆ operator+()

CVector3 argos::CVector3::operator+ ( const CVector3 c_vector3) const
inline

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

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

Definition at line 592 of file vector3.h.

◆ operator+=()

CVector3& argos::CVector3::operator+= ( const CVector3 c_vector3)
inline

Sums the passed vector to this vector.

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

Definition at line 544 of file vector3.h.

◆ operator-() [1/2]

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

Returns a negated copy of this vector.

Returns
A negated copy of this vector.

Definition at line 535 of file vector3.h.

◆ operator-() [2/2]

CVector3 argos::CVector3::operator- ( const CVector3 c_vector3) const
inline

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

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

Definition at line 603 of file vector3.h.

◆ operator-=()

CVector3& argos::CVector3::operator-= ( const CVector3 c_vector3)
inline

Subtracts the passed vector from this vector.

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

Definition at line 556 of file vector3.h.

◆ operator/()

CVector3 argos::CVector3::operator/ ( const 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 625 of file vector3.h.

◆ operator/=()

CVector3& argos::CVector3::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 580 of file vector3.h.

◆ operator<()

bool argos::CVector3::operator< ( const CVector3 c_vector3) const
inline

Returns true if this vector is smaller than the passed one.

This method checks all the coordinates, and returns true only if the condition is true for all of them.

Parameters
c_vector3The other vector.
Returns
true if this vector is smaller than the passed one.

Definition at line 494 of file vector3.h.

◆ operator<=()

bool argos::CVector3::operator<= ( const CVector3 c_vector3) const
inline

Returns true if this vector is smaller than or equal to the passed one.

This method checks all the coordinates, and returns true only if the condition is true for all of them.

Parameters
c_vector3The other vector.
Returns
true if this vector is smaller than or equal to the passed one.

Definition at line 505 of file vector3.h.

◆ operator==()

bool argos::CVector3::operator== ( const CVector3 c_vector3) const
inline

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

This method checks all the coordinates for equality.

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

Definition at line 473 of file vector3.h.

◆ operator>()

bool argos::CVector3::operator> ( const CVector3 c_vector3) const
inline

Returns true if this vector is greater than the passed one.

This method checks all the coordinates, and returns true only if the condition is true for all of them.

Parameters
c_vector3The other vector.
Returns
true if this vector is greater than the passed one.

Definition at line 516 of file vector3.h.

◆ operator>=()

bool argos::CVector3::operator>= ( const CVector3 c_vector3) const
inline

Returns true if this vector is greater than or equal to the passed one.

This method checks all the coordinates, and returns true only if the condition is true for all of them.

Parameters
c_vector3The other vector.
Returns
true if this vector is greater than or equal to the passed one.

Definition at line 527 of file vector3.h.

◆ operator[]() [1/2]

Real& argos::CVector3::operator[] ( UInt32  un_index)
inline

Returns a Cartesian coordinate of this vector.

This method returns the value by reference.

Parameters
un_indexThe desired coordinate, with 0 mapping to x, 1 mapping to y, and 2 mapping to z.
Returns
A Cartesian coordinate of this vector.
Exceptions
CARGoSExceptionif the given index is out of bounds.

Definition at line 458 of file vector3.h.

◆ operator[]() [2/2]

Real argos::CVector3::operator[] ( UInt32  un_index) const
inline

Returns a Cartesian coordinate of this vector.

This method returns the value by copy.

Parameters
un_indexThe desired coordinate, with 0 mapping to x, 1 mapping to y, and 2 mapping to z.
Returns
A Cartesian coordinate of this vector.
Exceptions
CARGoSExceptionif the given index is out of bounds.

Definition at line 442 of file vector3.h.

◆ ProjectOntoXY()

CVector2& argos::CVector3::ProjectOntoXY ( CVector2 c_proj) const
inline

Calculates the projection of this vector onto the xy plane.

Parameters
c_projA 2d vector to use as buffer.
Returns
A reference to the passed 2d vector buffer.

Definition at line 398 of file vector3.h.

◆ ProjectOntoXZ()

CVector2& argos::CVector3::ProjectOntoXZ ( CVector2 c_proj) const
inline

Calculates the projection of this vector onto the xz plane.

Parameters
c_projA 2d vector to use as buffer.
Returns
A reference to the passed 2d vector buffer.

Definition at line 418 of file vector3.h.

◆ ProjectOntoYZ()

CVector2& argos::CVector3::ProjectOntoYZ ( CVector2 c_proj) const
inline

Calculates the projection of this vector onto the yz plane.

Parameters
c_projA 2d vector to use as buffer.
Returns
A reference to the passed 2d vector buffer.

Definition at line 408 of file vector3.h.

◆ Rotate()

CVector3 & argos::CVector3::Rotate ( const CQuaternion c_quaternion)

Rotates this vector by the given quaternion.

Parameters
c_quaternionThe quaternion to use.
Returns
A reference to this vector.
See also
CQuaternion

Definition at line 23 of file vector3.cpp.

◆ RotateX()

CVector3& argos::CVector3::RotateX ( const CRadians c_angle)
inline

Rotates this vector wrt the x axis.

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

Definition at line 247 of file vector3.h.

◆ RotateY()

CVector3& argos::CVector3::RotateY ( const CRadians c_angle)
inline

Rotates this vector wrt the y axis.

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

Definition at line 267 of file vector3.h.

◆ RotateZ() [1/2]

CVector3& argos::CVector3::RotateZ ( const CRadians c_angle)
inline

Rotates this vector wrt the z axis.

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

Definition at line 287 of file vector3.h.

◆ RotateZ() [2/2]

CVector3& argos::CVector3::RotateZ ( const CVector2 c_vector)
inline

Rotates this vector wrt the z axis.

This method rotates the vector wrt to the z axis using a 2d vector that is expected to contain: (cos(angle), sin(angle)). This method is mostly useful when you must rotate a lot of vectors by the same angle. You calculate the angle's cosine and sine, store it, and using multiple times. For speed reasons, no checks are performed - be sure you feed this method the right values.

Parameters
c_vectorThe precalculated cosine and sine of the rotation angle.
Returns
A reference to this vector.
See also
RotateZ(const CRadians&)

Definition at line 314 of file vector3.h.

◆ Set() [1/2]

void argos::CVector3::Set ( const Real  f_x,
const Real  f_y,
const Real  f_z 
)
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.
f_zThe new z coordinate of this vector.

Definition at line 155 of file vector3.h.

◆ Set() [2/2]

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

Sets the vector contents from Cartesian coordinates.

Parameters
arr_coordinatesThe new coordinates.

Definition at line 167 of file vector3.h.

◆ SetX()

void argos::CVector3::SetX ( const Real  f_x)
inline

Sets the x coordinate of this vector.

Parameters
f_xThe new x coordinate of this vector.

Definition at line 113 of file vector3.h.

◆ SetY()

void argos::CVector3::SetY ( const Real  f_y)
inline

Sets the y coordinate of this vector.

Parameters
f_yThe new y coordinate of this vector.

Definition at line 129 of file vector3.h.

◆ SetZ()

void argos::CVector3::SetZ ( const Real  f_z)
inline

Sets the z coordinate of this vector.

Parameters
f_zThe new z coordinate of this vector.

Definition at line 145 of file vector3.h.

◆ SquareLength()

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

Returns the square length of this vector.

Returns
The square length of this vector.

Definition at line 219 of file vector3.h.

◆ ToSphericalCoords()

void argos::CVector3::ToSphericalCoords ( Real f_radius,
CRadians c_inclination,
CRadians c_azimuth 
) const
inline

Returns the vector contents as spherical coordinates.

Parameters
f_lengthA buffer for the length of the vector.
c_inclinationA buffer for the angle between the z axis and the vector (range [-pi,pi])
c_azimuthA buffer for the angle on the xy plane (range [0,2pi])
See also
FromSphericalCoords()

Definition at line 207 of file vector3.h.

Member Data Documentation

◆ X

const CVector3 argos::CVector3::X
static

The x axis.

Definition at line 36 of file vector3.h.

◆ Y

const CVector3 argos::CVector3::Y
static

The y axis.

Definition at line 39 of file vector3.h.

◆ Z

const CVector3 argos::CVector3::Z
static

The z axis.

Definition at line 42 of file vector3.h.

◆ ZERO

const CVector3 argos::CVector3::ZERO
static

The zero vector (0,0,0)

Definition at line 45 of file vector3.h.