Advertisement

Quaternion limitations

Started by February 28, 2006 01:38 PM
3 comments, last by Egelsoft 18 years, 9 months ago
Hi everyone, I made this nice engine that uses quaternions for rotation math, I am also attempting (<- notice it's not working >.<) to use quats for setting basic simulation features like rotational speed and acceleration. However quat's can only represent +- pi rad's of rotation (since they use sin & cos representations for the angular magnitude), so what happens is that I set a ball (or any other object) to rotate at 1.5pi rad/sec. When a frame completes I get a delta T (in seconds) in an update function. The update function scales the quat's rotation by dT and performs the rotation. However when I get above pi rad/sec in either direction it naturally wraps around to the other sign (like 1.5pi rad has the same net effect as -.5pi) and so the update function scales -.5pi by dT instead of 1.5pi rad/sec and (not entirely unexpected) my rotation is all screwed. Is there any way to overcome this limitation of quats (without resorting to saying the rotation must be in rad/(.01*sec) and the likes which only strech the cap point)? I have been reading some on wiki and came across tensors, they sound mighty interresting. Can they help? (are they any use at all in computer graphics?) Any thoughts are welcomed Greets, Egelsoft
When using quaternions for dynamics it is important to realize the relationship between quaternions, an axis-angle representation of an orientation, and a rotational torque.

Effectively, a Quaternion is just an axis to rotate about and an angular amount of how much to rotate. It is simply in a slightly different form that has nice properties when interpolating between them.

Generally a quaternion is used to express an orientation which can only be in the 360 degree range.

But you could have an angular velocity that is greater than 2 PI/frame. It won't look great if you object is rotating that fast every frame. It would lead to that weird strobing effect you sometimes see on video of rotating objects. But you can do it.

So if your angular velocity is something big, you then need to intergrate it with respect to your timestep to get your new orientation which can then be expressed as a quaternion.

I would suggest reading David Baraff's course notes on this, as he gives the formula and it is sort of drawn out to derive. www-2.cs.cmu.edu/~baraff/sigcourse/notesd1.pdf

Formula 4-2 should show you what you want.

Advertisement
Quaternion's aren't "amount of rotation", they are "change in orientation".

If you spin around twice, your orientation did not change -- you are still facing exactly the same way -- even if you rotated alot.

If you want to be able to encode any rate of rotation, but use Quaternion, try the following.

Let Q by a Quaternion. Let Q` be the "reverse" of that Quaternion. (ie, QQ` = Q`Q = no change in orientation. Q` is the inverse of Q.)

Let R(d) be a rotation by d degrees around a fixed axis (like the z axis). Note that this rotation can be converted into a Quaternion relatively easily, but the amount of rotation should not be stored as a Quaternion.

Then, multiplied as quaternions, the following:
QR(d)Q`
is the orientation caused by a rotation by d degrees around some axis.

Which axis? Whatever axis the quaternion Q moves the z axis to.

If you want to see the effects of 1/100th of that rotation, you simply calculate the quaternion:
QR(d/100)Q`

So your rate-of-rotations should store two values:
Q -- the Quaternion that represents the axis around which you are rotating
d -- the amount of rotation you want to do around that axis.

(I am assuming that your library has right-most quaternion acting on your point first -- it is possible my multiplication is backwards.)
Yes, exactly as they say; quaternion is not what you need to use for angular velocities.
Angular velocity can be best represented as 3D vector. That's how it is usually(or always) done in physics. Direction of vector specifies axis of angular velocity, length specifies rotation speed itself. There's no more need to use quaternions there than to use quaternions to store linear velocities.[smile]

Now, how inertia tensors is used: the momentum of spinning body is inertia tensor * angular velocity . This formula is usually used other way to get angular velocity from momentum, tho.
Quote: Original post by Dmytry
Angular velocity can be best represented as 3D vector.


wow.. I never thought of it that way. I was strugeling with the fact that vectors would require an aditional variable to indicate rotation about that axis, never thought about encoding them in the vector length. I'll look it up on google. This could mean seriously elegant code...
Thanx!

This topic is closed to new replies.

Advertisement