2015-07-28 97 views
2

我正在嘗試創建一個四元數,旋轉歐拉角並將其轉換回歐拉角。我正在使用Eigen。從Euler轉換到Quaternion反之亦然,但是當我使用角度軸旋轉時,我的值約爲20-50%。例如,當我嘗試從0,0,0旋轉到90,50,60時,我得到x:75,5 y:103,13,z:78,46。 任何想法,我錯了轉彎?我使用102/YXZ慣例。 我試圖像這裏描述的那樣實現它:Rotate a quaternion by Euler angles input使用特徵根據歐拉角旋轉四元數

Vector3f retVector; 
    Matrix3f rotFromMat, qautRotMatrix; 

const auto fromPitch = xFrom*M_PI/360; 
const auto fromYaw = zFrom*M_PI/360; 
const auto fromRoll = yFrom*M_PI/360; 



rotFromMat = AngleAxisf(fromRoll, Vector3f::UnitY()) 
    * AngleAxisf(fromPitch, Vector3f::UnitX()) 
    * AngleAxisf(fromYaw, Vector3f::UnitZ()); 
Quaternionf fromQuat(rotFromMat); 

    fromQuat.normalize(); 

    fromQuat = fromQuat * AngleAxisf(yTo, Vector3f::UnitY()); 
    fromQuat = fromQuat * AngleAxisf(xTo, Vector3f::UnitX()); 
    fromQuat = fromQuat * AngleAxisf(zTo, Vector3f::UnitZ()); 


    qautRotMatrix = fromQuat.toRotationMatrix(); 

    retVector = quatRotMatrix.eulerAngles(1, 0, 2); 
    retVector *= 360/M_PI; 

    return retVector; 
+0

當旋轉在歐拉角度任意軸旋轉90度,一個名爲'萬向節鎖'的現象出現了,這就產生了意想不到的行爲。你處理了嗎? –

+0

我將旋轉矩陣轉換爲四元數「Quaternionf fromQuat(rotFromMat);」在旋轉之前。萬向節鎖應該沒問題。 –

回答

1

您沒有給出足夠的細節來說明如何重現這一點。

但我可以看出兩個錯誤: *度數和弧度之間的比率是180/PI而不是360/PI。 *您的輪換命令錯誤!左側旋轉右側:

fromQuat = AngleAxisf(...) * fromQuat; 

從我能猜到你已經解決了這個日期,我在這裏評論的新觀衆