23 #ifndef QGLVIEWER_QUATERNION_H 24 #define QGLVIEWER_QUATERNION_H 73 { q[0]=q[1]=q[2]=0.0; q[3]=1.0; }
78 setAxisAngle(axis, angle);
89 { q[0]=q0; q[1]=q1; q[2]=q2; q[3]=q3; }
93 {
for (
int i=0; i<4; ++i) q[i] = Q.
q[i]; }
98 for (
int i=0; i<4; ++i)
108 const double norm = axis.
norm();
112 q[0] = 0.0; q[1] = 0.0; q[2] = 0.0; q[3] = 1.0;
116 const double sin_half_angle = sin(angle / 2.0);
117 q[0] = sin_half_angle*axis[0]/norm;
118 q[1] = sin_half_angle*axis[1]/norm;
119 q[2] = sin_half_angle*axis[2]/norm;
120 q[3] = cos(angle / 2.0);
125 void setValue(
double q0,
double q1,
double q2,
double q3)
126 { q[0]=q0; q[1]=q1; q[2]=q2; q[3]=q3; }
129 void setFromRotationMatrix(
const float m[3][3]);
130 void setFromRotatedBase(
const Vec& X,
const Vec& Y,
const Vec& Z);
132 void setFromRotationMatrix(
const double m[3][3]);
133 void setFromRotatedBasis(
const Vec& X,
const Vec& Y,
const Vec& Z);
140 double angle()
const;
141 void getAxisAngle(
Vec& axis,
float& angle)
const;
167 a.
q[3]*b.
q[1] + b.
q[3]*a.
q[1] + a.
q[2]*b.
q[0] - a.
q[0]*b.
q[2],
168 a.
q[3]*b.
q[2] + b.
q[3]*a.
q[2] + a.
q[0]*b.
q[1] - a.
q[1]*b.
q[0],
169 a.
q[3]*b.
q[3] - b.
q[0]*a.
q[0] - a.
q[1]*b.
q[1] - a.
q[2]*b.
q[2]);
192 Vec rotate(
const Vec& v)
const;
193 Vec inverseRotate(
const Vec& v)
const;
210 void invert() { q[0] = -q[0]; q[1] = -q[1]; q[2] = -q[2]; }
220 void negate() { invert(); q[3] = -q[3]; }
229 const double norm = sqrt(q[0]*q[0] + q[1]*q[1] + q[2]*q[2] + q[3]*q[3]);
230 for (
int i=0; i<4; ++i)
241 const double norm = sqrt(q[0]*q[0] + q[1]*q[1] + q[2]*q[2] + q[3]*q[3]);
242 for (
int i=0; i<4; ++i)
251 const GLdouble* matrix()
const;
252 void getMatrix(GLdouble m[4][4])
const;
253 void getMatrix(GLdouble m[16])
const;
255 void getRotationMatrix(
float m[3][3])
const;
257 const GLdouble* inverseMatrix()
const;
258 void getInverseMatrix(GLdouble m[4][4])
const;
259 void getInverseMatrix(GLdouble m[16])
const;
261 void getInverseRotationMatrix(
float m[3][3])
const;
285 explicit Quaternion(
const QDomElement& element);
286 QDomElement domElement(
const QString& name, QDomDocument& document)
const;
287 void initFromDOMElement(
const QDomElement& element);
311 #endif // QGLVIEWER_QUATERNION_H Quaternion inverse() const
std::ostream & operator<<(std::ostream &o, const qglviewer::Quaternion &)
Quaternion(const Vec &axis, double angle)
Vec rotate(const Vec &v) const
static double dot(const Quaternion &a, const Quaternion &b)
Quaternion(double q0, double q1, double q2, double q3)
double & operator[](int i)
The Vec class represents 3D positions and 3D vectors.
double operator[](int i) const
Quaternion normalized() const
void setValue(double q0, double q1, double q2, double q3)
friend Vec operator*(const Quaternion &q, const Vec &v)
The Quaternion class represents 3D rotations and orientations.
void setAxisAngle(const Vec &axis, double angle)
Quaternion(const Quaternion &Q)
friend Quaternion operator*(const Quaternion &a, const Quaternion &b)
Quaternion & operator*=(const Quaternion &q)
Quaternion & operator=(const Quaternion &Q)