从数学角度理解欧拉旋转中的万向节死锁

欧拉旋转

姿态角pitch/roll/yaw

​ 姿态角是飞行器的机体坐标系与地面坐标系的夹角,也叫欧拉角。其中,

pitch是俯仰角,yaw是偏航角,roll是滚转角。

image-20201130164214454

​ 欧拉角最直观、最容易理解、存储空间少,但欧拉角存在万向节死锁现象、插值速度不均匀等缺点,而且不可以在计算机中直接运算。

image-20201130211651758

设xyz-轴为参考系的参考轴,也成为固定轴,XYZ-轴称为动轴,xy-平面和XY-平面的相交为交点线,用字母N表示。则章动角θ=β是z轴与Z轴的夹角,进动角ψ=α是x轴与交点线的夹角,自转角j=γ是交点线与X轴的夹角。上述旋转方式采用zxz的顺规方式旋转得到,即:

1. 绕z轴旋转α,使x轴与N轴重合,N轴是旋转前后两个坐标系x-y平面的交线
2. 绕x轴(也就是N轴)旋转β,使z轴与旋转后的z轴重合
3. 绕z轴旋转γ,使坐标系与旋转后的完全重合

欧拉角的旋转方式总共有12种:

  • 非对称型欧拉角: XYZ,XZY,YXZ,YZX,ZXY,ZYX
  • 对称型欧拉角: XYX,XZX,YXY,YZY,ZXZ,ZYZ

每一种旋转方式得到的结果并不一样,比如先绕X轴旋转45°再分别绕Y轴和Z轴旋转45°与先绕Y轴再绕X轴和Z轴旋转得到的结果是不一致的,由此可见旋转顺序的重要性。

在数学公式表达中,需要用矩阵相乘来表示旋转,乘以矩阵的顺序不同意味着旋转方式的不同,其结果也是不一样的。以二维旋转为例:

image-20201208155755750

​ 设x点的坐标为(x0,y0),旋转后的坐标为(x1,y1),旋转角度为θ,则以矩阵表示为
[ x 1 y 1 ] = [ c o s θ − s i n θ s i n θ c o s θ ] [ x 0 y 0 ] \left[ \begin{matrix} x1 \\ y1 \end{matrix} \right] =\left[ \begin{matrix} cos\theta & -sin\theta \\ sin\theta & cos\theta \end{matrix} \right] \left[ \begin{matrix} x0 \\ y0 \end{matrix} \right] [x1y1]=[cosθsinθsinθcosθ][x0y0]
​ 在三维旋转中,可以分解为先绕x轴旋转,再绕y轴旋转,之后绕z轴旋转,则通过矩阵可表示为
[ x 1 y 1 z 1 ] = [ c o s α − s i n α 0 s i n α c o s α 0 0 0 1 ] [ c o s β 0 − s i n β 0 1 0 s i n β 0 c o s β ] [ 1 0 0 0 c o s θ − s i n θ 0 s i n θ c o s θ ] [ x 0 y 0 z 0 ] \left[ \begin{matrix} x1 \\ y1 \\ z1 \end{matrix} \right]= \left[ \begin{matrix} cos\alpha & -sin\alpha & 0 \\ sin\alpha & cos\alpha & 0 \\ 0 & 0 & 1 \end{matrix} \right] \left[ \begin{matrix} cos\beta & 0 & -sin\beta \\ 0 & 1 & 0 \\ sin\beta & 0 & cos\beta \end{matrix} \right] \left[ \begin{matrix} 1 & 0 & 0 \\ 0 & cos\theta & -sin\theta \\ 0 & sin\theta & cos\theta \end{matrix} \right] \left[ \begin{matrix} x0 \\ y0 \\ z0 \end{matrix} \right] x1y1z1=cosαsinα0sinαcosα0001cosβ0sinβ010sinβ0cosβ1000cosθsinθ0sinθcosθx0y0z0
​ 通过上述矩阵可以看出,用[x0 y0 z0]代表一个向量的前提是定义了相应的坐标系,即X轴、Y轴和Z轴已经确定,不会因为旋转的发生而导致整个坐标轴发生形变。对于旋转矩阵ZYX,其顺序是先基于X轴旋转再进行Y轴和Z轴的旋转。

image-20201208164108589

​ 以万向节死锁演示视频的截图为例进行说明:蓝圈表示绕x轴旋转,红圈表示绕y轴旋转,绿圈表示绕z轴旋转,由于绿圈的旋转会导致红圈和蓝圈的方向变化,红圈的旋转会导致蓝圈的方向变化,所以可以看到,要满足矩阵公式,即坐标轴的方向不发生改变,则其旋转的顺序必须是先转动蓝圈,再转动红圈,最后转动绿圈。即该模型的旋转顺序(即顺规)是蓝红绿(XYZ)。

​ 如果换个旋转顺序——先转绿圈45°再转红圈45°最后转蓝圈45°,这和先转动蓝圈45°再转动红圈45°最后转动绿圈45°的结果是一样的吗?答案是肯定的,只要保证转动角度一致,最后产生的效果都是一样的。那为什么要规定转动的顺序呢?因为此处大家已经陷入了转动顺序的陷阱了。为什么会有这个矛盾,其实是陷入了欧拉旋转中重要的一个概念的误解,这就是顺规

顺规

首先讨论顺规存在的必要性,顺规从数学意义上来讲就是对矩阵顺序的规定,具体讨论如下:
[ x 1 y 1 z 1 ] = [ c o s α − s i n α 0 s i n α c o s α 0 0 0 1 ] [ c o s β 0 − s i n β 0 1 0 s i n β 0 c o s β ] [ 1 0 0 0 c o s θ − s i n θ 0 s i n θ c o s θ ] [ x 0 y 0 z 0 ] \left[ \begin{matrix} x1 \\ y1 \\ z1 \end{matrix} \right]= \left[ \begin{matrix} cos\alpha & -sin\alpha & 0 \\ sin\alpha & cos\alpha & 0 \\ 0 & 0 & 1 \end{matrix} \right] \left[ \begin{matrix} cos\beta & 0 & -sin\beta \\ 0 & 1 & 0 \\ sin\beta & 0 & cos\beta \end{matrix} \right] \left[ \begin{matrix} 1 & 0 & 0 \\ 0 & cos\theta & -sin\theta \\ 0 & sin\theta & cos\theta \end{matrix} \right] \left[ \begin{matrix} x0 \\ y0 \\ z0 \end{matrix} \right] x1y1z1=cosαsinα0sinαcosα0001cosβ0sinβ010sinβ0cosβ1000cosθsinθ0sinθcosθx0y0z0

[ x 1 y 1 z 1 ] = [ c o s β 0 − s i n β 0 1 0 s i n β 0 c o s β ] [ c o s α − s i n α 0 s i n α c o s α 0 0 0 1 ] [ 1 0 0 0 c o s θ − s i n θ 0 s i n θ c o s θ ] [ x 0 y 0 z 0 ] \left[ \begin{matrix} x1 \\ y1 \\ z1 \end{matrix} \right]= \left[ \begin{matrix} cos\beta & 0 & -sin\beta \\ 0 & 1 & 0 \\ sin\beta & 0 & cos\beta \end{matrix} \right] \left[ \begin{matrix} cos\alpha & -sin\alpha & 0 \\ sin\alpha & cos\alpha & 0 \\ 0 & 0 & 1 \end{matrix} \right] \left[ \begin{matrix} 1 & 0 & 0 \\ 0 & cos\theta & -sin\theta \\ 0 & sin\theta & cos\theta \end{matrix} \right] \left[ \begin{matrix} x0 \\ y0 \\ z0 \end{matrix} \right] x1y1z1=cosβ0sinβ010sinβ0cosβcosαsinα0sinαcosα00011000cosθsinθ0sinθcosθx0y0z0

​ 可以看到,矩阵的顺序不一样会导致最终的旋转结果不一致,不妨以一支笔为向量比划一下,假设向量为[1,0,0],则向量先绕y轴旋转90°到z轴,再绕x轴旋转30°,和先绕x轴旋转30°再绕y轴旋转90°,其结果是不一样的。如果空间思维能力差的可以参考欧拉角的旋转顺序能改变吗?中的几个gif动图。

​ 从数学角度上分析,确实旋转的顺序相当重要,但为什么上图中会有旋转顺序不一致结果却一样呢?这就跳回到我们前边要注意的细节,首先旋转过程中,我们必须保证第二次旋转轴不会因为第一个的旋转而发生偏转(第三次旋转同理)。即,第一次绕x轴旋转后,y轴和z轴的方向是没有发生任何变化的,这是对矩阵最直观的理解。

​ 从演示视频和模型来看,如果我们先转动红圈,其实蓝圈的轴心已经发生了偏转,即我们不能认为红圈先动就先乘以第二个矩阵。换言之,在数学上,哪个矩阵先乘在该模型中不等于哪个圈先转动,而必须遵循一个准则——先转动的圈不能影响还没转动的圈的轴心方向。所以实际上,该模型的顺规其实是已经确定了,即xyz顺序。那如何理解先转动红圈对应的数学模型呢?

​ 重新声明一点,通过矩阵运算可以得到,右边的矩阵运算后是对左边的矩阵不产生影响的,而左边的矩阵运算是会对右边的矩阵有一定的影响作用。我们可以通过空间想象得知,由于左边的矩阵会导致右边的矩阵原定旋转方向产生一定的偏转,相当于代入我们已知β的值,实际上就已经产生了对前一个矩阵旋转轴和整个向量的偏转,即红圈对蓝圈产生了影响,蓝圈也发生偏转了!

万向节死锁

​ 万向节死锁是欧拉旋转中顺规存在导致的必然缺陷,其本质就是欧拉旋转过程中出现了维度丢失的情况。无论是哪种顺规的欧拉旋转,总是会存在这种情况。比如zxz,但x旋转180°时,前后两次围绕z轴的旋转只产生了一个维度上的旋转,此时zxz的旋转只能产生两个维度的转动,即滚转角和俯仰角,偏转角丢失了。

​ 万向节死锁的关键原因在于顺规的存在——由于有了绕轴转动的顺序问题,导致对于绕顺序为第二的轴转动90°会导致其他两个轴上的运动方向重合,从而导致了原本三维的旋转运动少了一个维度,进而导致在某种特定的情况下不能按照预期的路线进行绕轴运动,具体过程可参考万向节死锁演示视频。详细的解释可参考【Unity编程】Unity中的欧拉旋转【Unity编程】欧拉角与万向节死锁(图文版)。其解释仅供参考,我们还可以通过万向节死锁模拟程序Unity动手实践演示。

​ Unity中的顺规是zxy,即绕z轴的转动不影响x和y轴,绕x轴的转动不影响y轴但影响z轴,绕y轴的转动直接影响x和z轴,所以当先对x轴产生一个90°的旋转时,y轴和z轴都产生了同样的翻滚角效果,无法产生偏转角(x轴产生的是俯仰角的变化)。

​ 万向节死锁的模型演示已经在上述视频和其他文章中描述的比较清晰,以下我们只从数学角度上理解。
[ x 1 y 1 z 1 ] = [ c o s α − s i n α 0 s i n α c o s α 0 0 0 1 ] [ c o s β 0 − s i n β 0 1 0 s i n β 0 c o s β ] [ 1 0 0 0 c o s θ − s i n θ 0 s i n θ c o s θ ] [ x 0 y 0 z 0 ] \left[ \begin{matrix} x1 \\ y1 \\ z1 \end{matrix} \right]= \left[ \begin{matrix} cos\alpha & -sin\alpha & 0 \\ sin\alpha & cos\alpha & 0 \\ 0 & 0 & 1 \end{matrix} \right] \left[ \begin{matrix} cos\beta & 0 & -sin\beta \\ 0 & 1 & 0 \\ sin\beta & 0 & cos\beta \end{matrix} \right] \left[ \begin{matrix} 1 & 0 & 0 \\ 0 & cos\theta & -sin\theta \\ 0 & sin\theta & cos\theta \end{matrix} \right] \left[ \begin{matrix} x0 \\ y0 \\ z0 \end{matrix} \right] x1y1z1=cosαsinα0sinαcosα0001cosβ0sinβ010sinβ0cosβ1000cosθsinθ0sinθcosθx0y0z0

= [ c o s α c o s β − s i n α c o s θ − c o s α s i n β s i n θ s i n α s i n θ − c o s α s i n β c o s θ s i n α c o s β c o s α c o s θ − s i n α s i n β s i n θ − c o s α s i n θ − s i n α s i n β c o s θ s i n β c o s β s i n θ c o s β c o s θ ] [ x 0 y 0 z 0 ] = \left[ \begin{matrix} cos\alpha cos\beta & -sin\alpha cos\theta-cos\alpha sin\beta sin\theta & sin\alpha sin\theta-cos\alpha sin\beta cos\theta \\ sin\alpha cos\beta & cos\alpha cos\theta-sin\alpha sin\beta sin\theta & -cos\alpha sin\theta-sin\alpha sin\beta cos\theta \\ sin\beta & cos\beta sin\theta & cos\beta cos\theta \end{matrix} \right] \left[ \begin{matrix} x0 \\ y0 \\ z0 \end{matrix} \right] =cosαcosβsinαcosβsinβsinαcosθcosαsinβsinθcosαcosθsinαsinβsinθcosβsinθsinαsinθcosαsinβcosθcosαsinθsinαsinβcosθcosβcosθx0y0z0

当β=pi/2时,sinβ=1,cosβ=0,故

[ x 1 y 1 z 1 ] = [ 0 − s i n ( θ + α ) − c o s ( θ + α ) 0 c o s ( θ + α ) − s i n ( θ + α ) 1 0 0 ] [ x 0 y 0 z 0 ] \left[ \begin{matrix} x1 \\ y1 \\ z1 \end{matrix} \right]= \left[ \begin{matrix} 0 & -sin(\theta+\alpha) & -cos(\theta+\alpha) \\ 0 & cos(\theta+\alpha) & -sin(\theta+\alpha) \\ 1 & 0 & 0 \end{matrix} \right] \left[ \begin{matrix} x0 \\ y0 \\ z0 \end{matrix} \right] x1y1z1=001sin(θ+α)cos(θ+α)0cos(θ+α)sin(θ+α)0x0y0z0
​ 此时可以看到θ和α的变化都产生了相同的效果,即产生的都是绕z轴的旋转(正常情况下α和θ对应的矩阵是正交的),而原本θ角产生的旋转维度丢失了,不能产生偏转角。实际上对于不同的向量,会有不同的锁定效果,如当[x0 y0 z0]=[1 0 0]时,不能产生偏转角,当[x0 y0 z0]=[0 0 1]时,不能产生滚转角等。归结为:万向节死锁产生的是在某个特殊状态下某种特定运动不能发生,如无法发生偏转,无法发生翻滚或者无法发生俯仰,或者无法发生上述运动的某个结合运动,具体取决于向量的初始状态。

​ 丢失旋转维度产生的最大问题在视频中也有详细的演示,即向量不能朝某一个特定的方向进行最短路径旋转,而需要绕弧线产生一定的旋转,为什么会这样?直观上看就是因为丢失了一个维度导致在这个维度上呈现出锁死的状态,需要先解除这个特殊状态才能转到我们需要的姿态角上。

​ 以下从微分学的角度来分析为什么在这个状态下不能产生特定维度的旋转。

​ 我们以[x0 y0 z0]=[1 0 0]为例,首先我们将x、y、z看成是自变量为α、β和θ的函数。即
x = x 0 ∗ c o s β c o s α + y 0 ∗ ( − s i n α c o s θ − c o s α s i n β s i n θ ) + z 0 ∗ ( s i n α s i n θ − c o s α s i n β c o s θ ) y = x 0 ∗ s i n α c o s β + y 0 ∗ ( c o s α c o s θ − s i n α s i n β s i n θ ) + z 0 ∗ ( − c o s α s i n θ − s i n α s i n β c o s θ ) z = x 0 ∗ ( s i n β ) + y 0 ∗ c o s β s i n θ + z 0 ∗ c o s β c o s θ x=x_0*cos\beta cos\alpha + y_0*(-sin\alpha cos\theta-cos\alpha sin\beta sin\theta) + z_0*(sin\alpha sin\theta-cos\alpha sin\beta cos\theta) \\ y=x_0*sin\alpha cos\beta +y_0*(cos\alpha cos\theta-sin\alpha sin\beta sin\theta)+z_0*(-cos\alpha sin\theta-sin\alpha sin\beta cos\theta) \\ z=x_0*(sin\beta)+y_0*cos\beta sin\theta+z_0*cos\beta cos\theta x=x0cosβcosα+y0(sinαcosθcosαsinβsinθ)+z0(sinαsinθcosαsinβcosθ)y=x0sinαcosβ+y0(cosαcosθsinαsinβsinθ)+z0(cosαsinθsinαsinβcosθ)z=x0(sinβ)+y0cosβsinθ+z0cosβcosθ
分别求出x、y和z在α=0、β=pi/2和θ=0时的偏导数,得到
∂ x ∂ α = y 0 , ∂ x ∂ β = − x 0 , ∂ x ∂ θ = y 0 ∂ y ∂ α = z 0 , ∂ y ∂ β = 0 , ∂ y ∂ θ = z 0 ∂ z ∂ α = 0 , ∂ z ∂ β = − z 0 , ∂ z ∂ θ = 0 \frac{\partial x}{\partial \alpha} = y_0, \frac{\partial x}{\partial \beta} = -x_0, \frac{\partial x}{\partial \theta} = y_0\\ \frac{\partial y}{\partial \alpha} = z_0, \frac{\partial y}{\partial \beta} = 0, \frac{\partial y}{\partial \theta} = z_0\\ \frac{\partial z}{\partial \alpha} = 0, \frac{\partial z}{\partial \beta} = -z_0, \frac{\partial z}{\partial \theta} = 0 αx=y0,βx=x0,θx=y0αy=z0,βy=0,θy=z0αz=0,βz=z0,θz=0

d x = ∂ x ∂ α d α + ∂ x ∂ β d β + ∂ x ∂ θ d θ = y 0 ( d α − d θ ) − x 0 d β d y = ∂ y ∂ α d α + ∂ y ∂ β d β + ∂ y ∂ θ d θ = z o ( d θ − d α ) d z = ∂ z ∂ α d α + ∂ z ∂ β d β + ∂ z ∂ θ d θ = − z 0 d β dx = \frac{\partial x}{\partial \alpha}d\alpha+\frac{\partial x}{\partial \beta}d\beta+\frac{\partial x}{\partial \theta}d\theta=y_0(d\alpha-d\theta)-x_0d\beta \\ dy = \frac{\partial y}{\partial \alpha}d\alpha+\frac{\partial y}{\partial \beta}d\beta+\frac{\partial y}{\partial \theta}d\theta=z_o(d\theta-d\alpha) \\ dz = \frac{\partial z}{\partial \alpha}d\alpha+\frac{\partial z}{\partial \beta}d\beta+\frac{\partial z}{\partial \theta}d\theta=-z_0d\beta \\ dx=αxdα+βxdβ+θxdθ=y0(dαdθ)x0dβdy=αydα+βydβ+θydθ=zo(dθdα)dz=αzdα+βzdβ+θzdθ=z0dβ
则可以得到,当z0≠0时,
− z 0 ∗ d x + y 0 ∗ d y + x 0 ∗ d z = 0 -z_0*dx+y_0*dy+x_0*dz=0 z0dx+y0dy+x0dz=0
此时,向量的变化是沿着与旋转后的向量垂直的平面变化的。

当z0=0时,
d x = y 0 ( d α − d θ ) − x 0 d β ≠ 0 , d y = 0 , d z = 0 dx=y_0(d\alpha-d\theta)-x_0d\beta≠0,dy=0,dz=0 dx=y0(dαdθ)x0dβ=0,dy=0,dz=0

可以看到对于[1 0 0]
d x = − x 0 d β , d y = 0 , d z = 0 dx=-x_0d\beta,dy=0,dz=0 dx=x0dβ,dy=0,dz=0
​ 只能沿x轴方向发生变化,此变化是由β角的转动产生的**(α和θ产生的是滚转角,xyz坐标系无法体现出滚转角的变化)**,而dy和dz的变化始终为0,则可以看出,沿着Y轴与Z轴所在平面的偏转是不能实现的,这与视频中的死锁现象是一致的。

对于[0 0 1]
− d x = 0 -dx=0 dx=0
​ 得到x=z0=1,即可以沿着x=1的平面进行任意角度的偏移,只要控制好α、β和θ的旋转度即可,但实际上,[0 0 1]丢失了滚转角,只是滚转角无法从xyz坐标系上表示出来罢了。

总而言之,欧拉旋转由于其固有缺陷总是会出现万向节死锁的情况,即丢失某一个特定维度的变化,这个维度可以是纯翻滚或者纯偏航等,也可以是某个角度的翻滚和某个角度的偏航的特定结合,具体取决于向量的初始状态,实际上用向量表示欧拉旋转并不合适,因为向量不存在滚转角,但向量可以表示出偏航和俯仰两种变化,故可以轻易通过向量推出俯仰或偏航锁定的情况。现实中应将向量想象为视频中的飞机,简化为带滚转角的向量。

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值