c++ - 如何在 Eigen 中翻译矩阵(4x4)?

标签 c++ matrix translation 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 0.0 0.0 0.0
0.0 1.0 0.0 0.0
0.0 0.0 1.0 0.0
0.0 0.0 0.0 1.0

我想得到这个:

1.0 0.0 0.0 3.0
0.0 1.0 0.0 4.0
0.0 0.0 1.0 5.0
0.0 0.0 0.0 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();

Here是包含更多详细信息的文档。

关于c++ - 如何在 Eigen 中翻译矩阵(4x4)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20323487/

相关文章:

c++ - vector<vector<double>> 是制作矩阵类的好方法吗?

r - 使用 col 行索引从矩阵中提取值

python - "map"的算法

python - 如何翻译 OpenERP 本地化模块的内容

translation - Symfony 3 上的奏鸣曲管理实体翻译

c++ - 修改为具有可配置数量的星星 "*"

c++ - 在 Julia 中编写和调用 ArrayFire 自定义 C 函数的正确方法

c++ - 在固定模板参数的同时扩展模板类

c++ - 模板类的组织

android - 您如何管理 Android 应用的翻译?