Difference between revisions of "Rotations using quaternions"

From Robotics
Jump to: navigation, search
(Mathematical solving of a quaternion rotation)
(Mathematical solving of a quaternion rotation)
Line 42: Line 42:
  
 
===Mathematical solving of a quaternion rotation===
 
===Mathematical solving of a quaternion rotation===
Assume a quaternion <math>e(\vec{\mathbf{u}},\phi)</math> describing a rotation and a vector <math>\vec{\mathbf{r}}</math> that should be rotated. The result of this rotation will be <math>\vec{\mathbf{r}}'</math>.
+
Assume a quaternion <math>e(\vec{\mathbf{u}},\phi)</math> describing a rotation and a vector <math>\vec{\mathbf{r}}</math> that should be rotated. To be able to apply the rotation, <math>\vec{\mathbf{r}}</math> has to be presented as a quaternion. So the [[Pure and unit quaternions|pure quaternion]] <math>r</math> is defined with scalar part equal to 0 and <math>\vec{\mathbf{r}}</math> as vector part:
 +
:<math>
 +
r = 0 \oplus \vec{\mathbf{r}}
 +
</math>
 +
The same is done for the resulting vector <math>\vec{\mathbf{r}}'</math> of the rotation:
 +
:<math>
 +
r' = 0 \oplus \vec{\mathbf{r}}'
 +
</math>
  
 
===Applet===
 
===Applet===

Revision as of 16:05, 8 September 2015

← Back: Multiplication of quaternions Overview: Quaternions Next: Realization of transformations
Quaternion-rpy.png

Usually rotations are defined by 3 angles, either Euler or Roll-Pitch-Yaw angles. So three successive rotations around three different axes lead to a combined rotation, that can be described by a single rotation matrix. Such a combined rotation is equal to a rotation around a certain axis in three-dimensional space about a certain angle. This is shown in the figure on the right. The vector \vec{\mathbf{r}} is rotated such that it results in \vec{\mathbf{r}}'. This could be done by rotating the vector around the z-, the y- and the x-axis successively or by just rotating it around the rotation axis \vec{\mathbf{u}} by \phi.

Mathematical description

First the rotation axis \vec{\mathbf{u}} has to be defined by a unit vector. So it holds:


|\vec{\mathbf{u}}|= \sqrt{u_x^2+u_y^2+u_z^2} = 1 \qquad \Rightarrow \qquad {u_x^2+u_y^2+u_z^2} = 1

Then a rotation about \vec{\mathbf{u}} by the angle \phi can be represented by a quaternion e like follows:


\begin{align}
e(\vec{\mathbf{u}},\phi) 
&= e_0 + \vec{\mathbf{e}} \\
&= e_0+e_1i+e_2j+e_3k \\
&= \cos{\frac{\phi}{2}} + \sin{\frac{\phi}{2}}\vec{\mathbf{u}} \\
&= \cos{\frac{\phi}{2}} + \sin{\frac{\phi}{2}}(u_xi+u_yj+u_zk) \\
&= \cos{\frac{\phi}{2}} + \sin{\frac{\phi}{2}}u_xi + \sin{\frac{\phi}{2}}u_yj + \sin{\frac{\phi}{2}}u_zk
\end{align}

So the scalar part e_0 is defined as the cosine of \frac{\phi}{2} and the vector part consisting of e_1, e_2 and e_3 equals \vec{\mathbf{u}} multiplied by the sine of \frac{\phi}{2}.

That the resulting quaternion e is a unit quaternion can be proven as follows:


\begin{align}
|e| &= \sqrt{e_0^2+e_1^2+e_2^2+e_3^2} \\
 &= \sqrt{\cos^2{\frac{\phi}{2}} + \sin^2{\frac{\phi}{2}}u_x^2 + \sin^2{\frac{\phi}{2}}u_y^2 + \sin^2{\frac{\phi}{2}}u_z^2 } \\
 &= \sqrt{\cos^2{\frac{\phi}{2}} + \sin^2{\frac{\phi}{2}}\cdot(u_x^2 + u_y^2 + u_z^2)} \\
 &= \sqrt{\cos^2{\frac{\phi}{2}} + \sin^2{\frac{\phi}{2}}\cdot1}  = \sqrt{\cos^2{\frac{\phi}{2}} + \sin^2{\frac{\phi}{2}}} = \sqrt{1} = 1
\end{align}

So if a quaternion e=(e_0,e_1,e_2,e_3) is given, the angle \phi and the rotation axis \vec{\mathbf{u}} can be computed as follows:


\begin{align}
\phi &= 2\cdot \arccos e_0 \\
\vec{\mathbf{u}} &= \frac{1}{\sin{\frac{\phi}{2}}}\left[\begin{array}{c}e_1\\e_2\\e_3\end{array}\right]
\end{align}

Mathematical solving of a quaternion rotation

Assume a quaternion e(\vec{\mathbf{u}},\phi) describing a rotation and a vector \vec{\mathbf{r}} that should be rotated. To be able to apply the rotation, \vec{\mathbf{r}} has to be presented as a quaternion. So the pure quaternion r is defined with scalar part equal to 0 and \vec{\mathbf{r}} as vector part:


r = 0 \oplus \vec{\mathbf{r}}

The same is done for the resulting vector \vec{\mathbf{r}}' of the rotation:


r' = 0 \oplus \vec{\mathbf{r}}'

Applet

The following three-dimensional applet helps you to understand the relation between Roll-Pitch-Yaw angles and a quaternion. The initial position of the object can be set using the sliders for x, y and z. Then the object can be rotated by defining the roll, pitch and yaw angles. The most intuitive way is to start with the yaw angle, because this one is applied first. Then the object is rotated aroud the y-axis by the pitch angle followed by a rotation around the x-axis by the roll angle. The quaternion describing the same rotation is shown dynamically and the corresponding angle \alpha and the rotation axis \vec{\mathbf{u}} are presented. The rotation axis and the rotational path are visualized on the left side. After pressing the Show Quaternion Rotation button, the rotation of the object around \vec{\mathbf{u}} gets animated.