# Why do game programmers use quaternions to rotate a vector?

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

## Recommended Posts

[Edited by - Kambiz on March 29, 2006 8:36:21 AM]

##### Share on other sites
Do game programers do so? Yes, but very seldom. In fact the matrix vector product is much better suited to rotate a vector.

However, quaternions are good for operations occuring _before_ rotating a vector, namely in intra-/extrapolating rotations, in concatenating rotations, and a bit also in storing rotations (if the memory footprint plays a remarkable role).

But, hey, formula 4) seems me a look worth ;) That is an axis/angle pair rotation, right?

##### Share on other sites
Because sometimes, rotating a vector is not the goal, it's part of the process you must follow, in order to achieve the goal.

And quaternions -sometimes- make it easier to achieve some goals, than just rotate a vector.

##### Share on other sites
Quote:
 Original post by haegarrBut, hey, formula 4) seems me a look worth ;) That is an axis/angle pair rotation, right?

Yes

Quaternion rotations are easy to combine, that is a good reason to use them, but I think many programmers use quaternions just because they do not know formula 4 or think that quaternions are cool!

##### Share on other sites
Quote:
 Original post by someusernameAnd quaternions -sometimes- make it easier to achieve some goals, than just rotate a vector.

Give me an example.

##### Share on other sites
Orientation interpolation at constant angular speed

##### Share on other sites
I saw an engine once that serialized rotations as a quaternion using 3 8-bit values. It used w = 1-sqrt(x^2+y^2+z^2) (or something like that) when it loaded them from disk, then converted that to a 3x3 matrix. So basically it compressed the 3x3 matrix down to 24-bits.

Not sure I'd do that, but it seemed to work okay.

##### Share on other sites
Quote:
 Original post by someusernameOrientation interpolation at constant angular speed

Why do you need a quaternion? In classical mechanics people use just a vector and it works well.

##### Share on other sites
Quote:
 Original post by Anonymous PosterI saw an engine once that serialized rotations as a quaternion using 3 8-bit values. It used w = 1-sqrt(x^2+y^2+z^2)...Not sure I'd do that, but it seemed to work okay.

The same way you can use a vector to represent the rotation... as you see you just need 3 values x,y,z and w is useless.

##### Share on other sites
You're talking about the angular velocity vector which describes the instantaneous rate of change of an object's axes.
I'm talking about arbitrarily setting the object's axes to any two orientations, and interpolating smoothly from one to the other.

If you just want to rotate a vector, there must be a million ways. You could even change to spherical coordinates, offset the angles and reproject to cartesian.
Have you seen anyone using that? It's all a matter of what you want to achieve in the first place.

And I said "quaternions sometimes make it easier", not that they can do something when there is no other way.
Anyway, I don't feel like arguing about this. Anyone who has ever used them can decide for themselves whether they are worth the fuss.

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632993
• Total Posts
3009763
• ### Who's Online (See full list)

There are no registered users currently online

×