2
$\begingroup$

I am trying to use a quaternions for robotics and there is one thing I don't understand about it. Most likely because I don't understand how to define position with quaternions and how to define rotation with quaternions if there is any difference..
Please watch my "understanding steps" and correct if I am wrong somewhere.

Lets assume I we have 2 vehicle positions described by 2 rotation quaternions: $$ q_1 = w_1 + x_1i + y_1j +z_1k = \cos(\pi/4) + \sin(\pi/4)i $$ This quaternion is normalized and represents rotation over the $x$ axis for $\pi/2$ angle as I understand it. $$ q_2 = w_2 + x_2i + y_2j + z_2k = \cos(\pi/4) + \sin(\pi/4)k $$ And this one represents rotation for the same angle $\pi/2$ over the $y$ axis.

$q_1*q_2 = q_3$ which would be the same rotation as if we made $q_1$ first and $q_2$ second. $$q_3 = \frac{1}{2} + \frac{i}{2} +\frac{j}{2} +\frac{k}{2}$$

QUESTION 1: Given $q_2$ and $q_3$ how can I find $q_1$?

QUESTION 2: How to find a rotation angle over some other vector, given rotation quaternion? For example I want to find on what angle does $q_3$ turned over $2i+j-k$ quaternion.

$\endgroup$
5
  • $\begingroup$ Your question is a bit unclear. Are you representing both position and rotation in a single quaternion? Are you trying to find the angular displacement between 2 given rotations? Are you simply rotating a quaternions? I think you should do some more background reading. $\endgroup$
    – Ben
    Commented Mar 2, 2016 at 0:29
  • $\begingroup$ @RyanLoggerythm Quaternion is not a hyperspace representation of both position and rotation. That would be double quaternions. Quaternions simply represents rotations and covers the entire $SO(3)$ space. It has nothing to do with position. $\endgroup$
    – Marvin
    Commented Mar 18, 2016 at 21:26
  • $\begingroup$ Yes I had checked the link. I meant that the quaternions do not have anything to do with position. Am I wrong in that regard? $\endgroup$
    – Marvin
    Commented Mar 20, 2016 at 8:20
  • $\begingroup$ Look at this code. github.com/tswanepoel/pilotgadgetry/blob/master/README.md $\endgroup$
    – Biscuits
    Commented Apr 8, 2016 at 18:53
  • $\begingroup$ @RyanLoggerythm - I agree with Saurav; quaternions don't have anything to do with the position of the object to be rotated. Yes, there is technically an i/j/k or x/y/z component to the quaternion, but that is better described as the axis about which the rotation occurs (axis-angle). What you're saying is akin to saying that a ruler in my pocket represents position - technically correct but misleading because, while it measures a position, it doesn't measure my position. $\endgroup$
    – Chuck
    Commented Apr 19, 2016 at 12:26

2 Answers 2

0
$\begingroup$

Quaternions

Mathematical definition

$\mathcal{H} := \{ h_{1} + h_{2}i + h_{3}j + h_{4}k : h_{1},h_{2},h_{3},h_{4} \in \Re$ and $ i^{2} = j^{2} = k^{2} = ijk = -1 \}$

A pure quaternion can be defined as:

$\mathcal{H}_{p} := \{ p \in \mathcal{H} : Re(p)=0\}$

Pure quaternions can be associated to vectors.

Translation

Since pure quaternions are directly related to vectors, you can add two pure quaternions to form a third one. Observe the figure, were we represent a pure quaternion and the real axis is omitted:

Translation quaternion p

Rotation

A general rotation of $\phi$ around an arbitrary unit norm rotation axis n is givem by:

Quaternion rotaiton by an arbitrary axis n

QUESTION 1: Given $q_{2}$ and $q_{3}$ how can I find $q_{1}$?

If $q_{3} = q_{1}q_{2}$ and they are rotation quaternions:

$q_{3} = q_{2}q_{1}$

$q_{3}q_{2}^{*} = q_{1}q_{2}q_{2}^{*}$

Since $q_{2}^{*}q_{2} = 1 = q_{2}q_{2}^{*}$

$q_{1} = q_{3}q_{2}^{*}$

were the * states for the conjugate of a quaternion.

QUESTION 2: How to find a rotation angle over some other vector, given rotation quaternion? For example I want to find on what angle does $q_{3}$ turned over 2i+j−k quaternion.

If your vector is represented by $n$ and you know the $r$, your rotation angle will be the double of the angle you see.

Example:

$n = i + 0j + 0k$

$r$ = $q_{1} = cos(\frac{\pi}{4}) + sin(\frac{\pi}{4})i$

from the formula presented in the section of rotation:

$\frac{\phi}{2} = \frac{\pi}{4}$

$\phi = \frac{\pi}{2}$

Hope that was useful.

Best regards

$\endgroup$
0
$\begingroup$

Unit quaternions are used to define rotations, and has nothing to do with position. It defines all points in $SO(3)$, the 3D rotation group, and does not suffer from singularity, as in the case of Euler angles.

The quaternion ${\bf q}_1=\cos(\pi/4)+\sin(\pi/4)\bf i$ represents rotation about (not over) the $\bf i$ vector, which in general represents the $x$-axis, by an angle of $\pi/2$. This can be easily understood by the equivalent axis-angle representation. Any quaternion can be written as ${\bf q}=\cos(\phi/2) + \sin(\phi/2){\bf k}$, where ${\bf k}$ is a unit vector representing the axis of rotation and $\phi$ is the angle in radians. Following the logic, the quaternion ${\bf q}_2=\cos(\pi/4)+\sin(\pi/4)\bf k$ represents rotation about the $z$-axis and not $y$-axis.

The equivalent rotation of first performing ${\bf q}_1$ and then ${\bf q}_2$ is given by ${\bf q}_3={\bf q}_2{\bf q}_1$. Note the order of the multiplication. Also, the quaternion multiplication is not commutative. The quaternion multiplication is performed using the following rules:

  1. ${\bf ij}={\bf k}$, ${\bf jk}={\bf i}$, ${\bf ki}={\bf j}$
  2. ${\bf ji}={\bf -k}$, ${\bf jk}={\bf -i}$, ${\bf ki}={\bf -j}$
  3. ${\bf i}^2={-1}$, ${\bf j}^2={-1}$, ${\bf k}^2={-1}$.

Following these rules, one can calculate ${\bf q}_3={\bf q}_2{\bf q}_1=\frac{1}{2}+\frac{1}{2}{\bf i}+\frac{1}{2}{\bf j}+\frac{1}{2}{\bf k}$.

In order to find ${\bf q}_1$ if ${\bf q}_2$ and ${\bf q}_3$ are given, one can write the equation as

${\bf q}_1={\bf q}^{-1}_2{\bf q}_3$. The inverse of a quaternion ${\bf q}^{-1}_2$ is given by its conjugate.

Hence, ${\bf q}^{'}_1=(\cos(\pi/4)-\sin(\pi/4){\bf k})*(\frac{1}{2}+\frac{1}{2}{\bf i}+\frac{1}{2}{\bf j}+\frac{1}{2}{\bf k})$, $*$ represents quaternion multiplication. This gives ${\bf q}^{'}_1={\bf q}_1$.

Finding the equivalent axis-angle representation:

The norm of the vector component gives $\sin(\phi/2)$ and the scalar component gives $\cos(\phi/2)$. Hence, the angle $\phi=2\operatorname{ArcTan}(\sin(\phi/2),\cos(\phi/2))$. Note the use of ArcTan and the double argument. This gives a unique answer, as opposed to taking ArcCos or ArcSin. The axis vector can then be found by dividing the vector component of quaternion by $\sin(\phi/2)$. For example, the quaternion ${\bf q}_3$ can be stated as rotation about the unit vector ${\bf v}=\frac{1}{\sqrt{3}}{\bf i}+\frac{1}{\sqrt{3}}{\bf j}+\frac{1}{\sqrt{3}}{\bf k}$ by an angle of $\frac{2\pi}{3}$.

Further references:

Quatenions and spatial rotations (Wikipedia)

Quaternions and Rotations in 3-Space: How it Works

Representing Attitude: Euler Angles, Unit Quaternions, and Rotation Vectors

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.