如何在Eigen中平移矩阵(4x4)
How translation a matrix(4x4) in Eigen?
如何在Eigen中平移矩阵(4x4)?
//identity matrix 4x4
/*type=*/Eigen::Matrix<float, 4, 4> /*name=*/result = Eigen::Matrix<float, 4, 4>::Identity();
//translation vector
// 3.0f
// 4.0f
// 5.0f
Translation<float, 3> trans(3.0f, 4.0f, 5.0f);
即,我有矩阵:
1.0 nbsp;0.0 nbsp;0.0 nbsp;0.0
0.0 nbsp;1.0 nbsp;0.0 nbsp;0.0
0.0 nbsp;0.0 nbsp;1.0 nbsp;0.0
0.0 nbsp;0.0 nbsp;0.0 nbsp;1.0
我想得到这个:
1.0 nbsp;0.0 nbsp;0.0 nbsp 3.0
0.0 nbsp;1.0 nbsp;0.0 nbsp 4.0
0.0 nbsp;0.0 nbsp;1.0 nbsp 5.0
0.0 nbsp;0.0 nbsp;0.0 nbsp;1.0
对吧?我该怎么做?
我可以做到:
result(0, 3) = 3.0f;
result(1, 3) = 4.0f;
result(2, 3) = 5.0f;
但它并不优雅你有什么建议?
像这样:
Affine3f transform(Translation3f(1,2,3));
Matrix4f matrix = transform.matrix();
这是有更多细节的文档。
catscradle答案的一些替代方案:
Matrix4f mat = Matrix4f::Identity();
mat.col(3).head<3>() << 1, 2, 3;
或
mat.col(3).head<3>() = translation_vector;
或
Matrix4f mat;
mat << Matrix3f::Identity, Vector3f(1, 2, 3),
0, 0, 0, 1;
或
Affine3f a;
a.translation() = translation_vector;
Matrix4f mat = a.matrix();
相关文章:
- Eigen如何在容器循环中干净地附加矩阵
- 当在带有Eigen的C++中使用GDB时,我如何才能看到更多的大矩阵
- 使用Pybind11向Python公开Eigen::张量
- 如何在没有数据拷贝的情况下从指针创建一个Eigen VectorXd对象
- Eigen:调用lpNorm()的正确方法
- 如何调整 std::vector of Eigen::MatrixXd 的大小
- 如何将 Eigen::Ref 与 pybind11 一起使用?
- Eigen c++ 三角形来自
- 使用 operator() 扩展 Eigen::EigenBase
- 更改高度贴图,使其在 4x4 网格上显示 16 个 hieghtmap
- 如何将 Eigen 库安装到 IAR c/c++ 编译器
- 初始化 std::数组 of Eigen::Map
- Eigen - matrix.transpose 会创建矩阵的副本吗?
- 将 MatrixXd 的行传递给要修改的函数,而不在 Eigen 中创建副本
- C++ Eigen 库中的 argmax() 方法
- Eigen::VectorXd 和 Boost::Odeint,不起作用
- TicTacToe with MiniMax algorithm 4x4
- 将数据从 std::Vector 存储到 Eigen::Vector 时出错
- Eigen LinSpaced - 已弃用的副本警告
- 如何在Eigen中平移矩阵(4x4)