Using quaternions to perform rotations

In summary: I have been looking at quaternions to perform rotations, however I have come across two slightly different equations to do this:v' = q^{-1}vqv' = qvq^{-1}What is the difference between these two?In summary, the difference between these two equations is a matter of convention and they both represent active transformations. The first equation can be seen as performing a rotation of the frame around the vector, while the second equation can be seen as rotating the vector within the frame. However, the difference is not in the equations themselves but in how the quaternion is chosen and plugged into the equation. It is important to be aware of this left versus right ambiguity when using quaternions and exchanging data
  • #1
ryan88
42
0
Hi,

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

[itex]v' = q^{-1}vq[/itex]
[itex]v' = qvq^{-1}[/itex]

What is the difference between these two?

Thanks,

Ryan
 
Physics news on Phys.org
  • #2
There is no difference. They just have the q's in a different order.

EDIT: Actually, nevermind that. Quaternion multiplication doesn't commute.
 
  • #3
The difference ought to be just a matter of definition. The [itex]q[/itex] in the first line is going to be the same as the [itex]q^{-1}[/itex] in the second to describe the same rotation.
 
  • #4
If I have a vector like so:

[itex]v=\begin{bmatrix}
0\\
1\\
0\\
0
\end{bmatrix}[/itex]

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

[itex]v=\begin{bmatrix}
0.7071\\
0\\
0\\
0.7071
\end{bmatrix}[/itex]

I would expect to obtain the following vector:

[itex]v=\begin{bmatrix}
0\\
0\\
1\\
0
\end{bmatrix}[/itex]

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

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
Where exactly have you seen the first one? I'm only familiar with the second.
 
  • #7
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
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
As further clarification of my earlier post, please consider the following diagram:
http://img171.imageshack.us/img171/2594/vec1a.png

This shows the following vector:
[itex]v=\begin{bmatrix}0\\1\\0\\0\end{bmatrix}[/itex]

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:
[itex]q_0 = \cos\left(\frac{\theta}{2}\right )[/itex]
[itex]q_1 = 0\times\sin\left(\frac{\theta}{2}\right )[/itex]
[itex]q_2 = 0\times\sin\left(\frac{\theta}{2}\right )[/itex]
[itex]q_3 = 1\times\sin\left(\frac{\theta}{2}\right )[/itex]

Giving the following:
[itex]q=\begin{bmatrix}0.7071\\0\\0\\0.7071\end{bmatrix}[/itex]

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

Giving the following vector:
[itex]v'=\begin{bmatrix}0\\0\\1\\0\end{bmatrix}[/itex]

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

However, using the following equation:
[itex]v'=q^{-1}vq[/itex]

gives me the following vector:
[itex]v'=\begin{bmatrix}0\\0\\-1\\0\end{bmatrix}[/itex]

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

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 [itex]q=q^{-1}[/itex] then [itex](q^{-1})^{-1}=q[/itex]?

Thanks,

Ryan
 
Last edited by a moderator:
  • #10
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 [itex]q[/itex].

In other words, let [itex]q = p^{-1}[/itex]. Your first equation is

[tex]v' = p v p^{-1}[/tex]

Your second equation could then be written as

[tex]v' = q v q^{-1}[/tex]

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 [itex]p^{-1}[/itex] in the first equation when you should be plugging it in as [itex]p[/itex]. The problem here isn't with the equations. It's how you're arriving at "this is the quaternion I think is [itex]q[/itex]" in the first place.
 
  • #11
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 [itex] q^{-1}q = 1 [/itex], 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:
  • #12
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
ryan88 said:
I have been looking at quaternions to perform rotations, however I have come across two slightly different equations to do this:

[itex]v' = q^{-1}vq[/itex]
[itex]v' = qvq^{-1}[/itex]

What is the difference between these two?
Semantics, nothing else.

A very similar issue arises with similarity transformations. Should they be written as [itex]PAP^{-1}[/itex] (e.g. http://mathworld.wolfram.com/SimilarityTransformation.html) or [itex]P^{-1}AP[/itex] (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 [itex]q[/itex] in the form [itex]v'=qvq^{-1}[/itex] a "left" quaternion while the form [itex]v'=q^{-1}vq[/itex] 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 [itex]q_{A\to B}[/itex] that transform a vector from frame A to frame B, and you know the quaternion [itex]q_{B\to C}[/itex] that transform a vector from frame B to frame C. Finally, suppose that you do not know, but need to know, the quaternion [itex]q_{A\to C}[/itex] that transforms a vector from frame A to frame C. It's an easy computation. With left quaternions, [itex]q_{A\to C} = q_{B\to C}q_{A\to B}[/itex]. Left quaternions chain from right to left. This is exactly how transformation matrices chain. With right quaternions, [itex]q_{A\to C} = q_{A\to B}q_{B\to C}[/itex]. 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
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:

ryan88 said:
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:
[itex]q_0 = \cos\left(\frac{\theta}{2}\right )[/itex]
[itex]q_1 = 0\times\sin\left(\frac{\theta}{2}\right )[/itex]
[itex]q_2 = 0\times\sin\left(\frac{\theta}{2}\right )[/itex]
[itex]q_3 = 1\times\sin\left(\frac{\theta}{2}\right )[/itex]

Giving the following:
[itex]q=\begin{bmatrix}0.7071\\0\\0\\0.7071\end{bmatrix}[/itex]

Is this an example of a right or left quaternion?

Thanks,

Ryan
 
  • #15
ryan88 said:
Ok, so how do I know whether a quaternion I define is a right of left quaternion?
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?
Is this an example of a right or left quaternion?
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.
 

Related to Using quaternions to perform rotations

What are quaternions and how are they used for rotations?

Quaternions are a mathematical concept that represents 4-dimensional numbers. They are used in computer graphics and 3D game development to perform rotations in 3D space. Quaternions can be multiplied and added together, making them a useful tool for representing rotations.

How do quaternions differ from other methods of performing rotations?

Unlike other methods, such as Euler angles or rotation matrices, quaternions do not suffer from gimbal lock, a phenomenon where certain orientations become impossible to reach. Quaternions also have a more intuitive and efficient way of interpolating between rotations, making them a popular choice in animation and graphics.

What are the benefits of using quaternions for rotations?

Quaternions have a compact representation, requiring only 4 numbers instead of the 9 required for rotation matrices. This makes them more memory-efficient and faster to compute. Quaternions also have a unique property called unit length, which ensures that the rotation is always well-defined and avoids numerical errors.

What are some common applications of using quaternions for rotations?

Quaternions are commonly used in 3D graphics applications, such as video games and computer-generated imagery (CGI) in movies. They are also used in robotics and physics simulations, where precise and efficient rotations are necessary. Quaternions have also found applications in computer vision and navigation systems.

Are there any challenges or limitations when using quaternions for rotations?

One challenge is the conversion between quaternions and other rotation representations, which can be complex and prone to errors. Quaternions can also be difficult to visualize and understand intuitively compared to other methods. Additionally, quaternions only represent rotations and not translations, so additional techniques must be used to handle translations in 3D space.

Similar threads

Replies
3
Views
764
  • Advanced Physics Homework Help
Replies
1
Views
664
Replies
8
Views
3K
  • Linear and Abstract Algebra
Replies
1
Views
731
Replies
19
Views
1K
Replies
2
Views
800
  • Classical Physics
Replies
6
Views
690
Replies
2
Views
2K
  • Mechanics
Replies
1
Views
5K
Back
Top