(Euler 轉動系統指的是以個別轉動XYZ軸的方式來組合成你所指定的轉動)
要瞭解gimbal lock, 就用Direct3D舉個例子給你瞧瞧...
D3DXMatrixRotationX(&matX, m_fTime/5.0f);
D3DXMatrixRotationY(&matY, D3DX_PI/2.0f);//--->Trigger the gimbal lock!!
D3DXMatrixRotationZ(&matZ, m_fTime/5.0f);
matTotal = matX*matY*matZ;
其中以Y軸做旋轉之後, 新的z軸恰巧和先前的X軸相反.這使得轉動會相消.
數學上來驗證一下你會發現matTotal的結果不管m_fTime的值為何, 都不會改變(一動也不動). 這當然不是我們要的, 所以達不到我們所要求的轉動.
請問gimbal lock的基本觀念
Maybe it's a bit difficult to understand. OK, let me show you a real sence.
可能有點不好理解。讓我們看個現實中的場景。
Say that we have a telescope and a tripod to put the telescope on. The tripod is put on the ground. The top of the tripod holding the telescope is leveled with the horizon (reference plane) so that a vertical rotation axis (we call it X axis) is perfectly vertical to the ground plane. The telescope can then be rotated around 360 degrees in X axis so that it can scan the horizon in all the directions of the compass. Zero degrees azimuth is usually set toward a heading of true north. A second horizontal axis parallel to the ground plane (we call it Y axis), enables the telescope to be rotated in elevation upward or downward from the horizon. The horizon is usually set at zero degrees and the telescope can be rotated +90 degrees upward in elevation so that it is looking straight up toward the zenith or rotated -90 degrees downward so that it is looking vertically at the ground plane.
假如我們有一個望遠鏡和一個用來放望遠鏡的三腳架,(我們將)三腳架放在地面上,使支撐望遠鏡的三腳架的頂部是平行於地平面(參考平面)的,以便使得豎向的旋轉軸(記為x軸)是完全地垂直於地平面的。現在,我們就可以將望遠鏡饒x軸旋轉360度,從而觀察(以望遠鏡為中心的)水平包圍圈的所有方向。通常將正北朝向方位角度記為0度方位角。第二個坐標軸,即平行於地平面的橫向的坐標軸(記為y軸)使得望遠鏡可以饒著它上下旋轉,通常將地平面朝向的仰角記為0 度,這樣,望遠鏡可以向上仰+90度指向天頂,或者向下-90度指向腳底。
OK, that's all we needed. every point in the sky (and the ground) can be referenced by only ONE unique pair of X and Y readings. For example an X of 90 degrees and Y of 45 degrees specifies a point exactly due east of the telescope and in a skyward direction half way up toward the zenith.
好了,萬事俱備。現在,天空中(包括地面上)的每個點只需要唯一的一對x和y度數就可以確定。比如x=90度,y=45度指向的點是位於正東方向的半天空上。
Now let me show you how the gimal lock occurred. We detect a high flying aircraft, near the horizon, due east from the telescope (X = 90 degrees, Y = 10 degrees) and we follow it (track it) as it comes directly toward us. The X angle stays at 90 degrees and the Y angle slowly increases. As the aircraft comes closer the Y angle increases more rapidly and just as the aircraft reaches an Y of 90 degrees (exactly overhead), it makes a sharp turn due south. We find that we cannot quickly move the telescope toward the south because the Y angle is exactly +90 degrees so we loose sight (loose track) of the aircraft . We have GIMBAL LOCK!
現在,看看萬向節死鎖是怎麼發生的。一次,我們探測到有一個飛行器貼地飛行,位於望遠鏡的正東方向(x=90度,y=10度),朝著我們直飛過來,我們跟蹤它。飛行器飛行方向是保持x軸角度90度不變,而y向的角度在慢慢增大。隨著飛行器的臨近,y軸角增長的越來越快且當y向的角度達到90度時(即將超越),突然它急轉彎朝南飛去。這時,我們發現我們不能將望遠鏡朝向南方,因為此時y向已經是 90度,造成我們失去跟蹤目標。這就是萬向節死鎖!
(譯註:為什麼說不能將望遠鏡朝向南方呢,讓我們看看坐標變化,從開始的(x=90 度,y=10度)到(x=90度,y=90度),這個過程沒有問題,望遠鏡慢慢轉動跟蹤飛行器。當飛行器到達(x=90度,y=90度)後,坐標突然變成(x=180度,y=90度)(因為朝南),x由90突變成180度,所以望遠鏡需要饒垂直軸向x軸旋轉180-90=90度以便追上飛行器,但此時,望遠鏡已經是平行於x軸,我們知道饒平行於自身的中軸線的的旋轉改變不了朝向,就像擰螺絲一樣,螺絲頭的指向不變。所以望遠鏡的指向還是天頂。而後由於飛行器飛遠,坐標變成(x=180度,y<90度)時,y向角減小,望遠鏡只能又轉回到正東指向,望'器'興嘆。這說明用x,y旋轉角(又稱歐拉角)來定向物體有時並不能按照你想像的那樣工作,象上面的例子中從(x=90度,y=10度)到(x=90度,y=90度),坐標值的變化和飛行器空間的位置變化一一對應,但是從(x=90度,y=90度)到(x=180度,y=90度),再到(x=180度,y<90度)這個變化,飛行器位置是連續的變化,但坐標值的變化卻不是連續的(從90突變到180),其原因在於(x=90度,y=90度)和(x=180度,y=90度)甚至和(x=任意度,y=90度)這些不同的坐標值對應空間同一個位置,這種多個坐標值對應同一個位置的不一致性是造成死鎖的根源。【感謝zeroyear, fatfatson 等的深層解釋,原先解釋的不夠清晰,故修改如上。原文:按照歐拉角旋轉確實可以正確地定向,但從(x=90度,y=90度)到(x=180度,y=90度),再到(x=180度,y<90度),按照歐拉角旋轉後的定向並非正確】) It's a example of 2D coordinate frame. It's very similar in 3D frame. We say that you have a vector which is parellel to the X axis. And we rotate it around Y axis so that the vector is parellel to the Z axis. Then we find that any rotations around Z axis will have no effect on the vector. We say that we have a GIMBAL LOCK 上面是2維坐標系中的例子,同樣,對於3維的也一樣。比如有一個平行於x軸的向量,我們先將它饒y旋轉直到它平行於z軸,這時,我們會發現任何饒z的旋轉都改變不了向量的方向,即萬向節死鎖。 (譯註:3維的萬向節死鎖情況分析見:http://www.cnblogs.com/soroman/archive/2008/03/24/1118996.html)
SoRoMan - 譯:關於萬向節死鎖(Gimbal Lock)
影片圖解(建議閱讀)
Gimble Lock - Explained
延伸閱讀
wikipedia - 歐拉角
wikipedia - 四元數
沒有留言:
張貼留言