00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025 #ifndef QVEUCLIDEANMAPPING3_H
00026 #define QVEUCLIDEANMAPPING3_H
00027
00028 #include <QVMatrix>
00029 #include <QV3DPointF>
00030 #include <qvmath.h>
00031
00044 class QVEuclideanMapping3
00045 {
00046 private:
00047 QVQuaternion q;
00048 QV3DPointF t;
00049
00050 public:
00052 QVEuclideanMapping3(): q(), t() { }
00053
00055 QVEuclideanMapping3(const QVEuclideanMapping3 &other): q(other.q), t(other.t) { }
00056
00060 QVEuclideanMapping3(const QVQuaternion &q, const QV3DPointF &t): q(q), t(t) { }
00061
00071 QVEuclideanMapping3(const double quatx, const double quaty, const double quatz, const double quatw,
00072 const double tx, const double ty, const double tz):
00073 q(quatx, quaty, quatz, quatw), t(tx, ty, tz)
00074 { }
00075
00081 QVEuclideanMapping3(const QVVector &v): q(v[0], v[1], v[2], v[3]), t(v[4], v[5], v[6])
00082 { }
00083
00088 QVEuclideanMapping3(const QVMatrix &Rt);
00089
00093 QV3DPointF apply(const QV3DPointF &X) const
00094 {
00095 return q.rotate(X) + t;
00096 }
00097
00103 operator QVVector() const
00104 {
00105 QVVector result(7);
00106
00107 result[0] = q[0];
00108 result[1] = q[1];
00109 result[2] = q[2];
00110 result[3] = q[3];
00111
00112 result[4] = t[0];
00113 result[5] = t[1];
00114 result[6] = t[2];
00115
00116 return result;
00117 }
00118
00121 bool operator ==(const QVEuclideanMapping3 &other) const
00122 {
00123 return (q == other.q and t == other.t);
00124 }
00125
00128 bool operator !=(const QVEuclideanMapping3 &other) const
00129 {
00130 return (q != other.q or t != other.t);
00131 }
00132
00137 QVMatrix toRotationTranslationMatrix() const
00138 {
00139 QVMatrix Rt = QVMatrix::identity(4);
00140 const QVMatrix R = q.toRotationMatrix();
00141
00142 for (int i = 0; i < 3; i++)
00143 {
00144 for (int j = 0; j < 3; j++)
00145 Rt(i,j) = R(i,j);
00146 Rt(i,3) = t[i];
00147 }
00148
00149 return Rt;
00150 }
00151
00153 QVQuaternion getRotation() const { return q; }
00154
00156 QV3DPointF getTranslation() const { return t; }
00157
00159 void setRotation(const QVQuaternion &other) { q = other; }
00160
00162 void setTranslation(const QV3DPointF &other) { t = other; }
00163
00166 QVEuclideanMapping3 inverse() const
00167 {
00168 const QVQuaternion qInv = q.inverse();
00169 return QVEuclideanMapping3(qInv, QV3DPointF(qInv.rotate(t)) * (-1));
00170 }
00171
00174 QVEuclideanMapping3 compose(const QVEuclideanMapping3 &other) const
00175 {
00176 return QVEuclideanMapping3(q * other.q, q.rotate(other.t) + t);
00177 }
00178
00181 QVEuclideanMapping3 operator*(const QVEuclideanMapping3 &other) const { return compose(other); };
00182
00191 QVEuclideanMapping3 operator/(const QVEuclideanMapping3 &other) const { return compose(other.inverse()); };
00192 };
00193 #endif