Quaternions not all they're cooked up to be

Started by
8 comments, last by BSXrider 22 years, 3 months ago
http://www.gamedev.net/reference/articles/article1199.asp Just browsed an article on gamedev by a "Diana Gruber". I only scan read it becuase it''s too early in the day for matrix maths but at the end she has an FAQ: Q. Quaternions are necessary because without them your program will suffer from gimbal lock. A. Nonsense. Gimbal lock is only an issue if you use Euler angles. So, apologies if I''m being stupid. If you don''t use quats OR euler angles what is the alternative? - seb
Advertisement
The alternative is to use basic trigonometry and vectors. Quaternions are just operations that involve both of the above (and they were actually invented prior to vectors, but quaternions didn''t turn out to be as useful for physics-applications), and you can make your own functions to control objecets with just elementary trig and vector knowledge.

Danny
h20, member of WFG 0 A.D.
trig and vector is what I''m using at the moment. I thought this was what she meant by "euler angles". In that case what''s the point of quaternions, I thought it was just to overcome gimbal lock.

- seb
I also thought you used quaternions to overcome gimbal lock. Isn't quaternions much more process demanding ? So if you were to write an airplane simulator what would you use ?

Edited by - messiah2k on January 19, 2002 12:01:04 PM
//Messiah
The alternative to the 3 angles gimal-locking method (the so-called euler angles way) is to use an abitrary vector and an angle of rotation about that axis. With rotations represented like that it won''t suffer from gimbal lock.

Quanterions are to rotations, what vectors are to translations.
Q = Q2 * Q1; means gimme the Q that represents the rotation by concatenating the rotations (represented by) Q1 and Q2.

Are they necessary? No, there''s a number of alternative methods -but recall how everything in mathematics is related. Comparing the vector+angle method vs. quaternion is like comparing euler spatial coordinates vs. spherical coordinates (i.e. &ltx,y,z> vs. &ltr, theta, phi>). Now, for translations, the Euler way makes more sense. But rotations, the ''polar'' form makes more sense (to me at least - many have lots of experience with the alternative forms, so they like them better - like Mrs. Gruber).

There was a raging debate on various boards and newgroups about her article...
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Yeah I gathered that from her last couple of Q&A on the article :-D

- seb
the alternative is to use basis vectors, although this always depends on what you're doing. for simple first person shooter stuff, here's how you'd do this simple motion... note that euler angles would become confusing even in this simple case..

when the user presses "look up" and "look down" keys, rotate the DIRECTION and UP vectors around the RIGHT vector.

when the user presses "turn left" and "turn right" keys, rotate the DIRECTION and UP around the _absolute Y axis_, you can then take the cross product UP X DIRECTION to get the RIGHT vector back.

so you can see, in this most common case, you don't need quats at all. things become more complicated as you move to rigid body dynamics, but even then quats don't really solve the problem for you, the problem becomes angular momentum, and angular velocities and whole bunch of other things..

what quats are useful for is interpolating between orientations that are key framed. if this is what you're doing, use quats.

--bart




Edited by - bpj1138 on January 19, 2002 7:00:10 PM
--bart
I read in an article somewhere that quaternions don''t suffer from some of the problems associated with matrices and floating point math, eg after many matrix multiplications floating point inaccuracies result in a non-orthogonal matrix that has to be rebuilt.

And, as Magmai Kai Holmlor said, the opinions in the article are hotly debated so take them with a grain of salt.
There are three main methods of representing rotations: Euler angles, matrices and quaternions.

Euler angles are easiest for users to understand, and so are good for situations where users control rotations directly, and are the most compact at only three floats. But they suffer from singularities (leading to gimbal lock) and are very expensive and far less accurate to work with. It can be proved that all three-element representations of rotations suffer from similar problems.

Matrices and quaternions are both far better than Euler angles for representing rotaions. Matrices have a number of problems with them, mostly due to their size. As they require nine floats many of their calculations are more expensive to do, and there is more to go wrong so they are less numerically stable and need to be reorthogonalised more often.

Quaternions two biggest advantages are that they are far easier to reorthogonalise/renormalise and interpolate (e.g. via SLERP), so if you need to regularly do either of these calculations quaternions are far superior.

Matrices biggest advantage is in transforming points: matrices can rotate, or rotate and translate, in a single linear operation. The quaternion operation is far less straightforward. So if a large set of points is being rotated and translated matrixes are almost always better.

One solution (which we use) is a combination of both. E.g use quaternions to integrate, interpolate and update the rotations of your objects. Then convert to matrices to transform the object vertices for rendering. As always the best solution depends on your application, and if you are not sure try out the alternatives to see which is fastest.

John
John BlackburneProgrammer, The Pitbull Syndicate
quote:Original post by messiah2k
I also thought you used quaternions to overcome gimbal lock. Isn''t quaternions much more process demanding ? So if you were to write an airplane simulator what would you use ?

Edited by - messiah2k on January 19, 2002 12:01:04 PM


Properly coded quaternions require the same number of operations as equivalent methods, so they run at the same speed and processor requirement.

This topic is closed to new replies.

Advertisement