I have an angular velocity vector[3] in three dimensions and a unit quaternion (magnitude of 1) representing an orientation in three dimensions.

I need to apply the angular velocity to the quaternion orientation, such that the rotation is correct in a Newtonian universe.

I'm sure it was in the books somewhere, but now I can't find it.


Alright, in reply to help; would this be the equations?


C is q-1 (well, the conjugate, but my books tell me a unit quaterinion conjugate is the same as the negate)

b is the angular velocity, already scaled by time.

a is q and the quaternion to rotate.

So: qbq-1, or abc for quaternion rotation. It's rotating, that's fine.

However, it's applying the angular velocity as if it were a rotation from (1,0,0,0).

To explain what I'm seeing: Let's say we apply an angular velocity, pre-multiplied by dt (delta time). It gets multiplied by the conjugate of the current rotation (which, currently, is (1,0,0,0) and the current rotation, to result in the next rotation.

So the next rotation is initially equal to the angular velocity.

Then we multiply the angular velocity, as a quaternion, by the conjugate of the current rotation.

Which is the conjugate of the angular velocity as a quaternion.

So essentially, we end up with a rotation from (1, 0, 0, 0) each time step.

...And now it's swinging back and forth along the Y axis.

I suspect the problem is in how I'm turning angular momentum into angular velocity; should I make a new topic? Not entirely sure of informal etiquette here. Makes sense too, but figured I'd ask.

  • $\begingroup$ I'm not sure I understand all of this. As far as I do, I don't see where you've used the sine and cosine -- it seems in the first set of four lines you're multiplying $q^{-1}$ by $(1,b)$? That should be $(\cos(|b|/2),b\sin(|b|/2)/|b|)$, if $b$ is what I think it is. Also, you seem to have transposed the $t$s in the second set of four rows; I think it should be $t_1$ through $t_4$ in each of the four rows. $\endgroup$ – joriki May 18 '11 at 15:25
  • $\begingroup$ Ok, looking at your explanation again - I take the magnitude of the angular velocity vector, divide it by 2 and that's the W component of the angular velocity quaternion? Then, the normalized vector multiplied by the sin of half its magnitude is the X, Y and Z coordinates of the angular velocity quaternion? And that is what I multiply by qwq-1, where w is the angular velocity quaternion? $\endgroup$ – Narf the Mouse May 18 '11 at 16:30
  • $\begingroup$ That's right, except you dropped the cosine on the $W$ component. I just realized I used the "scalar plus vector" notation from Wikipedia there that might be confusing -- I've changed it to the more usual tuple notation. $\endgroup$ – joriki May 18 '11 at 22:18

It's not entirely clear (to me) what you mean by "applying an angular velocity". Angular velocity is an instantaneous property; if you only have a single angular velocity vector, you only have the first derivative of the motion at one point in time, and thus can't say anything about the orientation at other times.

I'll assume that you're assuming the angular velocity to be constant, and that by "applying" it you mean calculating the orientation at later times of a body that has the given initial orientation and undergoes a motion with the given constant angular velocity.

To do this, you need to know a) how to find the unit quaternion corresponding to a rotation vector and b) how to compose two unit quaternions in order get the unit quaternion corresponding to the composition of the corresponding rotations.

For a), let's denote the angular velocity vector by $\vec{\omega}$. Over a time $t$, a motion with this (constant) angular velocity results in a rotation that can be described by the vector $\vec{w}=\vec{\omega}t$, where the direction and magnitude of $\vec{w}$ specify the axis and angle of the rotation, respectively. This rotation corresponds to the unit quaternion


For b), since applying the rotation corresponding to a unit quaternion $q$ to a three-dimensional vector $\vec{v}$ consists in conjugating a quaternion $\nu$ corresponding to $\vec{v}$ by $q$, composing rotations just corresponds to multiplying the corresponding quaternions:

$$q(\vec{v})=q\nu q^{-1}\;,$$ $$q_1(q_2(\vec{v}))=q_1(q_2\nu q_2^{-1})=q_1q_2\nu q_2^{-1} q_1^{-1}=(q_1q_2)(\vec{v})\;.$$

(This is part of what makes quaternions so useful for representing three-dimensional rotations). So now you just multiply $q$ and your initial unit quaternion, say, $q_0$. Since the initial rotation is applied first, the corresponding unit quaternion is on the inside of the nested conjugations, so it has to be the right-hand factor: $q'=qq_0$.

For more on all this, see this Wikipedia article.

  • $\begingroup$ Thanks. Replying a day late because my brain needed a break. I'm about to add a stab at implementing that equation mathematically; could you check it, please? Thanks. $\endgroup$ – Narf the Mouse May 18 '11 at 14:59
  • $\begingroup$ Thanks again; I have correct rotation! I'd upvote your answer, but, well, I can't. $\endgroup$ – Narf the Mouse May 19 '11 at 14:22
  • $\begingroup$ @Narf: You're welcome. But you can accept the answer (by clicking on the checkmark); that's actually more important than upvoting it, since that marks it as answered for others. $\endgroup$ – joriki May 19 '11 at 15:28
  • $\begingroup$ Slight problem: I realized I wasn't setting my torque to zero after applying it. Once I did that, the angular velocity I thought I was seeing became an apparent rotational offset. More to come. $\endgroup$ – Narf the Mouse May 19 '11 at 17:41
  • $\begingroup$ Well, I've marked yours as the answer and I'm making a new thread. $\endgroup$ – Narf the Mouse May 19 '11 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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