I have a rotation matrix rot (Eigen::Matrix3d) and a translation vector transl (Eigen::Vector3d) and I want them both together in a 4x4 transformation
You didn't post the compilation errors, nor what are rot and transl. Below is a working
sample showing, how you can create a 4x4 transformation matrix.
#include
Eigen::Affine3d create_rotation_matrix(double ax, double ay, double az) {
Eigen::Affine3d rx =
Eigen::Affine3d(Eigen::AngleAxisd(ax, Eigen::Vector3d(1, 0, 0)));
Eigen::Affine3d ry =
Eigen::Affine3d(Eigen::AngleAxisd(ay, Eigen::Vector3d(0, 1, 0)));
Eigen::Affine3d rz =
Eigen::Affine3d(Eigen::AngleAxisd(az, Eigen::Vector3d(0, 0, 1)));
return rz * ry * rx;
}
int main() {
Eigen::Affine3d r = create_rotation_matrix(1.0, 1.0, 1.0);
Eigen::Affine3d t(Eigen::Translation3d(Eigen::Vector3d(1,1,2)));
Eigen::Matrix4d m = (t * r).matrix(); // Option 1
Eigen::Matrix4d m = t.matrix(); // Option 2
m *= r.matrix();
return 0;
}