Another way is to use the
Eigen::Transform.
Let's take an example, such as implementing this affine transform
![T(x_0, y_0, z_0)R_x(a)R_y(b)R_z(c)\mathbf{x}](https://latex.codecogs.com/gif.latex?%5Cinline&space;T(x_0,&space;y_0,&space;z_0)R_x(a)R_y(b)R_z(c)%5Cmathbf%7Bx%7D)
,
#include <Eigen/Dense>
#include <Eigen/Geometry>
using namespace Eigen;
Matrix4f create_affine_matrix(float a, float b, float c, Vector3f trans)
{
Transform<float, 3, Eigen::Affine> t;
t = Translation<float, 3>(trans);
t.rotate(AngleAxis<float>(a, Vector3f::UnitX()));
t.rotate(AngleAxis<float>(b, Vector3f::UnitY()));
t.rotate(AngleAxis<float>(c, Vector3f::UnitZ()));
return t.matrix();
}
您也可以按以下方式实现。
Matrix4f create_affine_matrix(float a, float b, float c, Vector3f trans)
{
Transform<float, 3, Eigen::Affine> t;
t = AngleAxis<float>(c, Vector3f::UnitZ());
t.prerotate(AngleAxis<float>(b, Vector3f::UnitY()));
t.prerotate(AngleAxis<float>(a, Vector3f::UnitX()));
t.pretranslate(trans);
return t.matrix();
}
第一种实现和第二种实现的区别就像“固定角度”和“欧拉角”的区别,您可以参考
this video。
m = m * t.matrix()
,也许问题在于缺少*=
运算符。这种方式可行吗? - pqnetEigen
,但旋转矩阵通常是一个3x3的矩阵,你可以直接放入你的4x4矩阵中(假设你没有任何缩放)。在一个4x4的变换矩阵中,元素_00、_01、_02、_10、_11、_12、_20、_21和_22构成了旋转部分(如果有缩放则包括时间尺度)。元素_30、_31和_32是平移向量元素。 - rashmatash