Archived

This topic is now archived and is closed to further replies.

Quaternions - Why use them?

This topic is 6355 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve read a lot of information over them on the net. I probably can implement and use em now, but I ask myself - what''s the use? Most things I want I can do without quaternions. Can somebody please give me a short practical example, where you must use quaternions?

Share this post


Link to post
Share on other sites
What are the things you want to do?
Quaternion are useful in interpolating between two orientations. Like in tomb raider you turn your character but you notice the surrounding doesn''t turn as fast as your character, at that point the camera is following a interpolation between the two orientations.. you can try to do specify it with euler angles but you might get a gimbal lock. I think that''s it. Someone correct me if I''m wrong

Share this post


Link to post
Share on other sites
I never understood why people think they have to use quaternions to interpolate. You can use the 3 vector (UVN) viewing system and interpolate between vectors. This system works much better with matrices and the math is all normal.

http://3d.n3.net/

Share this post


Link to post
Share on other sites
the computer can calculate rotations quicker with quaternions , though this is only really useful if youre doing someit that needs speed like a 3d engine hehheh

Share this post


Link to post
Share on other sites
Some time back, I wrote a space simulator (or something that looked like it...) I uses the vectors of different object to make a "homing-algo". (a homing missile chasing a ship)
If I remember correctly - I used the crossproduct to get the vector between the two objects - then used the dot product to calc the angle. Afterwards rotated around this cross product vector...ect...

- It worked just fine -

zedzeek: I see - quaternions CAN be faster if you''re doing a lot of angle calculations after another. But (correct me if I''m wrong) to calc a quaterion from a matrix and back - you''ll need a lot of extra calculations just to convert.

My believe in quaternions is fading...


Share this post


Link to post
Share on other sites
To tell you the truth, I myself don''t know why they use them. But, I''d imagine it has to do with the "smooth" movement that you see in Tomb Raider''s camera system.

OldManDave.

Share this post


Link to post
Share on other sites
Oke guys, I think I''m getting it now!? - Quaternions are only used for smooth 3D angle interpolations.
I used to think they could be used for lots of more stuff.
Maybe I''ll do some more investigating on quaternions when I really really need them...
For the moment I guess there are more interresting and usefull things to learn...

All I can say: - Don''t believe the hype!

(ps: please prove me wrong hehe)

Share this post


Link to post
Share on other sites
From what I''ve read, quaternions are a bit more useful than merely producing smooth rotations. Also, they may be more computationally cheap than you think. Gamasutra has a really good article on them and I''d recommend you read that if you want more info after reading the one that was made for gamedev.

The biggest advantage I see is avoiding "gimbal lock", or the loss of one DOF due to compound rotations using the euler rep method. Also, it''s computationally cheap vs. the angle rep method when you''re interpolating between orientations (and want it to be smooth).

However, the gimbal lock problem doesn''t occur if you aren''t compounding angles/using all 3 DOF. So, if you only plan on rotating about 1, maybe even 2 axes, then you might not have this problem. However, if you are rotating about 3 DOF, gimbal lock may occur with the euler method and angle axis methods.

I guess it really depends on your application and how much freedom you want when moving objects about.

Just be warned, I''m not an expert by any means, but, it''s just from my observations.

-Division-By-Zero

Share this post


Link to post
Share on other sites
A single quaternion is made of 4 values (w,ix,jy,kz).
A single matrix is made of 9! values (3*3)

You can do exactly the same things with quaternions as with matrices, but far more efficiently.
Now in your 3D engine you would use only quaternion math, and eventualy convert the final quaternion to a full 4*4 matrix to give it to the 3D API (D3D or OpenGL) that uses only matrices.

As for the gimble lock, as said before, it''ll happen only if you rotate arround the 3 axes at the same time.

So the quaternion advantages would be:
smooth orientation interpolation,
no gimble lock,
fast & efficient math.

A disadvantage:
no translation & no scaling information

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quaternions aren''t meant to provide translation/scaling; they''re
meant to represent orientations specifically. Anywhere you
have to consider the orientation of an object they''re at least
a consideration. A couple more specific applications in addition
to the ones folks have mentioned so far:

1) Dynamics. Quaternions are much handier than matrices at
representing object orientations for a dynamics/kinematics
engine. If you do this, have a look at one of the SIGGraph
tutorials on physically-based modelling or dynamic simulation;
there are a couple of subtleties that need to be looked out for
(especially a rather ad hoc 1/2 factor you need in your differential equations). I''ve got a small piece of an engine
using this and it''s amazing how smoothly it coded up.

2) Random orientations. Because (unit) quaternions essentially provide a 1-to-1 correspondence between orientations and points on the three-sphere (actually it''s 1-to-2 but that''s just a minor detail) you can generate random orientations if you know how to generate random points on an n-sphere, and the latter is a well-known problem with several feasible solutions; just check Knuth vol. 2 or your copy of Numerical Recipes and you should find a good scheme. I''m using this right now in the screensaver I''m working on, in a fairly unusual application; again it works remarkably well for me.

That''s really what it comes down to: do you feel comfortable using them? I started as a mathematician and I find them to be really straightforward and a convenient way of doing a lot of things that don''t have many other convenient solutions. If you have a harder time grokking them then you may not need them; look into them if you want to but don''t feel forced to use them. Do what makes your own programming easiest and produces the best results for you.

Steven Stadnicki

Share this post


Link to post
Share on other sites