如何使用变换通过 Eigen 中的 Matrix3d 旋转矩阵旋转点 MatrixXd
How to rotate a point MatrixXd by a Matrix3d rotation matrix in Eigen using transformations
我有以下 MatrixXd V,代表二维形状的点:
==========================================
Bounding box vertices (AV) (Rows: 8 Cols: 3)
==========================================
[[ 2.367639937564554, 3.100420929531666, 0]
[ 2.367639937564554, 3.100420929531666, 0]
[ 2.367639937564554, -3.097445263635904, 0]
[ 2.367639937564554, -3.097445263635904, 0]
[-2.362324650030633, 3.100420929531666, 0]
[-2.362324650030633, 3.100420929531666, 0]
[-2.362324650030633, -3.097445263635904, 0]
[-2.362324650030633, -3.097445263635904, 0]]
我想通过这个 Matrix3d 旋转矩阵旋转形状:
==========================================
RM: (RM) (Rows: 3 Cols: 3)
==========================================
[[ 0.997496638487424, -0.07071390391068358, 0]
[ 0.07071390391068358, 0.997496638487424, 0]
[ 0, 0, 1]]
==========================================
我想不出正确的方法...我已经检查过转换:
Affine3d tf = RM;
tf.rotate(V);
当然这行不通,因为 Eigen 报告没有从 'Eigen::Matrix3d' 到 'Eigen::Affine3d' 的可行转换。
简而言之,如何告诉 Eigen 使用这个旋转矩阵 (RM) 作为变换并将其应用于目标矩阵 (V)?
因为我已经有了旋转矩阵,所以我没有理由使用四元数...
谢谢
Of course this doesn't work, as Eigen reports no viable conversion from 'Eigen::Matrix3d' to 'Eigen::Affine3d'.
Affine3d 来自 Transform
class 而不是 Matrix
class。试试这个:
Affine3d tf = Affine3d(RM);
现在关于旋转,我想出了这个小演示:
#include <iostream>
#include <eigen3/Eigen/Dense>
using Eigen::Matrix3d;
using Eigen::MatrixXd;
using Eigen::Affine3d;
int main(){
//obviously not a rotation matrix, but needed some numbers only
Matrix3d rot = Matrix3d::Random();
std::cout << "We have the rotation matrix:" << std::endl;
std::cout << rot << std::endl;
Affine3d aff_rot = Affine3d(rot);
std::cout << "Affine version:" << std::endl;
std::cout << aff_rot.matrix() << std::endl;
MatrixXd points = MatrixXd::Random(8,3);
std::cout << "Some random points:" << std::endl;
std::cout << points << std::endl;
std::cout << std::endl << std::endl;
MatrixXd m = aff_rot * points.transpose().colwise().homogeneous();
MatrixXd result = m.transpose();
std::cout << "Result:" << std::endl;
std::cout << result << std::endl;
return 0;
}
此处旋转应用于左侧,但您可以调整代码以将其应用于右侧。
为什么不直接将坐标矩阵乘以旋转矩阵?
#include <iostream>
#include <Eigen/Core>
#include <Eigen/Geometry>
int main(){
Eigen::MatrixXd AV(8,3);
AV <<
2.367639937564554, 3.100420929531666, 0,
2.367639937564554, 3.100420929531666, 0,
2.367639937564554, -3.097445263635904, 0,
2.367639937564554, -3.097445263635904, 0,
-2.362324650030633, 3.100420929531666, 0,
-2.362324650030633, 3.100420929531666, 0,
-2.362324650030633, -3.097445263635904, 0,
-2.362324650030633, -3.097445263635904, 0;
Eigen::Matrix3d RM(3,3);
RM << 0.997496638487424, -0.07071390391068358, 0,
0.07071390391068358, 0.997496638487424, 0,
0, 0, 1;
Eigen::AngleAxisd aa(RM);
std::cout << "Axis: " << aa.axis().transpose() << " angle:" << aa.angle() << std::endl;
Eigen::MatrixXd result = AV * RM;
std::cout << "Result:" << std::endl << result << std::endl;
return 0;
}
产生:
Axis: 0 0 1 angle:0.070773
Result:
2.58096 2.92523 0
2.58096 2.92523 0
2.14268 -3.25712 0
2.14268 -3.25712 0
-2.13717 3.25971 0
-2.13717 3.25971 0
-2.57544 -2.92264 0
-2.57544 -2.92264 0
我有以下 MatrixXd V,代表二维形状的点:
==========================================
Bounding box vertices (AV) (Rows: 8 Cols: 3)
==========================================
[[ 2.367639937564554, 3.100420929531666, 0]
[ 2.367639937564554, 3.100420929531666, 0]
[ 2.367639937564554, -3.097445263635904, 0]
[ 2.367639937564554, -3.097445263635904, 0]
[-2.362324650030633, 3.100420929531666, 0]
[-2.362324650030633, 3.100420929531666, 0]
[-2.362324650030633, -3.097445263635904, 0]
[-2.362324650030633, -3.097445263635904, 0]]
我想通过这个 Matrix3d 旋转矩阵旋转形状:
==========================================
RM: (RM) (Rows: 3 Cols: 3)
==========================================
[[ 0.997496638487424, -0.07071390391068358, 0]
[ 0.07071390391068358, 0.997496638487424, 0]
[ 0, 0, 1]]
==========================================
我想不出正确的方法...我已经检查过转换:
Affine3d tf = RM;
tf.rotate(V);
当然这行不通,因为 Eigen 报告没有从 'Eigen::Matrix3d' 到 'Eigen::Affine3d' 的可行转换。
简而言之,如何告诉 Eigen 使用这个旋转矩阵 (RM) 作为变换并将其应用于目标矩阵 (V)?
因为我已经有了旋转矩阵,所以我没有理由使用四元数...
谢谢
Of course this doesn't work, as Eigen reports no viable conversion from 'Eigen::Matrix3d' to 'Eigen::Affine3d'.
Affine3d 来自 Transform
class 而不是 Matrix
class。试试这个:
Affine3d tf = Affine3d(RM);
现在关于旋转,我想出了这个小演示:
#include <iostream>
#include <eigen3/Eigen/Dense>
using Eigen::Matrix3d;
using Eigen::MatrixXd;
using Eigen::Affine3d;
int main(){
//obviously not a rotation matrix, but needed some numbers only
Matrix3d rot = Matrix3d::Random();
std::cout << "We have the rotation matrix:" << std::endl;
std::cout << rot << std::endl;
Affine3d aff_rot = Affine3d(rot);
std::cout << "Affine version:" << std::endl;
std::cout << aff_rot.matrix() << std::endl;
MatrixXd points = MatrixXd::Random(8,3);
std::cout << "Some random points:" << std::endl;
std::cout << points << std::endl;
std::cout << std::endl << std::endl;
MatrixXd m = aff_rot * points.transpose().colwise().homogeneous();
MatrixXd result = m.transpose();
std::cout << "Result:" << std::endl;
std::cout << result << std::endl;
return 0;
}
此处旋转应用于左侧,但您可以调整代码以将其应用于右侧。
为什么不直接将坐标矩阵乘以旋转矩阵?
#include <iostream>
#include <Eigen/Core>
#include <Eigen/Geometry>
int main(){
Eigen::MatrixXd AV(8,3);
AV <<
2.367639937564554, 3.100420929531666, 0,
2.367639937564554, 3.100420929531666, 0,
2.367639937564554, -3.097445263635904, 0,
2.367639937564554, -3.097445263635904, 0,
-2.362324650030633, 3.100420929531666, 0,
-2.362324650030633, 3.100420929531666, 0,
-2.362324650030633, -3.097445263635904, 0,
-2.362324650030633, -3.097445263635904, 0;
Eigen::Matrix3d RM(3,3);
RM << 0.997496638487424, -0.07071390391068358, 0,
0.07071390391068358, 0.997496638487424, 0,
0, 0, 1;
Eigen::AngleAxisd aa(RM);
std::cout << "Axis: " << aa.axis().transpose() << " angle:" << aa.angle() << std::endl;
Eigen::MatrixXd result = AV * RM;
std::cout << "Result:" << std::endl << result << std::endl;
return 0;
}
产生:
Axis: 0 0 1 angle:0.070773
Result:
2.58096 2.92523 0
2.58096 2.92523 0
2.14268 -3.25712 0
2.14268 -3.25712 0
-2.13717 3.25971 0
-2.13717 3.25971 0
-2.57544 -2.92264 0
-2.57544 -2.92264 0