pose2.cpp
Go to the documentation of this file.
1 
7 #include <argos3/core/utility/math/pose2.h>
8 
9 namespace argos
10 {
11 
12  CPose2::CPose2(const CVector3& c_position, const CQuaternion& c_orientation) :
13  m_cPosition(c_position[0], c_position[1]) {
14  CRadians _angle; CVector3 _axis;
15  c_orientation.ToAngleAxis(_angle, _axis);
16  m_cOrientation = _axis[2]*_angle;
17  }
18 
19 
21  CPose2 cResult;
22  cResult.m_cOrientation = -1.0*m_cOrientation;
23  Real fSin, fCos;
24 #ifdef ARGOS_SINCOS
25  SinCos(cResult.m_cOrientation, fSin, fCos);
26 #else
27  fSin = Sin(cResult.m_cOrientation);
28  fCos = Cos(cResult.m_cOrientation);
29 #endif
30  cResult.m_cPosition.m_fX = -m_cPosition.m_fX*fCos + m_cPosition.m_fY*fSin;
31  cResult.m_cPosition.m_fY = -m_cPosition.m_fX*fSin - m_cPosition.m_fY*fCos;
32  return cResult;
33  }
34 
35 
36  CPose2 CPose2::operator*(const CPose2& c_pose) const {
37  CPose2 cResult(*this);
38  Real fSin, fCos;
39 #ifdef ARGOS_SINCOS
40  SinCos(cResult.m_cOrientation, fSin, fCos);
41 #else
42  fSin = Sin(cResult.m_cOrientation);
43  fCos = Cos(cResult.m_cOrientation);
44 #endif
45  cResult.m_cPosition.m_fX += c_pose.m_cPosition.m_fX*fCos - c_pose.m_cPosition.m_fY*fSin;
46  cResult.m_cPosition.m_fY += c_pose.m_cPosition.m_fX*fSin + c_pose.m_cPosition.m_fY*fCos;
47  cResult.m_cOrientation += c_pose.m_cOrientation;
48  return cResult;
49  }
50 
51 
52  CVector2 CPose2::operator*(const CVector2& c_vec) const {
53  CPose2 cResult(*this);
54  Real fSin, fCos;
55 #ifdef ARGOS_SINCOS
56  SinCos(cResult.m_cOrientation, fSin, fCos);
57 #else
58  fSin = Sin(cResult.m_cOrientation);
59  fCos = Cos(cResult.m_cOrientation);
60 #endif
61  cResult.m_cPosition.m_fX += c_vec.m_fX*fCos - c_vec.m_fY*fSin;
62  cResult.m_cPosition.m_fY += c_vec.m_fX*fSin + c_vec.m_fY*fCos;
63  return cResult.m_cPosition;
64  }
65 
66 
67  CPose2& CPose2::operator*=(const CPose2& c_pose) {
68  Real fSin, fCos;
69 #ifdef ARGOS_SINCOS
70  SinCos(m_cOrientation, fSin, fCos);
71 #else
72  fSin = Sin(cResult.m_cOrientation);
73  fCos = Cos(cResult.m_cOrientation);
74 #endif
75  m_cPosition.m_fX += c_pose.m_cPosition.m_fX*fCos - c_pose.m_cPosition.m_fY*fSin;
76  m_cPosition.m_fY += c_pose.m_cPosition.m_fX*fSin + c_pose.m_cPosition.m_fY*fCos;
77  m_cOrientation += c_pose.m_cOrientation;
78  return *this;
79  }
80 
81 } // namespace argos
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
Real Cos(const CRadians &c_radians)
Computes the cosine of the passed value in radians.
Definition: angles.h:595
void SinCos(const CRadians &c_radians, Real &f_sin, Real &f_cos)
Computes the sine and cosine of the passed value in radians.
Definition: angles.h:574
Real Sin(const CRadians &c_radians)
Computes the sine of the passed value in radians.
Definition: angles.h:586
It defines the basic type CRadians, used to store an angle value in radians.
Definition: angles.h:42
CPose2 Inverse() const
Computes the returns the inverse of the current pose.
Definition: pose2.cpp:20
CPose2 operator*(const CPose2 &c_pose) const
Multiplication operator overloading.
Definition: pose2.cpp:36
CPose2 & operator*=(const CPose2 &c_pose)
Multiplication operator overloading.
Definition: pose2.cpp:67
CPose2()
Default constructor.
Definition: pose2.h:23
void ToAngleAxis(CRadians &c_angle, CVector3 &c_vector) const
Definition: quaternion.h:143
A 2D vector class.
Definition: vector2.h:27
A 3D vector class.
Definition: vector3.h:31