00001
00028 #include "threeD_mouse/geometry.h"
00029 #include <math.h>
00030
00031 namespace geometry
00032 {
00033
00034
00035
00036 const double Quaternion::pi_over_360 = 0.0087266462599716477;
00037
00038
00039 Quaternion:: Quaternion()
00040 : x(0.0), y(0.0), z(0.0), w(0.0)
00041 {}
00042
00043 Quaternion::Quaternion(double nx, double ny, double nz, double nw)
00044 : x(nx), y(ny), z(nz), w(nw)
00045 {}
00046
00047 Quaternion:: Quaternion(Quaternion& q)
00048 : x(q.x), y(q.y), z(q.z), w(q.w)
00049 {}
00050
00051 Quaternion::Quaternion(const Quaternion& q)
00052 : x(q.x), y(q.y), z(q.z), w(q.w)
00053 {}
00054
00055 Quaternion:: ~Quaternion()
00056 {}
00057
00058 Quaternion Quaternion::euler_to_quaternion(float pitch, float yaw, float roll)
00059 {
00060
00061
00062
00063
00064 Quaternion quater;
00065
00066 double p = pitch * pi_over_360;
00067 double y = yaw * pi_over_360;
00068 double r = roll * pi_over_360;
00069
00070 double sinp = sin(p);
00071 double siny = sin(y);
00072 double sinr = sin(r);
00073 double cosp = cos(p);
00074 double cosy = cos(y);
00075 double cosr = cos(r);
00076
00077 quater.x = sinr * cosp * cosy - cosr * sinp * siny;
00078 quater.y = cosr * sinp * cosy + sinr * cosp * siny;
00079 quater.z = cosr * cosp * siny - sinr * sinp * cosy;
00080 quater.w = cosr * cosp * cosy + sinr * sinp * siny;
00081
00082 normalise(quater);
00083
00084 return Quaternion(quater);
00085 }
00086
00087 void Quaternion::normalise(Quaternion quater)
00088 {
00089
00090 double mag2 = quater.w * quater.w +
00091 quater.x * quater.x + quater.y * quater.y +
00092 quater.z * quater.z;
00093
00094 if ( mag2!=0.0 && (fabs(mag2 - 1.0f) > 0.01)) {
00095 double mag = sqrt(mag2);
00096 quater.w /= mag;
00097 quater.x /= mag;
00098 quater.y /= mag;
00099 quater.z /= mag;
00100 }
00101 }
00102
00103
00104
00105
00106
00107 Translation::Translation()
00108 : x(0.0), y(0.0), z(0.0)
00109 {}
00110
00111 Translation::Translation(double nx, double ny, double nz)
00112 : x(nx), y(ny), z(nz)
00113 {}
00114
00115 Translation::Translation(Translation& t)
00116 : x(t.x), y(t.y), z(t.z)
00117 {}
00118
00119 Translation::Translation(const Translation& t)
00120 : x(t.x), y(t.y), z(t.z)
00121 {}
00122
00123
00124
00125
00126
00127 Pose::Pose()
00128 : translation(Translation()), quaternion(Quaternion())
00129 {}
00130
00131 Pose::~Pose()
00132 {}
00133
00134 };