打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
eigen转换四元数和欧拉角
#include <iostream>  
#include <stdio.h>  
#include <Eigen/Core>  
#include <Eigen/Geometry>  

using namespace std;

#define PI (3.1415926535897932346f)  

::Eigen::Quaterniond  Euler_to_Quaterniond(double yaw, double pitching, double droll)
{
::Eigen::Vector3d ea0(yaw,pitching,droll);  
    ::Eigen::Matrix3d R;  
    R = ::Eigen::AngleAxisd(ea0[0], ::Eigen::Vector3d::UnitZ())  
        * ::Eigen::AngleAxisd(ea0[1], ::Eigen::Vector3d::UnitY())  
        * ::Eigen::AngleAxisd(ea0[2], ::Eigen::Vector3d::UnitX());  
  
    //cout << R << endl << endl;  
  
    //RotationMatrix to Quaterniond  
    ::Eigen::Quaterniond q;   
    q = R;      
    cout <<"x:"<<q.x()<<"\t"<<"y:"<<q.y()<<"\t"<<"z:"<<q.z()<<"\t"<<"w:"<<q.w()<<endl;
return q;
}

::Eigen::Vector3d Quaterniond_to_Euler(double x, double y, double z, double w)
{
::Eigen::Quaterniond q(w,x,y,z);
::Eigen::Matrix3d Rx = q.toRotationMatrix();  
::Eigen::Vector3d ea1 = Rx.eulerAngles(2,1,0);       
    cout <<ea1[0]<<" "<<ea1[1]<<" "<<ea1[2]<<endl;
return ea1;
}


int main(int argc, char **argv)   
{    
    double yaw = PI/3,pitching = PI/4,droll = PI/6;  
//double yaw = PI,pitching = PI,droll = PI;

printf("T yaw[%f] pitching[%f] droll[%f]\n",yaw,pitching,droll);

::Eigen::Quaterniond q = Euler_to_Quaterniond(yaw, pitching, droll);

    ::Eigen::Vector3d    V = Quaterniond_to_Euler(q.x(), q.y(), q.z(), q.w());
//cout << V/PI*180 << endl;
#if 0      
printf("T yaw[%f] pitch[%f]  droll[%f]\n", yaw, pitching, droll);
      //EulerAngles to RotationMatrix  
    ::Eigen::Vector3d ea0(yaw,pitching,droll);  
    ::Eigen::Matrix3d R;  
    R = ::Eigen::AngleAxisd(ea0[0], ::Eigen::Vector3d::UnitZ())  
        * ::Eigen::AngleAxisd(ea0[1], ::Eigen::Vector3d::UnitY())  
        * ::Eigen::AngleAxisd(ea0[2], ::Eigen::Vector3d::UnitX());  
  
    cout << R << endl << endl;  
  
    //RotationMatrix to Quaterniond  
    ::Eigen::Quaterniond q;   
    q = R;      
    cout << q.x() << endl << endl;  
    cout << q.y() << endl << endl;  
    cout << q.z() << endl << endl;  
    cout << q.w() << endl << endl;  

::Eigen::Quaterniond q1(q.w(),q.x(),q.y(),q.z()); 
 
    //Quaterniond to RotationMatrix  
    ::Eigen::Matrix3d Rx = q1.toRotationMatrix();  
    cout << Rx << endl << endl;  
      
      
    //RotationMatrix to EulerAngles  
    ::Eigen::Vector3d ea1 = Rx.eulerAngles(2,1,0);       
    //cout << ea1/PI*180 << endl << endl;  
    cout << ea1 << endl << endl;  
      
    std::cin.ignore();  
#endif
    return 0;  
}  

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Eigen库使用教程之旋转矩阵,旋转向量和四元数的初始化和相互转换的实现
Qt使用Eigen矩阵库
Ubuntu安装eigen
Eigen 3.2稀疏矩阵入门
高翔Slambook第七讲代码解读(3d-2d位姿估计)
法向量、旋转矩阵计算(五十一)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服