歐拉角轉四元數

來源:互聯網
上載者:User

標籤:使用   os   io   for   ad   on   sp   c   

二、歐拉角
  歐拉角指的是:以全局座標係為參考座標系(一定記住是全局座標系),使用x,y,z三個值來分別表示繞(世界的)x軸、y軸、z軸旋轉的角度量值。其取值是在[0, 360]間。一般用roll, pitch, yaw來表示這些分量的旋轉值。因為是以全局座標係為參考座標系,因此每一次的旋轉都不會影響到後續的旋轉轉軸。即:它無法表示任意軸的旋轉。

一直以為  x軸是pitch   y是yaw ,z 是roll的,今天受到教訓了,搞了很久

原來,x軸對應的roll,y軸對應的是pitch  ,z是yaw

如此  歐拉角轉四元數就解決了

void FromEuler(float roll, float pitch, float yaw)
    {
        // Basically we create 3 Quaternions, one for pitch, one for yaw, one for roll
        // and multiply those together.
        // the calculation below does the same, just shorter
        

        
        
            float p = pitch * DEG2RAD / 2.0;
            float y = yaw * DEG2RAD / 2.0;
            float r = roll * DEG2RAD / 2.0;


            float sinp = sin(p);
            float siny = sin(y);
            float sinr = sin(r);
            float cosp = cos(p);
            float cosy = cos(y);
            float cosr = cos(r);


            this->x = sinr * cosp * cosy - cosr * sinp * siny;
            this->y = cosr * sinp * cosy + sinr * cosp * siny;
            this->z = cosr * cosp * siny - sinr * sinp * cosy;
            this->w = cosr * cosp * cosy + sinr * sinp * siny;


            Normalize();
        
    }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.