Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert an Eigen affine transformation to an Eigen isometry transformation

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?"

like image 885
user664303 Avatar asked Dec 19 '12 16:12

user664303


1 Answers

.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();
like image 140
ggael Avatar answered Oct 19 '22 09:10

ggael