1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Using quaternions to perform rotations

  1. Jul 19, 2012 #1

    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?


  2. jcsd
  3. Jul 19, 2012 #2
    There is no difference. They just have the q's in a different order.

    EDIT: Actually, nevermind that. Quaternion multiplication doesn't commute.
  4. Jul 19, 2012 #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.
  5. Jul 19, 2012 #4
    If I have a vector like so:


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


    I would expect to obtain the following vector:


    If I use the first of the two equations in my first post, this gives the following vector:

    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?


  6. Jul 19, 2012 #5
    Where exactly have you seen the first one? I'm only familiar with the second.
  7. Jul 19, 2012 #6
  8. Jul 19, 2012 #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.
  9. Jul 19, 2012 #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.
  10. Jul 19, 2012 #9
    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:

    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:

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

    Giving the following vector:

    If I use the following quaternion vector rotation equation, I get the answer I expect:

    However, using the following equation:

    gives me the following vector:

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


    Last edited by a moderator: May 6, 2017
  11. Jul 19, 2012 #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.
  12. Jul 19, 2012 #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: Jul 19, 2012
  13. Jul 19, 2012 #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.
  14. Jul 19, 2012 #13

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    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.
  15. Jul 20, 2012 #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:

    Is this an example of a right or left quaternion?


  16. Jul 20, 2012 #15

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    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.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook