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;
當旋轉在歐拉角度任意軸旋轉90度,一個名爲'萬向節鎖'的現象出現了,這就產生了意想不到的行爲。你處理了嗎? –
我將旋轉矩陣轉換爲四元數「Quaternionf fromQuat(rotFromMat);」在旋轉之前。萬向節鎖應該沒問題。 –