问题
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