How to express a rotation to describe the change of orientation between two quaternions?

222 Views Asked by At

Please let me describe the following situation: Having a quaternion q1 representing an orientation of an object in 3d space at time t=n and one other q2 at time t=n+1. Is it possible to calculate a description of what happend to the object with angles or rotation matrix?

The aim would be to reconstruct the rotation that happened between q1 and q2. So if i knew the angles around the objects axis (lets call them 2Ψ,2Θ,2*Φ) i could reconstruct q2 from q1 by multiplication with the quaternion I get from:

( cos ⁡ Ψ + k sin ⁡ Ψ ) ( cos ⁡ Θ + i sin ⁡ Θ ) ( cos ⁡ Φ + k sin ⁡ Φ ) 
= cos ⁡ Ψ cos ⁡ Θ cos ⁡ Φ − sin ⁡ Ψ cos ⁡ Θ sin ⁡ Φ  


= cos ⁡ Ψ cos ⁡ Θ cos ⁡ Φ − sin ⁡ Ψ cos ⁡ Θ sin ⁡ Φ 

    + i ( cos ⁡ Ψ sin ⁡ Θ cos ⁡ Φ + sin ⁡ Ψ sin ⁡ Θ sin ⁡ Φ ) 
    + j ( − cos ⁡ Ψ sin ⁡ Θ sin ⁡ Φ + sin ⁡ Ψ sin ⁡ Θ cos ⁡ Φ ) 
    + k ( sin ⁡ Ψ cos ⁡ Θ cos ⁡ Φ + cos ⁡ Ψ cos ⁡ Θ sin ⁡ Φ ) 
2

There are 2 best solutions below

1
On

When you have a rotation quaternion $r = (\cos \theta/2, 0, 0, \sin \theta/2)$ and you multiply a general quaterion $p=(p_0, p_1, p_2,p_3)$ from the left (quaternion multiplication), you get a resulting quaternion $q$ so that $$ q= \left[ \begin{array}{ccc} \cos \frac{\theta}{2} & 0 &0 &- \sin \frac{\theta}{2} \\ 0 & \cos \frac{\theta}{2} & \sin \frac{\theta}{2} & 0 \\ 0 & -\sin \frac{\theta}{2} & \cos \frac{\theta}{2} & 0 \\ \sin \frac{\theta}{2} & 0 &0 & \cos \frac{\theta}{2} \\ \end{array} \right] \left[ \begin{array}{c} p_0 \\ p_1 \\ p_2 \\p_3 \end{array} \right] $$ In order to solve for $\theta$, you can take for example the two middle rows. They just say that $$ \begin{cases} q_1 = \cos \frac{\theta}{2} p_1 &+ \sin \frac{\theta}{2} p_2 \\ q_2 = -\sin \frac{\theta}{2} p_1 &+ \cos \frac{\theta}{2} p_2 \\ \end{cases} $$ or $$ \begin{cases} q_1 = \cos \frac{\theta}{2} p_1 &+ \sin \frac{\theta}{2} p_2 \\ q_2 = \cos \frac{\theta}{2} p_2 &-\sin \frac{\theta}{2} p_1 \\ \end{cases} $$ You can multiply the first row by $p_1$ and the second row by $p_2$ to get $$ \begin{cases} q_1p_1 = \cos \frac{\theta}{2} p_1^2 &+ \sin \frac{\theta}{2} p_1 p_2 \\ q_2 p_2 = \cos \frac{\theta}{2} p_2^2 &-\sin \frac{\theta}{2} p_1 p_2 \\ \end{cases} $$ the sum of which is $$ q_1 p_1 + q_2 p_2 = \left(p_1^2 + p_2^2 \right)\cos \frac{\theta}{2} $$ I'm sure that from this, you can already solve for $\theta$.

1
On

If you know $q_2$ and $q_1$ such that

$$q_2 = q_1 q_z$$

And your goal is to solve for $q_z$ then you can simply multiply both sides by $\tilde q_1$ on the left so:

$$\tilde q_1 q_2 = \tilde q_1 q_1 q_z$$

$$\tilde q_1 q_2 = q_z$$

Where $\tilde q_1$ is the conjugate of $q_1$ so that $\tilde q_1 q_1 = 1$

Now, if you only know $q_2$ and want to recover $q_z$ you can do that as follows assumung the relationship $q_2 = q_1 q_z$ holds.

Multiply both sides by $z \tilde q_2$ on the right.

$$q_2 z \tilde q_2 = q_1 q_z z \tilde q_2$$

Where $z$ is the conventional "z-vector" $(0,0,1)$ embedded in a pure quaternion.

By definition, the reverse of $q_2$ can be written in terms of $q_1$ and $q_z$ as:

$$\tilde q_2 = \tilde q_z \tilde q_1$$

Replacing on previous equation we have:

$$q_2 z \tilde q_2 = q_1 q_z z \tilde q_z \tilde q_1$$

Since $z$ is an eigen-quaternion of $q_z$ so $z = q_z z \tilde q_z$ we arrive to:

$$q_2 z \tilde q_2 = q_1 z \tilde q_1$$

Which means that $q_1$ is the twist-free rotation component of $q_2$ (in the sense of the "Swing Twist Decomposition") when applied to $z$.

We define $z'$ as $z' = q_2 z \tilde q_2$, then $q_1$ can be recovered as:

$$q_1 = \frac{1 + z z'}{\sqrt{2 (1 + z \cdot z')}}$$

Which is a compact formula to find the unit quaternion aligning $z$ with $z'$ (sometimes known as the "half-way" solution).

Having $q_1$ we can recover $q_z$ as before as:

$$\tilde q_1 q_2 = q_z$$