mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Add Scaling and Translation class as discussed on ML, still missing:
* handling Quaternion, AngleAxis and Rotation2D, 2 options here:
1- make all of them inheriting a common base class Rotation such that we can
have a single version of operator* for all the rotation type (they all get converted to a matrix)
2- write a version for all type (so 3 rotations types * 3 for Transform,Translation and Scaling)
* real documentation
This commit is contained in:
@@ -40,6 +40,12 @@ template<typename Scalar> void geometry(void)
|
||||
typedef Matrix<Scalar,4,1> Vector4;
|
||||
typedef Quaternion<Scalar> Quaternion;
|
||||
typedef AngleAxis<Scalar> AngleAxis;
|
||||
typedef Transform<Scalar,2> Transform2;
|
||||
typedef Transform<Scalar,3> Transform3;
|
||||
typedef Scaling<Scalar,2> Scaling2;
|
||||
typedef Scaling<Scalar,3> Scaling3;
|
||||
typedef Translation<Scalar,2> Translation2;
|
||||
typedef Translation<Scalar,3> Translation3;
|
||||
|
||||
Quaternion q1, q2;
|
||||
Vector3 v0 = test_random_matrix<Vector3>(),
|
||||
@@ -115,12 +121,8 @@ template<typename Scalar> void geometry(void)
|
||||
VERIFY_IS_APPROX(AngleAxis(m).toRotationMatrix(),
|
||||
Quaternion(m).toRotationMatrix());
|
||||
|
||||
|
||||
// Transform
|
||||
// TODO complete the tests !
|
||||
typedef Transform<Scalar,2> Transform2;
|
||||
typedef Transform<Scalar,3> Transform3;
|
||||
|
||||
a = 0;
|
||||
while (ei_abs(a)<0.1)
|
||||
a = ei_random<Scalar>(-0.4*M_PI, 0.4*M_PI);
|
||||
@@ -169,12 +171,60 @@ template<typename Scalar> void geometry(void)
|
||||
t21.linear() = Rotation2D<Scalar>(-a).toRotationMatrix();
|
||||
VERIFY( (t20.fromPositionOrientationScale(v20,a,v21)
|
||||
* (t21.prescale(v21.cwise().inverse()).translate(-v20))).isIdentity(test_precision<Scalar>()) );
|
||||
|
||||
// Transform - new API
|
||||
// 3D
|
||||
t0.setIdentity();
|
||||
t0.rotate(q1).scale(v0).translate(v0);
|
||||
// mat * scaling and mat * translation
|
||||
t1 = (Matrix3(q1) * Scaling3(v0)) * Translation3(v0);
|
||||
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
||||
// mat * transformation and scaling * translation
|
||||
t1 = Matrix3(q1) * (Scaling3(v0) * Translation3(v0));
|
||||
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
||||
|
||||
t0.setIdentity();
|
||||
t0.prerotate(q1).prescale(v0).pretranslate(v0);
|
||||
// translation * scaling and transformation * mat
|
||||
t1 = (Translation3(v0) * Scaling3(v0)) * Matrix3(q1);
|
||||
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
||||
// scaling * mat and translation * mat
|
||||
t1 = Translation3(v0) * (Scaling3(v0) * Matrix3(q1));
|
||||
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
||||
|
||||
t0.setIdentity();
|
||||
t0.scale(v0).translate(v0).rotate(q1);
|
||||
// translation * mat and scaling * transformation
|
||||
t1 = Scaling3(v0) * (Translation3(v0) * Matrix3(q1));
|
||||
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
||||
// transformation * scaling
|
||||
t0.scale(v0);
|
||||
t1 = t1 * Scaling3(v0);
|
||||
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
||||
// transformation * translation
|
||||
t0.translate(v0);
|
||||
t1 = t1 * Translation3(v0);
|
||||
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
||||
// translation * transformation
|
||||
t0.pretranslate(v0);
|
||||
t1 = Translation3(v0) * t1;
|
||||
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
||||
|
||||
// translation * vector
|
||||
t0.setIdentity();
|
||||
t0.translate(v0);
|
||||
VERIFY_IS_APPROX(t0 * v1, Translation3(v0) * v1);
|
||||
|
||||
// scaling * vector
|
||||
t0.setIdentity();
|
||||
t0.scale(v0);
|
||||
VERIFY_IS_APPROX(t0 * v1, Scaling3(v0) * v1);
|
||||
}
|
||||
|
||||
void test_geometry()
|
||||
{
|
||||
for(int i = 0; i < g_repeat; i++) {
|
||||
CALL_SUBTEST( geometry<float>() );
|
||||
CALL_SUBTEST( geometry<double>() );
|
||||
// CALL_SUBTEST( geometry<double>() );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user