Rotation, combined with translation and scaling, are the three affin transforms we do every day in the 3D nutshell universe. The rotation itself, however, is somehow much more complicated than the other two transform, it is one really needs a matrix representation among all three. Representations and computation of it has been developed for years. We have systems like Axis-angle representation, matrix representation, euler angles and quaternions. Despite I have known them for a long time, when I forgot, the rotation is still complicated. Here I am writing this again, as easily understanding as possible, for my future-self (or I can just travel through time to ask myself now).

in 3D space, we think a rotation is about an axis(in 2D you can also do it, but the axis is out of the space, and yeah, higher dimension is out of my reach, just forget about those). This leads us to the rotation vector representation $(W, \theta)$ where $W$ is the rotating axis, and $\theta$ is the rotating angle. This representation is just for sake of looking. It raise the question like how do you rotate a vector or point with this $\theta$ and the axis algebraly? Well, follow the Rodrigues formula $v_{rot} = \cos\theta v + \sin\theta (w \times v) + (1-\cos\theta) (w \cdot v) w$. Or ease the pain for the head, you can re-represent in Matrix then do the dot product.

Well, but, this matrix form, is confusing when you look at it if it is ever more complex than a 2D transform, so you could dicompose the rotation into 3 2D rotation matrices. Anyway, I feel that we cannot avoid the rotation table here, they are Bruce Banna in different forms of hulk(clear throat).

Name representation N operations on vector combination interpolation
rotation vector $(w,\theta)$ 4 Rodrigues’ rotation impossible hard
Matrix $M$ 9 $M \cdot v$ $M_1 \cdot M_2 \cdot v$ hard
euler angles $(\phi,\theta,\psi)$ 3 $\psi(\theta(\phi(v)))$ cascade hard
quaternions $q=(w,x,y,z)$ 4 $q\cdot v \cdot q^{-1}$ $q_1 q v q^{-1} q_1^{-1}$ slep

Let’s play the role of doctor, dive into the head of rotation and see which causes him to turn into different “hulks”. The rotation matrix is the most common “hulk” we see, green, big and it smashes everyone with its multiplication. But what it really does with its gamma (okay, enough) what the matrix really does is projections, or in other words, changing basis. It is better to see with the example of a extrinsic matrix, if I rotate my camera -45 degrees based around y axis, what we see in the camera is that my object rotate 45 degree around y axis. Reversely, if I want to rotate the object 45 degree around y axis, I can rotate my camera -45 degree around y axis, same for the x and z axis. Then express the change sous la forme de change of basis. Then we re-project this new world with this new camera. Everything worked out fine.

$$ M = \begin{bmatrix} R_x & R_y & R_z & 0 \\ U_x & U_y & U_z & 0 \\ D_x & D_y & D_z & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} $$

rotation matrix rotation vector euler angle quaternions
rotation matrix x decompose solving equations solving equation
rotation vector $RR_{2D}R^{-1}$ x $(w,1/2\theta)$
euler angle $R_p R_y R_r$ x x
quaternions Matrix formula $(w, 1/2\theta)$ x x

So what is the relationship between rotation matrix and rotation vector? Remember that an axis-angle rotation is around an angle? So let us align our normal vector of the image plane of the camera to the rotating axis, this is the same as changing basis, let us call it the basis $R$. Then we use a simple matrix for expressing an 2D rotation $R_{2D}$. Finally after we are done, we need to rotate the camera back using a inverse matrix $R^{-1}$, Parpait!

euler angle{:style=“float: right;”} As much as we love the rotation matrices, it is too heavy for many people. We can paint our world of rotations with only 3 numbers (yaw, pitch, roll). By the name of Euler, the angle is also called euler angle. Euler angle is the The Green Scar whom everyone likes, he waves a hammer and a shield, defeated everyone in the arena, years later, he became the story of legend. Words about him spread among young children’s ears.

Okay, pratically, euler-angle is cascading the transform on different axises. So if we rotate two of the axis so that the third axis became the rotating vector in the angle-rotation representation then we see our old friend in a different suit. Transforming to matrix is as easy as 3-product of 2D transform $R_p R_y R_r$. It is harder to come back from the other end, but you can still do it by solving the matrix

$$ R(\phi) R(\theta) R(\psi) = \\ \begin{bmatrix} \cos \theta \cos \phi & \sin \psi \sin \theta \cos \phi - \cos\psi \sin\phi & \cos\psi \sin\theta \cos\phi + \sin\psi \sin\phi \\ \cos\theta \cos\phi & \sin\psi\sin\theta\sin\phi & \cos\psi\sin\theta\sin\phi - \sin\psi\cos\phi \\ -sin\theta & sin\psi \cos\theta & \cos\psi\cos\theta \end{bmatrix} $$

The last bit of the story of euler angle here, we have to mention the gimbal lock, which is so elegantly designed to cause a dimension drop, a singularity that traps the earth to a 2D plane, no escape, thus brings the end of world (clear the throat). Okay, the gimbal lock lies in the second axis, when you turn 90 degree, you will align the first and the third axis together. Then rotating on first and second axis is to the same axis. Okay, I finished.

The last one of the family, is the Quaternion, he is the “perfect” hulk, with a face and intelligence of Bruce Banner and the strength of the hulk. The only problem is the difficulty to understand. The math of quaternion is skipped here(I am too lazy, maybe one day I will come back to fill it up). We can note done in the mind that $i^2=j^2=k^2=ijk$ and $q=(\cos\frac{1}{2\theta}, n_x\frac{1}{2\theta}, n_y\frac{1}{2\theta}, n_z\frac{1}{2\theta})$ without understand it. It is $\frac{1}{2\theta}$ not $\theta$, why!!! Well, it because $i^2=j^2=k^2=ijk=-1$. So you need to rotate 720 degree to get back to original state, sounds like there are some higher dimensions beneath. In the end, We can also successfully transfer a quaternion into rotation matrix without going though the rotation vector, which makes our lives easier.

comments powered by Disqus