What is the simplest way to convert an affine transformation to an isometric transformation (i.e. consisting of only a rotation and translation) using the Eigen library?
Both transformations are 3D. The affine matrix has a general 3x3 matrix (i.e. rotation, scaling and shear) for the top left quadrant, whereas the isometry has a 3x3 rotation matrix for the same quadrant, therefore a projection is required.
Eigen::AffineCompact3f a;
Eigen::Isometry3f b(a);
gives the compile error:
error C2338: YOU_PERFORMED_AN_INVALID_TRANSFORMATION_CONVERSION
whilst
Eigen::AffineCompact3f a;
Eigen::Isometry3f b(a.rotation(), a.translation());
gives
(line 2) error C2661: 'Eigen::Transform<_Scalar,_Dim,_Mode>::Transform' : no overloaded function takes 2 arguments
and
Eigen::AffineCompact3f a;
Eigen::Isometry3f b;
b.translation() = a.translation();
b.rotation() = a.rotation();
gives
(line 4) error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const Eigen::Matrix<_Scalar,_Rows,_Cols>' (or there is no acceptable conversion)
Given the rotation() and translation() functions, the question can be rephrased as "How do I best set the rotation and translation components of an isometric transform?"
.rotation() extract the rotation part of the transformation. It involves a SVD, and thus it is read-only. On the left hand side, you have to use .linear():
Eigen::AffineCompact3f a;
Eigen::Isometry3f b;
b.translation() = a.translation();
b.linear() = a.rotation();
If you know that 'a' is an isometry and only want to cast it to an Isometry 3f, you can simply do:
b = a.matrix();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With