11 class CRotationMatrix2;
14 #include <argos3/core/utility/math/general.h>
15 #include <argos3/core/utility/math/angles.h>
16 #include <argos3/core/utility/math/matrix/matrix.h>
17 #include <argos3/core/utility/string_utilities.h>
73 CVector2(
const std::array<Real, 2>& arr_coordinates) {
86 m_fX(
Cos(f_angle) * f_length),
87 m_fY(
Sin(f_angle) * f_length) {
136 inline void Set(
const std::array<Real, 2>& arr_coordinates) {
137 m_fX = arr_coordinates[0];
138 m_fY = arr_coordinates[1];
150 m_fX =
Cos(f_angle) * f_length;
151 m_fY =
Sin(f_angle) * f_length;
186 return ATan2(m_fY, m_fX);
197 SinCos(c_angle, fSin, fCos);
202 Real fX = m_fX * fCos - m_fY * fSin;
203 Real fY = m_fX * fSin + m_fY * fCos;
215 return m_fX * c_vector2.m_fX + m_fY * c_vector2.m_fY;
224 return m_fX * c_vector2.m_fY - m_fY * c_vector2.m_fX;
271 return (m_fX == c_vector2.m_fX && m_fY == c_vector2.m_fY);
281 return (m_fX != c_vector2.m_fX || m_fY != c_vector2.m_fY);
290 m_fX += c_vector2.m_fX;
291 m_fY += c_vector2.m_fY;
301 m_fX -= c_vector2.m_fX;
302 m_fY -= c_vector2.m_fY;
335 cResult += c_vector2;
346 cResult -= c_vector2;
400 return c_vector2 * f_value;
415 c_os << c_vector2.m_fX <<
","
429 ParseValues<Real> (c_is, 2, fValues,
',');
430 c_vector2.
Set(fValues[0], fValues[1]);
454 return (c_v1 - c_v2).SquareLength();
464 return (c_v1 - c_v2).Length();
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.
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.
T Abs(const T &t_v)
Returns the absolute value of the passed argument.
It defines the basic type CRadians, used to store an angle value in radians.
Real Length() const
Returns the length of this vector.
CVector2(const std::array< Real, 2 > &arr_coordinates)
Class constructor.
Real DotProduct(const CVector2 &c_vector2) const
Returns the dot product between this vector and the passed one.
Real GetY() const
Returns the y coordinate of this vector.
CVector2 operator-(const CVector2 &c_vector2) const
Returns a new vector containing the subtraction between this vector and the passed one.
bool operator==(const CVector2 &c_vector2) const
Returns true if this vector and the passed one are equal.
Real SquareLength() const
Returns the square length of this vector.
Real CrossProduct(const CVector2 &c_vector2) const
Returns the cross product between this vector and the passed one.
CVector2(Real f_length, const CRadians &f_angle)
Class constructor.
CVector2(Real f_x, Real f_y)
Class constructor.
friend std::istream & operator>>(std::istream &c_is, CVector2 &c_vector2)
Deserializes the contents of a stream and stores them into the passed vector.
void Set(const std::array< Real, 2 > &arr_coordinates)
Sets the vector contents from Cartesian coordinates.
CRadians Angle() const
Returns the angle of this vector.
CVector2 & Scale(Real f_scale_x, Real f_scale_y)
Scales the vector by the wanted values.
CVector2 operator/(Real f_value) const
Returns a new vector containing the division between this vector and the passed value.
bool operator!=(const CVector2 &c_vector2) const
Returns true if this vector and the passed one are not equal.
CVector2 operator-() const
CVector2 & Perpendicularize()
Transforms this vector into its ortogonal.
friend std::ostream & operator<<(std::ostream &c_os, const CVector2 &c_vector2)
Serializes the contents of the passed vector onto a stream.
static const CVector2 ZERO
The zero vector (0,0)
CVector2 & operator/=(Real f_value)
Divides this vector by the given value.
CVector2 & operator-=(const CVector2 &c_vector2)
Subtracts the passed vector from this vector.
CVector2 & Rotate(const CRadians &c_angle)
Rotates this vector by the wanted angle.
CVector2 & Absolute()
Applies Abs() to the coordinates of this vector.
void FromPolarCoordinates(Real f_length, const CRadians &f_angle)
Sets the vector contents from polar coordinates.
CVector2()
Class constructor.
CVector2 & Normalize()
Normalizes this vector.
void SetY(Real f_y)
Sets the y coordinate of this vector.
static const CVector2 X
The x axis.
friend CVector2 operator*(Real f_value, const CVector2 &c_vector2)
Returns a new vector containing the multiplication between the passed value and the passed vector.
CVector2 operator+(const CVector2 &c_vector2) const
Returns a new vector containing the sum between this vector and the passed one.
CVector2 operator*(Real f_value) const
Returns a new vector containing the multiplication between this vector and the passed value.
void Set(Real f_x, Real f_y)
Sets the vector contents from Cartesian coordinates.
CVector2 & operator+=(const CVector2 &c_vector2)
Sums the passed vector to this vector.
void SetX(Real f_x)
Sets the x coordinate of this vector.
Real GetX() const
Returns the x coordinate of this vector.
static const CVector2 Y
The y axis.
CVector2 & operator*=(Real f_value)
Multiplies this vector by the given value.