四元數球面內插補點公式推導
慣例先廢話 其實去年就推過這個 不過當時忙别的就一直沒寫 前兩天回想起來 發現再推一邊還是費了一些時間 是以決定還是來記錄一下以下正文
還是先說結論
q m = q a ⋅ s i n ( ( 1 − t ) θ ) + q b ⋅ s i n ( t θ ) s i n θ qm = \frac{qa·sin((1-t)\theta)+qb·sin(t\theta)}{sin\theta} qm=sinθqa⋅sin((1−t)θ)+qb⋅sin(tθ)
其中:qm為插值結果
qa為插值起點
qb為插值終點
t為插值步長 取值範圍0~1
θ \theta θ為從qa轉到qb旋轉過的角度的一半
這裡先證明一個引理
假設 q1 , q2 , q 都是四元數,
從 q1 變換到 q2 對應的四元數為 q ,轉過角度的一半為 θ \theta θ
則 q 2 = q 1 ⋅ q q2=q1·q q2=q1⋅q
左右同乘 q1 的逆 q 1 − 1 q1^{-1} q1−1 得
q = q 1 − 1 q 2 q=q1^{-1}q2 q=q1−1q2
因為四元數相等,是以兩四元數的實部(即 ω \omega ω分量)對應相等
令real() 表示取實部操作 則有
real( q 1 − 1 q 2 q1^{-1}q2 q1−1q2) = real(q) = cos θ \theta θ
又因為四元數的逆可以用共轭四元數表達(實部相同虛部相反)
是以可以得到
real( q 1 q 2 − 1 q1q2^{-1} q1q2−1) = real( q 1 − 1 q 2 q1^{-1}q2 q1−1q2) = real(q) = cos θ \theta θ
開始證明
假設 q m = x ⋅ q a + y ⋅ q b qm = x·qa + y·qb qm=x⋅qa+y⋅qb
x,y為常實數
在等式兩邊分别乘以qa和qb的逆 q a − 1 , q b − 1 qa^{-1},qb^{-1} qa−1,qb−1
得到
q a − 1 q m = x + y ⋅ q a − 1 q b qa^{-1}qm=x+y·qa^{-1}qb qa−1qm=x+y⋅qa−1qb
q b − 1 q m = x ⋅ q b − 1 q a + y qb^{-1}qm=x·qb^{-1}qa+y qb−1qm=x⋅qb−1qa+y
令 θ \theta θ為從 qa 轉到 qb 旋轉過的角度的一半
t 為插值步長 取值範圍0~1
則從 qa 到 qm 轉過的角度的一半為 t θ t\theta tθ
則從 qm 到 qb 轉過的角度的一半為 ( 1 − t ) θ (1-t)\theta (1−t)θ
将上文兩等式左右同時取實部 得
r e a l ( q a − 1 q m ) = x + y ⋅ r e a l ( q a − 1 q b ) real(qa^{-1}qm)=x+y·real(qa^{-1}qb) real(qa−1qm)=x+y⋅real(qa−1qb)
r e a l ( q b − 1 q m ) = x ⋅ r e a l ( q b − 1 q a ) + y real(qb^{-1}qm)=x·real(qb^{-1}qa)+y real(qb−1qm)=x⋅real(qb−1qa)+y
帶入引理結論 得
c o s ( t θ ) = x + y c o s θ cos(t\theta)=x+ycos\theta cos(tθ)=x+ycosθ
c o s ( ( 1 − t ) θ ) = x c o s θ + y cos((1-t)\theta)=xcos\theta+y cos((1−t)θ)=xcosθ+y
聯立兩等式得出
x = c o s ( t θ ) − c o s θ cos ( 1 − t ) θ s i n 2 θ x=\frac{cos(t\theta)-cos\theta\cos(1-t)\theta}{sin^{2}\theta} x=sin2θcos(tθ)−cosθcos(1−t)θ
y = c o s ( 1 − t ) θ − c o s θ cos ( t θ ) s i n 2 y=\frac{cos(1-t)\theta-cos\theta\cos(t\theta)}{sin^{2}} y=sin2cos(1−t)θ−cosθcos(tθ)
根據和差化積公式化簡後得到結論
x = s i n ( ( 1 − t ) θ ) s i n θ x= \frac{sin((1-t)\theta)}{sin\theta} x=sinθsin((1−t)θ)
y = s i n ( t θ ) s i n θ y= \frac{sin(t\theta)}{sin\theta} y=sinθsin(tθ)
即
q m = q a ⋅ s i n ( ( 1 − t ) θ ) + q b ⋅ s i n ( t θ ) s i n θ qm = \frac{qa·sin((1-t)\theta)+qb·sin(t\theta)}{sin\theta} qm=sinθqa⋅sin((1−t)θ)+qb⋅sin(tθ)
參考連結http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
碼公式累死人 轉載請注明出處 謝謝~