如何使用 Eigen3 从比例和平移创建变换矩阵?
我对如何创建一个简单的变换矩阵感到困惑。
我有以下 C++ 代码:
static constexpr float pos_scale = 2 * size / iside;
static constexpr std::array<float, 2> pos_translation = { -size, -size };
不幸的是, pos_translation
需要是 std::array
因为你无法制作 Eigen::Vector2f
> constexpr。
然后我有一个向量:
Vector2i xy;
它将填充一些数据。 我想将 xy
转换为 Vector2f
,方法是将其转换为齐次坐标,将其与变换矩阵相乘,然后再次删除齐次坐标。
变换矩阵
Matrix3f xy_to_pos;
至少声明为,我认为这是正确使用的类型?
我的问题是,如何从 pos_scale
(必须首先应用:首先是比例,然后是平移)和 pos_translation
初始化 xy_to_pos
?
一旦我有了xy_to_pos
,我将如何使用它来将xy
转换为Vector2f pos
?
我尝试了各种方法,
Matrix3f xy_to_pos = Matrix3f::Identity() * Eigen::Scaling(pos_scale) * Eigen::Translation2f(pos_translation[0], pos_translation[1]);
但没有编译任何内容,并且编译错误也没有帮助。当然,我也用谷歌搜索过这个问题,但找不到有帮助的例子。
I am stumped on how to create a simple transformation matrix.
I have the following C++ code:
static constexpr float pos_scale = 2 * size / iside;
static constexpr std::array<float, 2> pos_translation = { -size, -size };
Unfortunately, the pos_translation
needs to be a std::array
because you can't make an Eigen::Vector2f
constexpr.
Then I have a vector:
Vector2i xy;
That will be filled with some data.
I want to convert xy
to a Vector2f
by converting it to homogeneous coordinates, multiplying it with a transformation matrix and then dropping the homogeneous coordinates again.
The transformation matrix is declared as
Matrix3f xy_to_pos;
at least, I think that is the right type to use?
My question is, how can I initialize xy_to_pos
from pos_scale
(which has to be applied first: first the scale then the translation) and pos_translation
?
And once I have xy_to_pos
how would I use it to convert xy
to Vector2f pos
?
I tried all kinds of things, like
Matrix3f xy_to_pos = Matrix3f::Identity() * Eigen::Scaling(pos_scale) * Eigen::Translation2f(pos_translation[0], pos_translation[1]);
but nothing compiles, and the compile errors don't help. I Googled for this too of course, but couldn't find an example that helped.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想通了:
I figured it out: