Using rotation matrices to represent the orientation of an object with the Euler angles.
We need to store nine variables.
The nine elements of the rotation matrix.
And every time we need to compose consecutive rotations, we need to multiply two three by three matrices.
And so we need to perform 27 multiplications and 18 sums.
The quaternion is based on the real and imaginary numbers, and in fact it is an extension of it in
the imaginary numbers we call a.
The real part of the number and B the imaginary one.
The quaternion is an extension of this concept and it is composed by four variables.
So four coefficients that here I called A, B, C, and D, where A is the scalar part of the number.
B, C and D are the vector part.
Although this tool is less intuitive than the Euler angles and the rotation matrices to represent the
orientation of an object, since it is not possible to draw in four dimensions, it offers several advantages
that make it more efficient and therefore preferable to Euler angles.
When it's time to express the orientation of an object in computer science.
The first advantage is clear just by looking at the quaternion equation, it is fully described just
by four components.
The four coefficients of the quaternion.
So the variables A, B, C, and D.
One with the Euler angles.
We needed nine components with the quaternion, we only need to store four variables.
Furthermore, the quaternion also offered other properties that make it more efficient when it's time
to manipulate and compose rotations.
The first property is that the quaternion is unitary, namely, the sum of the squares of its coefficients
is equal to one.
The second property is that it is possible to combine two rotations, each of them represented with
a quaternion simply by multiplying the two quaternions.
Also, when we represent the orientation with Euler angles, it was enough to multiply two rotation
matrices to compose two consecutive rotations.
However, in that case we needed to calculate 27 products and 18 sums.
In this case, when we multiply quaternions, we just need to calculate 16 products and nine sums.
Another property of the quaternion is that the calculation of its inverse is extremely simple and actually
is not even a calculation.
It just needs a change of the sign of the vector part of the quaternion.
The inverse of a quaternion also represents the inverse rotation of an object.
And so the rotation that can sell the previous one.
One can do this also with the rotation matrices and calculate the transpose of the matrix to calculate
the inverse rotation.
But of course, transposing a matrix is a far more expensive calculation than simply changing a sign.
Because of these properties and because of its efficient representation.
The quaternion is commonly used in computer science.
However, as humans it is very complex for us to think about the orientation of an object in terms of
quaternion, and instead it's much easier and intuitive to think in terms of Euler angles and rotation
matrices.
In the following laboratory lessons, we are going to use some useful tool that will let us think about
the orientation in terms of Euler angles, and then we will convert this information in quaternion to
be used in Ros2.