14 class CRotationMatrix3;
17 #include <argos3/core/utility/math/general.h>
18 #include <argos3/core/utility/math/angles.h>
19 #include <argos3/core/utility/math/vector2.h>
20 #include <argos3/core/utility/math/matrix/matrix.h>
21 #include <argos3/core/utility/string_utilities.h>
82 CVector3(
const std::array<Real, 3>& arr_coordinates) {
167 inline void Set(
const std::array<Real, 3>& arr_coordinates) {
168 m_fX = arr_coordinates[0];
169 m_fY = arr_coordinates[1];
170 m_fZ = arr_coordinates[2];
183 Real fInclinationSin, fInclinationCos;
184 Real fAzimuthSin, fAzimuthCos;
186 SinCos(c_inclination, fInclinationSin, fInclinationCos);
187 SinCos(c_azimuth, fAzimuthSin, fAzimuthCos);
189 fInclinationSin =
Sin(c_inclination);
190 fInclinationCos =
Cos(c_inclination);
191 fAzimuthSin =
Sin(c_azimuth);
192 fAzimuthCos =
Cos(c_azimuth);
194 m_fX = f_length * fInclinationSin * fAzimuthCos;
195 m_fY = f_length * fInclinationSin * fAzimuthSin;
196 m_fZ = f_length * fInclinationCos;
211 c_inclination =
ACos(m_fZ / f_radius);
212 c_azimuth =
ATan2(m_fY, m_fX);
250 SinCos(c_angle, fSin, fCos);
255 Real fNewY = m_fY * fCos - m_fZ * fSin;
256 Real fNewZ = m_fY * fSin + m_fZ * fCos;
270 SinCos(c_angle, fSin, fCos);
275 Real fNewX = m_fX * fCos + m_fZ * fSin;
276 Real fNewZ = m_fZ * fCos - m_fX * fSin;
290 SinCos(c_angle, fSin, fCos);
295 Real fNewX = m_fX * fCos - m_fY * fSin;
296 Real fNewY = m_fX * fSin + m_fY * fCos;
315 Real fNewX = m_fX * c_vector.
GetX() - m_fY * c_vector.
GetY();
316 Real fNewY = m_fX * c_vector.
GetY() + m_fY * c_vector.
GetX();
345 return ATan2(m_fZ, m_fY);
353 return ATan2(m_fX, m_fZ);
361 return ATan2(m_fY, m_fX);
371 m_fX * c_vector3.m_fX +
372 m_fY * c_vector3.m_fY +
373 m_fZ * c_vector3.m_fZ;
383 Real fNewX, fNewY, fNewZ;
384 fNewX = m_fY * c_vector3.m_fZ - m_fZ * c_vector3.m_fY;
385 fNewY = m_fZ * c_vector3.m_fX - m_fX * c_vector3.m_fZ;
386 fNewZ = m_fX * c_vector3.m_fY - m_fY * c_vector3.m_fX;
399 c_proj.
Set(m_fX,m_fY);
409 c_proj.
Set(m_fY,m_fZ);
419 c_proj.
Set(m_fX,m_fZ);
447 default:
THROW_ARGOSEXCEPTION(
"Real Vector3::operator[]: index " << un_index <<
" out of bounds");
463 default:
THROW_ARGOSEXCEPTION(
"Real Vector3::operator[]: index " << un_index <<
" out of bounds");
474 return m_fX == c_vector3.m_fX && m_fY == c_vector3.m_fY && m_fZ == c_vector3.m_fZ;
484 return !((*this) == c_vector3);
495 return m_fX < c_vector3.m_fX && m_fY < c_vector3.m_fY && m_fZ < c_vector3.m_fZ;
506 return m_fX <= c_vector3.m_fX && m_fY <= c_vector3.m_fY && m_fZ <= c_vector3.m_fZ;
517 return m_fX > c_vector3.m_fX && m_fY > c_vector3.m_fY && m_fZ > c_vector3.m_fZ;
528 return m_fX >= c_vector3.m_fX && m_fY >= c_vector3.m_fY && m_fZ >= c_vector3.m_fZ;
536 return CVector3(-m_fX, -m_fY, -m_fZ);
545 m_fX += c_vector3.m_fX;
546 m_fY += c_vector3.m_fY;
547 m_fZ += c_vector3.m_fZ;
557 m_fX -= c_vector3.m_fX;
558 m_fY -= c_vector3.m_fY;
559 m_fZ -= c_vector3.m_fZ;
594 cResult += c_vector3;
605 cResult -= c_vector3;
661 return c_vector3 * f_value;
672 c_os << c_vector3.m_fX <<
","
673 << c_vector3.m_fY <<
","
687 ParseValues<Real>(c_is, 3, fValues,
',');
688 c_vector3.
Set(fValues[0], fValues[1], fValues[2]);
718 return (c_v1 - c_v2).SquareLength();
728 return (c_v1 - c_v2).Length();
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
unsigned int UInt32
32-bit unsigned integer.
float Real
Collects all ARGoS code.
The namespace containing all the ARGoS related code.
T Square(const T &t_v)
Returns the square of the value of the passed argument.
CRadians ACos(Real f_value)
Computes the arccosine of the passed value.
Real SquareDistance(const CVector2 &c_v1, const CVector2 &c_v2)
Computes the square distance between the passed vectors.
Real Cos(const CRadians &c_radians)
Computes the cosine of the passed value in radians.
Real Distance(const CVector2 &c_v1, const CVector2 &c_v2)
Computes the distance between the passed vectors.
void SinCos(const CRadians &c_radians, Real &f_sin, Real &f_cos)
Computes the sine and cosine of the passed value in radians.
Real Sin(const CRadians &c_radians)
Computes the sine of the passed value in radians.
CRadians ATan2(const Real f_y, const Real f_x)
Computes the arctangent of the passed values.
It defines the basic type CRadians, used to store an angle value in radians.
Real GetY() const
Returns the y coordinate of this vector.
void Set(Real f_x, Real f_y)
Sets the vector contents from Cartesian coordinates.
Real GetX() const
Returns the x coordinate of this vector.
Real operator[](UInt32 un_index) const
Returns a Cartesian coordinate of this vector.
Real Length() const
Returns the length of this vector.
CVector3 & operator+=(const CVector3 &c_vector3)
Sums the passed vector to this vector.
static const CVector3 Y
The y axis.
CVector3 & CrossProduct(const CVector3 &c_vector3)
Calculates the cross product between this vector and the passed one.
void SetY(const Real f_y)
Sets the y coordinate of this vector.
CVector3 operator-(const CVector3 &c_vector3) const
Returns a new vector containing the subtraction between this vector and the passed one.
CVector3 & Rotate(const CQuaternion &c_quaternion)
Rotates this vector by the given quaternion.
CVector3 operator/(const Real f_value) const
Returns a new vector containing the division between this vector and the passed value.
Real SquareLength() const
Returns the square length of this vector.
Real GetX() const
Returns the x coordinate of this vector.
CVector3 operator*(Real f_value) const
Returns a new vector containing the multiplication between this vector and the passed value.
CRadians GetZAngle() const
Returns the angle between this vector and the z axis.
friend CVector3 operator*(Real f_value, const CVector3 &c_vector3)
Returns a new vector containing the multiplication between the passed value and the passed vector.
CVector3 & operator/=(Real f_value)
Divides this vector by the given value.
void SetX(const Real f_x)
Sets the x coordinate of this vector.
CVector3 & operator-=(const CVector3 &c_vector3)
Subtracts the passed vector from this vector.
CRadians GetYAngle() const
Returns the angle between this vector and the y axis.
bool operator!=(const CVector3 &c_vector3) const
Returns true if this vector and the passed one are not equal.
Real DotProduct(const CVector3 &c_vector3) const
Returns the dot product between this vector and the passed one.
CVector3 operator-() const
Returns a negated copy of this vector.
CVector3()
Class constructor.
CVector3 & RotateX(const CRadians &c_angle)
Rotates this vector wrt the x axis.
bool operator>=(const CVector3 &c_vector3) const
Returns true if this vector is greater than or equal to the passed one.
bool operator==(const CVector3 &c_vector3) const
Returns true if this vector and the passed one are equal.
CVector2 & ProjectOntoXZ(CVector2 &c_proj) const
Calculates the projection of this vector onto the xz plane.
bool operator<=(const CVector3 &c_vector3) const
Returns true if this vector is smaller than or equal to the passed one.
CVector3 & Normalize()
Normalizes this vector.
CVector3 & Negate()
Negates this vector.
void Set(const Real f_x, const Real f_y, const Real f_z)
Sets the vector contents from Cartesian coordinates.
CVector3 & FromSphericalCoords(Real f_length, const CRadians &c_inclination, const CRadians &c_azimuth)
Sets the vector contents from spherical coordinates.
void SetZ(const Real f_z)
Sets the z coordinate of this vector.
static const CVector3 X
The x axis.
CRadians GetXAngle() const
Returns the angle between this vector and the x axis.
Real GetY() const
Returns the y coordinate of this vector.
CVector3 & operator*=(Real f_value)
Multiplies this vector by the given value.
bool operator<(const CVector3 &c_vector3) const
Returns true if this vector is smaller than the passed one.
static const CVector3 Z
The z axis.
Real GetZ() const
Returns the z coordinate of this vector.
CVector3(Real f_length, const CRadians &c_inclination, const CRadians &c_azimuth)
Class constructor.
void Set(const std::array< Real, 3 > &arr_coordinates)
Sets the vector contents from Cartesian coordinates.
CVector3 & RotateZ(const CRadians &c_angle)
Rotates this vector wrt the z axis.
Real & operator[](UInt32 un_index)
Returns a Cartesian coordinate of this vector.
CVector2 & ProjectOntoXY(CVector2 &c_proj) const
Calculates the projection of this vector onto the xy plane.
void ToSphericalCoords(Real &f_radius, CRadians &c_inclination, CRadians &c_azimuth) const
Returns the vector contents as spherical coordinates.
CVector3 & RotateZ(const CVector2 &c_vector)
Rotates this vector wrt the z axis.
CVector3 operator+(const CVector3 &c_vector3) const
Returns a new vector containing the sum between this vector and the passed one.
static const CVector3 ZERO
The zero vector (0,0,0)
friend std::ostream & operator<<(std::ostream &c_os, const CVector3 &c_vector3)
Serializes the contents of the passed vector onto a stream.
bool operator>(const CVector3 &c_vector3) const
Returns true if this vector is greater than the passed one.
friend std::istream & operator>>(std::istream &c_is, CVector3 &c_vector3)
Deserializes the contents of a stream and stores them into the passed vector.
CVector2 & ProjectOntoYZ(CVector2 &c_proj) const
Calculates the projection of this vector onto the yz plane.
CVector3(Real f_x, Real f_y, Real f_z)
Class constructor.
CVector3 & RotateY(const CRadians &c_angle)
Rotates this vector wrt the y axis.
CVector3(const std::array< Real, 3 > &arr_coordinates)
Class constructor.
CRadians GetAngleWith(const CVector3 &c_other)
Returns the angle between this vector and the passed vector.