我有以下MatrixXd V,它们代表2d形状的点:
==========================================
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)?
由于已经有了旋转矩阵,因此我没有理由使用四元数。
谢谢
最佳答案
当然这是行不通的,因为Eigen报告没有从'Eigen :: Matrix3d'到'Eigen :: Affine3d'的可行转换。
Affine3d来自Transform
类,而不是Matrix
类。尝试这个:
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;
}
在这里,旋转应用在左侧,但是您可以修改代码以将其应用在右侧。