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

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

Friends

CVector3 operator* (Real f_value, const CVector3 &c_vector3)
 Returns a new vector containing the multiplication between the passed value and the passed vector. More...
 
std::ostream & operator<< (std::ostream &c_os, const CVector3 &c_vector3)
 Serializes the contents of the passed vector onto a stream. More...
 
std::istream & operator>> (std::istream &c_is, CVector3 &c_vector3)
 Deserializes the contents of a stream and stores them into the passed vector. More...
 

Detailed Description

A 3D vector class.

Definition at line 29 of file vector3.h.

Constructor & Destructor Documentation

argos::CVector3::CVector3 ( )
inline

Class constructor.

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

See also
ZERO

Definition at line 52 of file vector3.h.

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 66 of file vector3.h.

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 83 of file vector3.h.

Member Function Documentation

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 361 of file vector3.h.

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 348 of file vector3.h.

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 158 of file vector3.h.

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 313 of file vector3.h.

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

Returns the x coordinate of this vector.

Returns
The x coordinate of this vector.

Definition at line 93 of file vector3.h.

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 323 of file vector3.h.

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

Returns the y coordinate of this vector.

Returns
The y coordinate of this vector.

Definition at line 109 of file vector3.h.

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 331 of file vector3.h.

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

Returns the z coordinate of this vector.

Returns
The z coordinate of this vector.

Definition at line 125 of file vector3.h.

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 339 of file vector3.h.

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

Returns the length of this vector.

Returns
The length of this vector.

Definition at line 205 of file vector3.h.

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 407 of file vector3.h.

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 215 of file vector3.h.

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 462 of file vector3.h.

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 593 of file vector3.h.

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 547 of file vector3.h.

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 571 of file vector3.h.

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 523 of file vector3.h.

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

Returns a negated copy of this vector.

Returns
A negated copy of this vector.

Definition at line 514 of file vector3.h.

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 582 of file vector3.h.

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 535 of file vector3.h.

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 604 of file vector3.h.

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 559 of file vector3.h.

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 473 of file vector3.h.

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 484 of file vector3.h.

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 452 of file vector3.h.

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 495 of file vector3.h.

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 506 of file vector3.h.

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 421 of file vector3.h.

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 437 of file vector3.h.

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 377 of file vector3.h.

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 397 of file vector3.h.

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 387 of file vector3.h.

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 25 of file vector3.cpp.

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 225 of file vector3.h.

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

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 265 of file vector3.h.

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 292 of file vector3.h.

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 143 of file vector3.h.

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 101 of file vector3.h.

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 117 of file vector3.h.

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 133 of file vector3.h.

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

Returns the square length of this vector.

Returns
The square length of this vector.

Definition at line 197 of file vector3.h.

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 185 of file vector3.h.

Friends And Related Function Documentation

CVector3 operator* ( Real  f_value,
const CVector3 c_vector3 
)
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 616 of file vector3.h.

std::ostream& operator<< ( std::ostream &  c_os,
const CVector3 c_vector3 
)
friend

Serializes the contents of the passed vector onto a stream.

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

Definition at line 627 of file vector3.h.

std::istream& operator>> ( std::istream &  c_is,
CVector3 c_vector3 
)
friend

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

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

Definition at line 641 of file vector3.h.

Member Data Documentation

const CVector3 argos::CVector3::X
static

The x axis.

Definition at line 34 of file vector3.h.

const CVector3 argos::CVector3::Y
static

The y axis.

Definition at line 37 of file vector3.h.

const CVector3 argos::CVector3::Z
static

The z axis.

Definition at line 40 of file vector3.h.

const CVector3 argos::CVector3::ZERO
static

The zero vector (0,0,0)

Definition at line 43 of file vector3.h.