Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <cmath>
00011
00012 #include "Pose.h"
00013 #include "Transformation2D.h"
00014
00015 using namespace std;
00016
00017
00018 #define THIS Pose
00019
00020 THIS::THIS(float x, float y, float theta) : Point2D(x, y) {
00021 m_Theta = theta;
00022 }
00023
00024 THIS::THIS() {
00025 m_Theta = 0.0;
00026 }
00027
00028 THIS::~THIS() {
00029 }
00030
00031 float THIS::theta() const {
00032 return m_Theta;
00033 }
00034
00035 void THIS::setTheta(float theta) {
00036 m_Theta = theta;
00037 }
00038
00039 Pose THIS::operator+ ( const Transformation2D& transformation ) const {
00040 float x, y, theta;
00041 x = m_X + transformation.x();
00042 y = m_Y + transformation.y();
00043 theta = m_Theta + transformation.theta();
00044 while (theta >= M_PI) theta -= 2*M_PI;
00045 while (theta < -M_PI) theta += 2*M_PI;
00046
00047 return Pose(x, y, theta);
00048 }
00049
00050 Pose THIS::operator- ( const Transformation2D& transformation ) const {
00051 float x, y, theta;
00052 x = m_X - transformation.x();
00053 y = m_Y - transformation.y();
00054 theta = m_Theta - transformation.theta();
00055 while (theta >= M_PI) theta -= 2*M_PI;
00056 while (theta < -M_PI) theta += 2*M_PI;
00057
00058 return Pose(x, y, theta);
00059 }
00060
00061 Transformation2D THIS::operator- ( const Pose& pose ) const {
00062 float x, y, theta;
00063 x = m_X - pose.x();
00064 y = m_Y - pose.y();
00065
00066 float s1, s2;
00067 if (m_Theta > pose.theta()) {
00068 s1 = -( 2 * M_PI - m_Theta + pose.theta());
00069 s2 = m_Theta - pose.theta();
00070 } else {
00071 s1 = 2 * M_PI - pose.theta() + m_Theta;
00072 s2 = -(pose.theta() - m_Theta);
00073 }
00074 if (fabs(s1) > fabs(s2)) {
00075 theta = s2;
00076 } else {
00077 theta = s1;
00078 }
00079 while (theta >= M_PI) theta -= 2*M_PI;
00080 while (theta < -M_PI) theta += 2*M_PI;
00081
00082 return Transformation2D(x, y, theta);
00083 }
00084
00085 Pose THIS::interpolate(const Pose& referencePose, float t) const {
00086
00087 float newX = m_X + t * (referencePose.x() - m_X);
00088 float newY = m_Y + t * (referencePose.y() - m_Y);
00089
00090
00091 float x1 = cosf(m_Theta);
00092 float y1 = sinf(m_Theta);
00093 float x2 = cosf(referencePose.theta());
00094 float y2 = sinf(referencePose.theta());
00095 float newTheta = atan2 (y1*(1-t)+y2*t, x1*(1-t)+x2*t);
00096
00097 return Pose(newX, newY, newTheta);
00098 }
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117