33 #include <Base/Common/CompareFloatingPoint.hh>
34 #include <Base/Geometry/Quaternion.hh>
35 #include <Base/Math/Random.hh>
44 Q[3] = cos(0.5*angle);
45 Q[0] = Q[1] = Q[2] = sin(0.5*angle);
53 for (
int j = 0; j < 3; j++) Q[j] *= axis[j];
61 return GenerateRandomQuaternion(randomizer, angle);
76 const double epsilon = 1e-12,
77 const bool verbose =
false)
86 double diffL = (Lp-qp).NormL2();
87 double diffR = (Rq-qp).NormL2();
88 double maxDiffLR = (diffL > diffR ? diffL : diffR);
90 cout <<
"q = " << q <<
", p = " << p <<
", q*p = " << qp << endl
91 <<
"L(q)*p = " << Lp <<
", |L(q)*p - q*p| = " << diffL << endl
92 <<
"R(p)*q = " << Rq <<
", |R(p)*q - q*p| = " << diffR << endl;
94 BIASASSERT(
Equal(diffL, 0.0, epsilon));
95 BIASASSERT(
Equal(diffR, 0.0, epsilon));
111 cout <<
"|<quat(M(q)*M(p)), q*p>| = " << diffQuatR+1.0 << endl << flush;
113 BIASASSERT(
Equal(diffQuatR, 0.0, epsilon));
115 return (fabs(diffQuatR) > maxDiffLR ? fabs(diffQuatR) : maxDiffLR);
119 const double epsilon = 1e-12,
120 const bool verbose =
false)
129 double diffV = (Rv-qvq).NormL2();
131 cout <<
"v = " << v <<
", q*v*q' = " << qvq
132 <<
", |R*v - q*v*q'| = " << diffV << endl << flush;
134 BIASASSERT(
Equal(diffV, 0.0, epsilon));
140 const int num = 10000;
141 const double epsilon = 1e-12;
142 const bool verbose =
false;
145 cout <<
"\ntest quaternions for " << num <<
" random rotations"
146 <<
"\n---------------------------------------------------\n";
148 double error, maxError = 0.0;
151 for (
int n = 0; n < num; n++)
153 q = GenerateRandomQuaternion(randomizer);
154 p = GenerateRandomQuaternion(randomizer);
155 v = GenerateRandomVector(randomizer);
156 error = TestQuatQuatMult(q, p, epsilon, verbose);
157 if (error > maxError) maxError = error;
158 error = TestQuatVecMult(q, v, epsilon, verbose);
159 if (error > maxError) maxError = error;
160 error = TestQuatVecMult(p, v, epsilon, verbose);
161 if (error > maxError) maxError = error;
163 cout <<
"max. error = " << setprecision(30) << maxError << endl << endl;
void Set(const T *pv)
copy the array of vectorsize beginning at *T to this->data_
int SetFromQuaternion(const Quaternion< ROTATION_MATRIX_TYPE > &q)
Set rotation matrix from a quaternion.
double GetUniformDistributed(const double min, const double max)
on succesive calls return uniform distributed random variable between min and max ...
Matrix4x4< QUAT_TYPE > GetQuaternionMultMatrixLeft() const
Returns matrix which expresses (left) quaternion multiplication.
int MultVec(const Vector3< QUAT_TYPE > &vec, Vector3< QUAT_TYPE > &res) const
rotates the given Vector qith the quaternion ( q v q* ) the resulting vector is given in res ...
int GetQuaternion(Quaternion< ROTATION_MATRIX_TYPE > &quat) const
Calculates quaternion representation for this rotation matrix.
void Normalize()
Scales quaternion to unit length, i.e.
void ScalarProduct(const Vector4< T > &argvec, T &result) const
scalar product (=inner product) of two vectors, storing the result in result
bool Equal(const T left, const T right, const T eps)
comparison function for floating point values See http://www.boost.org/libs/test/doc/components/test_...
Implements a 3D rotation matrix.
Vector3< T > & Normalize()
normalize this vector to length 1
class for producing random numbers from different distributions
double NormL2() const
the L2 norm sqrt(a^2 + b^2 + c^2)