如何在Eigen中翻译矩阵(4x4)? [英] How translation a matrix(4x4) in Eigen?

查看:384
本文介绍了如何在Eigen中翻译矩阵(4x4)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How translation a matrix(4x4) in Eigen?

//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);

即,我有矩阵:

ie, I have matrix:

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

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

And I want get this:

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;

但这并不优雅. =)您的建议是什么?

But it's not elegant. =) What you advice?

推荐答案

像这样:

Affine3f transform(Translation3f(1,2,3));
Matrix4f matrix = transform.matrix();

此处是具有更多详细信息的文档.

Here is the doc with more details.

这篇关于如何在Eigen中翻译矩阵(4x4)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆