#include<iostream>
#include<Eigen/Dense>
#include<Eigen/Core>
using namespace std;
using namespace Eigen;
int main(int argc, char **argv)
{
AngleAxisd rotation_vectorX(M_PI / 2, Vector3d(1, 0, 0));
AngleAxisd rotation_vectorY(M_PI / 4, Vector3d(0, 1, 0));
AngleAxisd rotation_vectorZ(M_PI / 6, Vector3d(0, 0, 1));
AngleAxisd rotation_vectorX_(M_PI / 2, Eigen::Vector3d::UnitX());
AngleAxisd rotation_vectorY_(M_PI / 4, Eigen::Vector3d::UnitY());
AngleAxisd rotation_vectorZ_(M_PI / 6, Eigen::Vector3d::UnitZ());
cout << rotation_vectorX.angle()/M_PI *180 << endl;
cout << rotation_vectorX.axis().transpose() << endl;
cout << rotation_vectorY.angle()/M_PI *180 << endl;
cout << rotation_vectorY.axis().transpose() << endl;
Eigen::Matrix3d rotation_matrix1 = Eigen::Matrix3d::Identity();
rotation_matrix1 = rotation_vectorX.matrix();
cout << "rotation_vectorX =\n" << rotation_matrix1 << endl;
Eigen::Matrix3d rotation_matrix2 = rotation_vectorX.toRotationMatrix();
cout << "rotation_vectorX =\n" << rotation_matrix2 << endl;
Eigen::Vector3d eulerAngle1 = rotation_vectorX.matrix().eulerAngles(2,1,0);
cout << "eulerAngle1, z y x: " << eulerAngle1.transpose() << endl;
cout << "eulerAngle1, z y x: " << eulerAngle1.transpose()/M_PI *180 << endl;
Eigen::Quaterniond quaternion1(rotation_vectorX);
Eigen::Quaterniond quaternion1_1;
quaternion1_1 = rotation_vectorX;
cout << "quaternion1 = " << quaternion1.coeffs().transpose() << endl;
cout << "quaternion1.x = " << quaternion1.x() << endl;
cout << "quaternion1.y = " << quaternion1.y() << endl;
cout << "quaternion1.z = " << quaternion1.z() << endl;
cout << "quaternion1.w = " << quaternion1.w() << endl;
quaternion1.normalized();
cout << "quaternion1 = " << quaternion1.coeffs().transpose() << endl;
Eigen::Matrix3d M1 ;
M1.setZero();
Eigen::Matrix3d M2 = Eigen::Matrix3d::Identity() ;
Eigen::AngleAxisd rotation_vector2;
rotation_vector2.fromRotationMatrix(rotation_matrix2);
Eigen::AngleAxisd rotation_vector2_1(rotation_matrix2);
cout << "rotation_vector2 " << "angle is: " << rotation_vector2.angle() * (180 / M_PI)
<< " axis is: " << rotation_vector2.axis().transpose() << endl;
cout << "rotation_vector2_1 " << "angle is: " << rotation_vector2_1.angle() * (180 / M_PI)
<< " axis is: " << rotation_vector2_1.axis().transpose() << endl;
Matrix3d Euler_angleZYX = rotation_vectorZ.toRotationMatrix() *rotation_vectorY.toRotationMatrix() * rotation_vectorX.toRotationMatrix() ;
cout <<" Euler_angleZYX = \n "<< Euler_angleZYX << endl;
Vector3d euler_angle = Euler_angleZYX.eulerAngles(2,1,0) ;
cout <<"euler_angle.transpose() = " << euler_angle.transpose() << endl;
cout << euler_angle(0)/3.14*180 << " " << euler_angle(1)/3.14*180 << " " << euler_angle(2)/3.14*180 << endl;
Quaterniond matrixtoquaternion(Euler_angleZYX);
Quaterniond matrixtoquaternion2;
matrixtoquaternion2 = Euler_angleZYX;
cout << "四元数 " << matrixtoquaternion.coeffs().transpose() << endl;
cout << endl << "********** EulerAngle **********" << endl;
Eigen::Vector3d ea0(0.785398, -0, 0);
Eigen::Vector3d ea = Euler_angleZYX.eulerAngles(2,1,0) ;
Eigen::Matrix3d rotation_matrix3;
rotation_matrix3 = Eigen::AngleAxisd(ea[0], Eigen::Vector3d::UnitZ()) *
Eigen::AngleAxisd(ea[1], Eigen::Vector3d::UnitY()) *
Eigen::AngleAxisd(ea[2], Eigen::Vector3d::UnitX());
cout << "rotation matrix3 =\n" << rotation_matrix3 << endl;
Eigen::Quaterniond quaternion3;
quaternion3 = Eigen::AngleAxisd(ea[0], Eigen::Vector3d::UnitZ()) *
Eigen::AngleAxisd(ea[1], Eigen::Vector3d::UnitY()) *
Eigen::AngleAxisd(ea[2], Eigen::Vector3d::UnitX());
cout << "quaternion3 x: " << quaternion3.x() << endl;
cout << "quaternion3 y: " << quaternion3.y() << endl;
cout << "quaternion3 z: " << quaternion3.z() << endl;
cout << "quaternion3 w: " << quaternion3.w() << endl;
Eigen::AngleAxisd rotation_vector3;
rotation_vector3 = Eigen::AngleAxisd(ea[0], Eigen::Vector3d::UnitZ()) *
Eigen::AngleAxisd(ea[1], Eigen::Vector3d::UnitY()) *
Eigen::AngleAxisd(ea[2], Eigen::Vector3d::UnitX());
cout << "rotation_vector3 " << "angle is: " << rotation_vector3.angle() * (180 / M_PI)
<< " axis is: " << rotation_vector3.axis().transpose() << endl;
cout << endl << "********** Quaternion **********" << endl;
Eigen::Quaterniond quaternion4(0.701057, 0.560986, 0.430459, -0.092296 );
Eigen::AngleAxisd rotation_vector4(quaternion4);
Eigen::AngleAxisd rotation_vector4_1;
rotation_vector4_1 = quaternion4;
cout << "rotation_vector4 " << "angle is: " << rotation_vector4.angle() * (180 / M_PI)
<< " axis is: " << rotation_vector4.axis().transpose() << endl;
cout << "rotation_vector4_1 " << "angle is: " << rotation_vector4_1.angle() * (180 / M_PI)
<< " axis is: " << rotation_vector4_1.axis().transpose() << endl;
Eigen::Matrix3d rotation_matrix4;
rotation_matrix4 = quaternion4.matrix();
Eigen::Matrix3d rotation_matrix4_1;
rotation_matrix4_1 = quaternion4.toRotationMatrix();
cout << "rotation matrix4 =\n" << rotation_matrix4 << endl;
cout << "rotation matrix4_1 =\n" << rotation_matrix4_1 << endl;
Eigen::Vector3d eulerAngle4 = quaternion4.matrix().eulerAngles(2,1,0);
cout << "yaw(z) pitch(y) roll(x) = " << eulerAngle4.transpose() << endl;
cout << eulerAngle4(0)/M_PI *180 << " " << eulerAngle4(1)/M_PI *180 << " " << eulerAngle4(2)/M_PI *180 << endl;
return 0;
}
|