banner
IWSR

IWSR

我永远喜欢志喜屋梦子!

Euler angles and gimbal lock

Explanation#

  • Pre-reading: Matrix derivation of basic geometric transformations in 3D graphics
  • In a reference frame in 3D space, the orientation of any coordinate system can be represented using three Euler angles. (The three Euler angle transformations can describe the pose of the current object.)
  • It is sufficient to have a basic understanding of pitch (rotation around the z-axis), yaw (rotation around the y-axis), and roll (rotation around the x-axis).
  • Since linear transformations do not follow the commutative property, the order of rotations will affect the result. The following analysis uses the dynamic Euler angle sequence (z-y-x).

Dynamic Euler Angles#

In Matrix derivation of basic geometric transformations in 3D graphics, the rotation matrices for rotating around the X, Y, and Z axes are derived as follows:

Rzγ=(cosγsinγ00sinγcosγ0000100001)R_{z}γ = \begin{pmatrix} cosγ & -sinγ & 0 & 0 \\ sinγ & cosγ & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}
Ryβ=(cosβ0sinβ00100sinβ0cosβ00001)R_{y}β = \begin{pmatrix} cosβ & 0 & sinβ & 0 \\ 0 & 1 & 0 & 0 \\ -sinβ & 0 & cosβ & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}
Rxα=(10000cosαsinα00sinαcosα00001)R_{x}α = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & cosα & -sinα & 0 \\ 0 & sinα & cosα & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}

Therefore, if we follow the dynamic Euler angle transformation sequence, we obtain the transformation matrix R=RxαRyβRzγR=R_{x}αR_{y}βR_{z}γ

R=RxαRyβRzγ=(cosβcosγcosαsinγ+sinαsinβcosγsinαsinγ+cosαsinβcosγ0cosβsinγcosαcosγ+sinαsinβsinγsinαcosγ+cosαsinβsinγ0sinβsinαcosβcosαcosβ00001)R= R_{x}αR_{y}βR_{z}γ = \begin{pmatrix} \cos β\cos γ & -\cos α\sin γ + \sin α\sin β\cos γ & \sin α \sin γ+ \cos α \sin β \cos γ & 0 \\ \cos β\sin γ & \cos α\cos γ + \sin α\sin β\sin γ & -\sin α \cos γ+ \cos α \sin β \sin γ & 0 \\ -\sin β & \sin α\cos β & \cos α\cos β & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}

Gimbal Lock#

Once ±90° is chosen as the pitch angle, the first and third rotations become equivalent, and the entire rotation representation system is limited to rotation around the vertical axis, losing one degree of freedom.

In simpler terms, when β is ±90°, rotating around the x-axis and rotating around the z-axis will have equivalent results.

If we directly explain the gimbal lock problem using the transformation matrix R, it becomes intuitive. For example, if we substitute β = 90° into the equation and simplify:

R=RxαRy90°Rzγ=(10000cosαsinα00sinαcosα00001)(0010010010000001)(cosγsinγ00sinγcosγ0000100001)=(0010sin(α+γ)cos(α+γ)00cos(α+γ)sin(α+γ)000001)R = R_{x}αR_{y}90°R_{z}γ = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & cosα & -sinα & 0 \\ 0 & sinα & cosα & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ -1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} cosγ & -sinγ & 0 & 0 \\ sinγ & cosγ & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix} = \begin{pmatrix} 0 & 0 & 1 & 0 \\ sin(α + γ) & cos(α + γ) & 0 & 0 \\ -cos(α + γ) & sin(α + γ) & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}

It is easy to see that the variable affecting the transformation matrix R is α + γ, which geometrically represents the equivalence between rotation around the x-axis and rotation around the z-axis. For example:

Rx30°Ry90°Rz50°=Rx0°Ry90°Rz80°R_{x}30°R_{y}90°R_{z}50° = R_{x}0°R_{y}90°R_{z}80°

It is important to emphasize that the rotation sequence in this article is z-y-x. The example above describes an object rotating 80° around the z-axis, 90° around the y-axis, and 0° around the x-axis, which is equivalent to rotating 80° around the z-axis, 90° around the y-axis, and 0° around the x-axis. In other words, when gimbal lock occurs, an object in space can be transformed into a specific pose through multiple different rotation methods, and the transformation does not have a one-to-one correspondence with the result. This is reflected in engineering as extremely strange animation interpolation.

Dec-05-2022 17-25-40
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.