Eigen: Perform an 3D rotation around an axis W and anchored at a point P

南楼画角 提交于 2021-02-08 06:30:33

问题


I want to create a function that receives an angle, two vectors, one of them being an unit vector that defines the direction of the axis of rotation and the other is the vector to be rotated and a point P that defines the anchoring position of the rotation.

To implement this in Eigen I guess I would have to use the geometry module, unfortunately, I think the documentation of this module is not great and I am failing to understand it.

My idea is to combine the rotation transformation AngleAxis<float> with two translations, but I don't understand how do I do this. I only managed to define the rotation matrix like this:

VectorXf m1(3);

Matrix3f m;
m1(0)=2;
m1(1)=1;
m1(2)=2;

m = AngleAxisf(M_PI, m1);

However, I could never create an translation matrix or use the concatenation of expressions they mention in the documentation of the module.

I would appreciate any help/suggestions you could give.

My thanks in advance.


回答1:


To represent a rotation plus translation you need a 3x4 or 4x4 matrix. With Eigen you can directly concatenate rotations and translations as follows:

Vector3f w = ...; // rotation axis
Vector3f c = ...; // center of rotation
Affine3f A = Translation3f(c) * AngleAxisf(theta, w) * Translation3f(-c);

Affine3f is an Eigen::Transform. It encapsulates a Matrix4f that you can get with A.matrix(). You can also directly use the Affine3f object to transform points. See the manual for details.



来源:https://stackoverflow.com/questions/38274455/eigen-perform-an-3d-rotation-around-an-axis-w-and-anchored-at-a-point-p

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!