三維空間剛體運動2:旋轉向量與羅德里格斯公式


本篇繼續參照高翔老師《視覺SLAM十四講從理論到實踐》,講解三維空間剛體運動。博文將原第三講分爲四部分來講解:1、旋轉矩陣和變換矩陣;2、旋轉向量與羅德里格斯公式;3、歐拉角表示旋轉;4、四元數表示變換。本文相對於原文會適當精簡,同時爲便於理解,會加入一些註解和補充知識點,本篇爲第二部分:旋轉向量表示旋轉,另外三部分請參照博主的其他博文。

1.定義

對於矩陣表示方式至少有以下兩個缺點:
1.SO(3)SO(3)的旋轉矩陣有9個量,但一次旋轉只有3個自由度,因此這種表達方式是冗餘的,同理SE(4)SE(4)也是。那麼,是否有更緊湊的表示呢?
2.旋轉矩陣和變換矩陣自身帶有約束:它必須是正交矩陣且行列式爲。當想估計或優化一個旋轉矩陣或變換矩陣時,這些約束會使得求解變的更困難。
因此,希望有一種方式能夠緊湊的描述旋轉和平移。

旋轉向量:事實上,任意旋轉都可以用一個旋轉軸和一個旋轉角來刻畫,於是,我們可以使用一個向量uu(爲方便表達,上下文統一採用符號uu表示單位向量,其他符號n,kn,k等也是可以的),其方向與旋轉軸一致,其長度等於旋轉角θ\theta,那麼向量θu\theta u也可以描述這個旋轉,這種向量稱爲旋轉向量(或軸角/角軸,Axis-Angle),只需一個三維向量即可描述旋轉。

在三維空間中定義一個方向只需要用到兩個量就可以了(與任意兩個座標軸之間的夾角,比如地球的經緯度就可以確定方向),因此第三個量可以用來定義長度,表示旋轉角度。同樣,對於變換矩陣,使用一個旋轉向量和一個平移向量即可表達一次變換,此時變量維數正好是六維。

2.羅德里格斯公式

2.1 定義

羅德里格斯公式:旋轉向量和旋轉矩陣有什麼聯繫嗎?事實上,從旋轉向量到旋轉矩陣的轉換過程由羅德里格斯公式(Rodrigues’s Formula)表示。因爲任意旋轉都可以由一個旋轉軸uu和一個旋轉角θ\theta刻畫,故羅德里格斯公式具體形式如下:R=cosθI+(1cosθ)uuT+sinθu(2.1)R= \cos \theta I+(1-\cos \theta )uu^{T}+\sin \theta u^{\wedge }\tag{2.1}符號^{\wedge }是向量到反對稱矩陣的轉換符,見第一篇博客的公式(1.4)。公式還可以寫爲:R=I+(1cosθ)U2+sinθU.(2.2)R= I +(1-\cos \theta )U^{2} + \sin \theta U. \tag{2.2}其中U代表向量uu轉換的反對稱矩陣。

2.2 推導

首先,理解下圖。定義uu是旋轉軸的單位向量,vv爲旋轉向量,wwu×vu\times v方向上的單位向量。圖中vvuu旋轉角度θ\theta得到vrotv_{rot}。將vv分解爲平行於旋轉軸uu以及正交於uu的兩個分量:vv_{∥}vv_{⊥}。將vrotv_{rot}分解爲平行於旋轉軸uu以及正交於uu的兩個分量:vrotv_{rot||}vrotv_{rot\perp}。向量aabb分別是vrotv_{rot}wwvv_{\perp }方向上的分量。
圖2.1:旋轉向量3D圖(數學繪圖軟件推薦geogebra
旋轉向量3D圖
所謂推導旋轉方程,實則求出一個旋轉矩陣,使得Vrot=RvV_{rot}=Rv,所以我們要做的就是找出vrotv_{rot}vv,並用矩陣來表示。
此公式有2種形式,故而也有2種推導方法,兩者推導方法的不同主要在vv_{\perp }的表示上。具體推導過程如下。

2.2.1 推導一

推導一推導過程如下:

  1. vv:對vv進行向量分解:v=v+vv = v_{\perp } + v_{||},根據向量減法可得:v=vv(2.3)v_{\perp } = v - v_{||}\tag{2.3}vrotv_{rot||}進行向量分解vrot=vrot+vrot(2.4)v_{rot}=v_{rot||}+v_{rot\perp } \tag{2.4}下邊分別推導vrotv_{rot||}vrotv_{rot\perp}
  2. vrotv_{rot||}:由於旋轉過程平行向量的不變性可得vrot=vv_{rot||} = v_{||}vv_{||}其實就是vvuu上的正交投影(Orthogonal Projection),根據正交投影公式:v=proju(v)=uvuuu=uvu2u=(uv)u(2.5)\begin{aligned} v_{||} &= proj_{u}(v) &= \frac{u\cdot v}{u\cdot u}u &= \frac{u\cdot v}{||u||^{2}}u &= (u\cdot v)u \end{aligned}\tag{2.5}其中uu=u2u\cdot u=||u||^{2}u=1||u||=1,點積(vu)(v\cdot u)爲標量,所以再乘向量uu得到一個矢量。
  3. vrotv_{rot\perp}:下面畫出vrotv_{rot\perp}的俯視圖:
    圖2.2:旋轉向量俯視圖
    旋轉向量俯視圖

我們需要處理正交於uuvv_{⊥},因爲這兩個向量是正交的,這個旋轉可以看做是平面內的一個旋轉,因爲旋轉不改變vv_{⊥}的長度,所以路徑是一個圓。現在,3D的旋轉被轉化爲了2D平面上的旋轉。由於在這個平面上只有一個向量vv_{⊥},用它來表示一個旋轉是不夠的,我們還需要構造一個同時正交於uuvv_{⊥}的向量ww,這個可以通過叉乘來獲得: w=u×v(2.6)w=u\times v_{⊥}\tag{2.6}注意叉乘的順序,因爲我們使用的是右手座標系統,按照右手定則你可以發現這 個新的向量ww指向vv_{⊥}逆時針旋轉(π/2)(π/2)後的方向,並且和vv_{⊥}一樣也處於正交於uu 的平面內。因爲u∥u∥ = 1,我們可以發現:w=u×v=uvsin(π2)=v(2.7)\begin{aligned} ||w|| &= ||u\times v_{⊥}|| \\ &= ||u||\cdot ||v_{⊥}||\cdot \sin(\frac{\pi}{2})\\ &=||v_{⊥}|| \end{aligned}\tag{2.7}也就是說,wwvv_{⊥}的模長是相同的,所以,ww也位於圓上。有了這個新的向量ww, 就相當於在平面內有了兩個座標軸。我們現在可以把vrotv_{rot||}投影到wwvv_{⊥}上,將其分解爲向量aabb,使用一些三角知識可以得到:vrot=a+b=sinθw+cosθv=sinθ(u×v)+cosθv(2.8)\begin{aligned} v_{rot⊥} &= a + b \\ &= \sin \theta w + \cos \theta v_{⊥} \\ &= \sin \theta (u\times v_{⊥}) + \cos \theta v_{⊥} \end{aligned}\tag{2.8}因爲叉乘遵守分配律,且uu平行於vv_{||},故:u×v=u×(vv)=u×vu×v=u×v(2.9)\begin{aligned} u\times v_{⊥} &=u\times (v-v_{||})\\ &=u\times v - u \times v_{||}\\ &=u \times v\end{aligned}\tag{2.9}另外,向量aabb還有另外一種證法,稍顯繁瑣,有興趣的同學請參見後兩小節。

  1. 綜上可得:
    vrot=vrot+vrot=a+b+v=sinθu×v+cosθv+(uv)u=sinθu×v+cosθ(vv)+(vu)u=sinθu×v+cosθ(v(vu)u)+(vu)u=cosθv+(1cosθ)(vu)u+sinθu×v(2.10)\begin{aligned} v_{rot} &= v_{rot\perp}+v_{rot||} \\ &=a+b+v_{||} \\ &=\sin \theta u\times v_{⊥} +\cos \theta v_{\perp } + (u\cdot v)u \\ &=\sin \theta u\times v +\cos \theta (v - v_{||}) + (v\cdot u)u \\ &=\sin \theta u\times v +\cos \theta (v - (v\cdot u)u ) + (v\cdot u)u \\ &=\cos \theta v+(1-\cos \theta )(v\cdot u)u + \sin \theta u\times v \end{aligned}\tag{2.10}
  2. 顯然:到此步,我們還無法將其用矩陣來表示,所以需要對(vu)u(v\cdot u)uu×vu\times v 進行矩陣轉換,由點積的交換律和結合律得:(vu)u=u(vu)=u(uTv)=uuTv(2.11)(v\cdot u)u=u\cdot(v\cdot u)=u\cdot (u^{T} v)=u\cdot u^{T} v\tag{2.11}其中的向量都是列向量,點積展開規則爲:xy=[x,y]=xTyx\cdot y = [x, y] =x^{T}y
    對於u×vu\times v可用叉乘矩陣來化簡爲UvUvu×v=[(u×v)x(u×v)y(u×v)z]=[uyvzuzvyuzvxuxvzuxvyuyvx]=[0uzuyuz0uxuyux0][vxvyvz]=Uv(2.12)u\times v =\begin{bmatrix} (u\times v)_{x}\\ (u\times v)_{y}\\ (u\times v)_{z} \end{bmatrix}= \begin{bmatrix} u_{y}v_{z}- u_{z}v_{y}\\ u_{z}v_{x}- u_{x}v_{z}\\ u_{x}v_{y}- u_{y}v_{x} \end{bmatrix}= \begin{bmatrix} 0 & -u_{z} & u_{y}\\ u_{z} & 0 & -u_{x}\\ u_{y} & u_{x} & 0 \end{bmatrix}\begin{bmatrix} v_{x}\\ v_{y}\\ v_{z} \end{bmatrix}= Uv\tag{2.12}其中U=[0uzuyuz0uxuyux0](2.13)U= \begin{bmatrix} 0 & -u_{z} & u_{y}\\ u_{z} & 0 & -u_{x}\\ u_{y} & u_{x} & 0 \end{bmatrix}\tag{2.13}
  3. (vu)u(v\cdot u)uu×vu\times v 轉換的矩陣代入式(2.10)得:vrot=cosθv+(1cosθ)(vu)u+sinθu×v=cosθv+(1cosθ)uuTv+sinθKv=(cosθI+(1cosθ)uuT+sinθU)v(2.14)\begin{aligned} v_{rot}&=\cos \theta v+(1-\cos \theta )(v\cdot u)u+ \sin \theta u\times v\\ &=\cos \theta v+(1-\cos \theta )uu^{T}v + \sin \theta K v\\ &=(\cos \theta I +(1-\cos \theta )uu^{T} + \sin \theta U)v \end{aligned}\tag{2.14}故旋轉矩陣R=cosθI+(1cosθ)uuT+sinθU.(2.15)R= \cos \theta I +(1-\cos \theta )uu^{T} + \sin \theta U. \tag{2.15} 其中II爲單位矩陣。

2.2.2 推導二

與推導一相比,推導二的不同主要在於用叉乘去表示一些數據。用叉乘來表示vv_{\perp }v=u×(u×v)(2.16)v_{\perp } =-u\times (u\times v)\tag{2.16}聯立推導一中各式得:
vrot=vrot+vrot=a+b+v=sinθu×v+cosθv+vv=sinθu×vcosθu×(u×v)+v+u×(u×v)=v+(1cosθ)u×(u×v)+sinθu×v=v+(1cosθ)U2v+sinθUv()=(I+(1cosθ)U2+sinθU)v=Rv(2.17)\begin{aligned} v_{rot} &=v_{rot\perp}+v_{rot||}\\ &=a+b+v_{||}\\ &=\sin \theta u\times v +\cos \theta v_{\perp } + v-v_{\perp }\\ &=\sin \theta u\times v -\cos \theta u\times (u\times v) + v + u\times (u\times v)\\ &=v + (1 - \cos \theta )u\times (u\times v) + \sin \theta u\times v \\ &=v + (1 - \cos \theta )U^{2}v+ \sin \theta Uv(叉乘矩陣表示) \\ &=(I + (1 - \cos \theta )U^{2}+ \sin \theta U)v \\ &=Rv \end{aligned}\tag{2.17}
從而得出第二種表達式R=I+(1cosθ)U2+sinθU.(2.18)R= I +(1-\cos \theta )U^{2} + \sin \theta U. \tag{2.18}顯然,第二種表達式更爲簡便,在計算的過程中涉及的參數更少,所以這也是在進行旋轉操作時常用的公式。

2.2.3 推導向量aabb

此處單獨推導羅德里格斯公式的向量aabb,僅做參考,也可以忽略不看。aabb是由vrotv_{rot\perp }正交分解得到的矢量,既有大小又有方向,所以在求解時,我們要對其大小和方向分別求解。
aa大小
θ1=πθ\theta_{1}= \pi -\thetaθ2\theta_{2}是向量vvuu的夾角,uu爲單位向量,則對於aa的大小a|a|有:
a=sinθ1vrot=sinθ1v=sin(πθ)v=sinθv=sinθsinθ2v=sinθsinθ2vu(2.19)\begin{aligned}|a| &=\sin \theta_{1}|v_{rot\perp }|\\ &=\sin \theta_{1}|v_{\perp }| \\ &=\sin (\pi -\theta)|v_{\perp }|\\ &=\sin \theta|v_{\perp }|\\ &=\sin \theta \sin \theta_{2}|v|\\ &=\sin \theta \sin \theta_{2}|v||u| \end{aligned}\tag{2.19}由三角公式a×b=sinθab|a\times b| = \sin \theta |a||b|知:sinθ2vu=u×v\sin \theta_{2}|v||u|=|u \times v|,所以:
a=sinθu×v(2.20)|a|=\sin \theta |u \times v|\tag{2.20}

aa方向
由叉乘方向可得aa的單位方向向量爲:u×v/u×v(2.21)u \times v /|u \times v|\tag{2.21}

綜上可得:
a=(u×v/u×v)a=(u×v/u×v)sinθu×v=sinθu×v(2.22)\begin{aligned} a&=(u \times v /|u \times v|)|a|\\ &=(u \times v /|u \times v|)\sin \theta |u \times v|\\ &=\sin \theta u\times v \end{aligned}\tag{2.22}

bb大小
由圖得,θ1\theta_{1}bbvrotv_{rot\perp }的夾角,則:
b=cosθ1vrot=cos(πθ)v=cosθv(2.23)\begin{aligned} |b| &=\cos \theta_{1}|v_{rot\perp }| \\ &=\cos (\pi -\theta)|v_{\perp }|\\ &= -\cos \theta|v_{\perp }| \end{aligned}\tag{2.23}

bb方向
由於bb的方向與vv_{\perp }方向相反,可得bb的單位方向向量爲:v/v(2.24)-v_{\perp }/|v_{\perp }|\tag{2.24}

綜上可得:
b=(v/v)b=cosθv(2.25)\begin{aligned} b &=(-v_{\perp }/|v_{\perp }|)|b|\\ &=\cos \theta v_{\perp } \end{aligned}\tag{2.25}

至此,羅德里格斯公式的證明全部結束。此外,如果讀者希望獲得關於Oxyz座標系的旋轉變換關係,可以參考這篇博客:圖形變換之旋轉變換公式推導
羅德里格斯公式反應的是旋轉向量到旋轉矩陣的轉換關係,如果已知旋轉矩陣RR,如果推導旋轉向量vv呢?下邊給出旋轉矩陣到旋轉向量的反向轉換關係。

3.旋轉矩陣到向量

這裏計算從一個旋轉矩陣到旋轉向量的轉換。對於旋轉角θ\theta,取旋轉矩陣RR兩邊的跡,有:tr(R)=cosθtr(I)+(1cosθ)tr(uuT)+sinθtr(u)=3cosθ+(1cosθ)=1+2cosθ.(3.1)\begin{aligned} tr(R) &= \cos \theta tr(I)+(1-\cos \theta )tr(uu^{T})+\sin \theta tr(u^{\wedge })\\ &=3\cos \theta + (1- \cos \theta) \\ &=1+2\cos \theta. \tag{3.1} \end{aligned}因此:θ=arccostr(R)12.(3.2)\theta = \arccos \frac{tr(R)-1}{2} .\tag{3.2}關於轉軸uu,旋轉軸上的向量在旋轉後不發生改變,說明:Ru=u.(3.3)Ru=u.\tag{3.3}因此,轉軸uu是矩陣RR特徵值1對應的特徵向量。求解此方程,再歸一化,就得到了旋轉軸uu。由v=θuv=\theta u得到旋轉向量vv

至此,推導結束。實踐部分代碼放到第三部分一起演示。

參考:
1.《視覺SLAM十四講:從理論到實踐》,高翔、張濤等著,中國工信出版社
2. 羅德里格斯公式推導
3. 四元數與三維旋轉

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章