# Using quaternions to perform rotations

1. Jul 19, 2012

### ryan88

Hi,

I have been looking at quaternions to perform rotations, however I have come across two slightly different equations to do this:

$v' = q^{-1}vq$
$v' = qvq^{-1}$

What is the difference between these two?

Thanks,

Ryan

2. Jul 19, 2012

### Mark M

There is no difference. They just have the q's in a different order.

EDIT: Actually, nevermind that. Quaternion multiplication doesn't commute.

3. Jul 19, 2012

### Muphrid

The difference ought to be just a matter of definition. The $q$ in the first line is going to be the same as the $q^{-1}$ in the second to describe the same rotation.

4. Jul 19, 2012

### ryan88

If I have a vector like so:

$v=\begin{bmatrix} 0\\ 1\\ 0\\ 0 \end{bmatrix}$

and the following quaternion which should perform a 90° rotation about the z axis:

$v=\begin{bmatrix} 0.7071\\ 0\\ 0\\ 0.7071 \end{bmatrix}$

I would expect to obtain the following vector:

$v=\begin{bmatrix} 0\\ 0\\ 1\\ 0 \end{bmatrix}$

If I use the first of the two equations in my first post, this gives the following vector:
$v=\begin{bmatrix} 0\\ 0\\ -1\\ 0 \end{bmatrix}$

whilst the second equation gives me the answer I expect.

Does this mean that the first of the two equations is rotating the frame around the vector, whilst the second is rotating the vector within the frame?

Thanks,

Ryan

5. Jul 19, 2012

### Mark M

Where exactly have you seen the first one? I'm only familiar with the second.

6. Jul 19, 2012

### ryan88

7. Jul 19, 2012

### Muphrid

As I said, it's a convention. You can't expect to plug in some specific quaternion for q and get the result you "expect" without knowing which convention the q came from.

8. Jul 19, 2012

### Mark M

Isn't it just the opposite rotation of the other equation? Since q and q^-1 are inverses, using equation one is the equivalent to using equation two with the inverse of q.

9. Jul 19, 2012

### ryan88

As further clarification of my earlier post, please consider the following diagram:
http://img171.imageshack.us/img171/2594/vec1a.png [Broken]

This shows the following vector:
$v=\begin{bmatrix}0\\1\\0\\0\end{bmatrix}$

If I want to perform a right handed rotation of 90° around the z axis of the above axes, this quaternion can be computed as follows:
$q_0 = \cos\left(\frac{\theta}{2}\right )$
$q_1 = 0\times\sin\left(\frac{\theta}{2}\right )$
$q_2 = 0\times\sin\left(\frac{\theta}{2}\right )$
$q_3 = 1\times\sin\left(\frac{\theta}{2}\right )$

Giving the following:
$q=\begin{bmatrix}0.7071\\0\\0\\0.7071\end{bmatrix}$

Performing this rotation graphically would give:
http://img443.imageshack.us/img443/9341/vec2.png [Broken]

Giving the following vector:
$v'=\begin{bmatrix}0\\0\\1\\0\end{bmatrix}$

If I use the following quaternion vector rotation equation, I get the answer I expect:
$v'=qvq^{-1}$

However, using the following equation:
$v'=q^{-1}vq$

gives me the following vector:
$v'=\begin{bmatrix}0\\0\\-1\\0\end{bmatrix}$

showing this graphically, it seems that it has done the following:
http://img256.imageshack.us/img256/6962/vec3.png [Broken]

either that or it has performed a -90° rotation around the z axis.

I would just like to know if one does represent rotating a vector within a frame and the other rotating the frame around a vector, or is it simply that if $q=q^{-1}$ then $(q^{-1})^{-1}=q$?

Thanks,

Ryan

Last edited by a moderator: May 6, 2017
10. Jul 19, 2012

### Muphrid

There are a couple viewpoints on this. Yes, you can say that one convention represents an active transformation and the other a passive one. But, you can also say that they both represent active transformations, and each just demands a different method of calculating $q$.

In other words, let $q = p^{-1}$. Your first equation is

$$v' = p v p^{-1}$$

Your second equation could then be written as

$$v' = q v q^{-1}$$

They both have the same form. Shifting the inverse around doesn't really do anything. It's just that you're insisting on plugging in the quaternion you think is right as $p^{-1}$ in the first equation when you should be plugging it in as $p$. The problem here isn't with the equations. It's how you're arriving at "this is the quaternion I think is $q$" in the first place.

11. Jul 19, 2012

### Mark M

Murphrid, don't the two expressions amount to doing the opposite rotation?

Since the first equation is just the second equation with the inverse of q, and since $q^{-1}q = 1$, applying both to the same vector should bring it back to the original state. In geometric terms, this is the equivalent of doing two opposite rotations.

Last edited: Jul 19, 2012
12. Jul 19, 2012

### Muphrid

Yes, they do, I'm not disputing that. I'm just trying to show that the descriptions both have the same form, and any difference between the two is a matter of convention.

Mostly I'm trying to question why ryan88 expects the given quaternion to produce a given rotation. Why not expect the inverse of that quaternion to do it instead? It's all just a matter of convention.

13. Jul 19, 2012

### D H

Staff Emeritus
Semantics, nothing else.

A very similar issue arises with similarity transformations. Should they be written as $PAP^{-1}$ (e.g. http://mathworld.wolfram.com/SimilarityTransformation.html) or $P^{-1}AP$ (e.g., http://en.wikipedia.org/wiki/Similar_matrix)? The answer is "yes". The same applies to quaternions when used to represent rotations.

In other words, there is no right way / wrong way. What is wrong is arguing that one way is right, the other wrong. One way is right, but the other way isn't wrong. It's left. I (and others) call the quaternion $q$ in the form $v'=qvq^{-1}$ a "left" quaternion while the form $v'=q^{-1}vq$ uses a "right" quaternion. Is the original quaternion is on the left or the right?

There are subtle differences in the representation. The equation that relates the time derivative of the quaternion to angular velocity takes on a slightly different form for left and right quaternions, and how quaternions for multiple reference frames chain also differs.

With regard to the latter, suppose you have three frames of interest denoted A, B, and C. Suppose you also know the quaternion $q_{A\to B}$ that transform a vector from frame A to frame B, and you know the quaternion $q_{B\to C}$ that transform a vector from frame B to frame C. Finally, suppose that you do not know, but need to know, the quaternion $q_{A\to C}$ that transforms a vector from frame A to frame C. It's an easy computation. With left quaternions, $q_{A\to C} = q_{B\to C}q_{A\to B}$. Left quaternions chain from right to left. This is exactly how transformation matrices chain. With right quaternions, $q_{A\to C} = q_{A\to B}q_{B\to C}$. This is analogous to how vectors chain, end to end.

One last issue occurs when two organizations that uses quaternions need to exchange data. Someone had better beware of this left versus right ambiguity. Tempers will flare otherwise! I've seen this silliness firsthand.

14. Jul 20, 2012

### ryan88

Ok, so how do I know whether a quaternion I define is a right of left quaternion?

For example, as I said in an earlier post:

Is this an example of a right or left quaternion?

Thanks,

Ryan

15. Jul 20, 2012

### D H

Staff Emeritus
If you defined it, you should know. On the other hand, if all you have are the four elements of a quaternion as numbers from some other organization, you had better well ask. You had also better ask a couple of other questions:
• Which of those four numbers is the scalar (real) part of the quaternion?
Some people place the real part of the quaternion as the first of the four values. For others, it is the last of the four values. There's no right way / wrong way, so you need to ask.

• Is this a rotation quaternion or a transformation quaternion?
Or as some put it, active versus passive transformation (http://en.wikipedia.org/wiki/Active_and_passive_transformation). Does the quaternion represent the physical rotation of some object (e.g., moving the hour hand of a clock from 2 to 3 to mark the onset of daylight savings time, or physically rotating a robotic arm by some amount), or does it represent the transformation of the representation of a vector from one reference frame to another?
From the way you wrote that, that appears to be either a left rotation quaternion or a right transformation quaternion. They have exactly the same form.

Muphrid was spot on when he said "It's all just a matter of convention." There are eight possible conventions here, (left vs right) × (rotation vs transformation) × (scalar first vs last). If you are defining the system, you get to choose the convention. If you are exchanging quaternions with some other organization, you had better well ascertain the conventions used by that other organization. The same applies when you are reading some poorly written journal paper that describes a nifty rotational control system: You need to ferret out the convention used by that author.