简体   繁体   中英

Convert an Eigen affine transformation to an Eigen isometry transformation

What is the simplest way to convert an affine transformation to an isometric transformation (ie consisting of only a rotation and translation) using the Eigen library?

Both transformations are 3D. The affine matrix has a general 3x3 matrix (ie 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM