# Rotations in 3D space

Registred
Hey there,
I have a question regarding quaternions and rotations. It's related to 3D graphics programming, but nevertheless I'm sure the physics forum is the right place for my question.

As far as I've understood there are 3 primary ways we can store rotation: euler angles, quaternions and matrices. In 3D graphics programming, quaternions are often the preferred way because they need less memory than matrices but avoid gimbal lock.

To represent a 3D object with euler angles I just need 3 components: x, y and z, which each represent the angle around an axis.

Now, how many quaternions are needed to store a rotation? To my knowledge a quaternion stores an axis and the amount of rotation - so I'd need 3 quaternions to store a rotation - is that right? That would be 3 (quaternions) x 4 (values) = 12 values to be stored. To store a rotation in a matrix I would need 3 x 3 = 9 values, which is even less. So why not just use matrices? Why do quaternions need less values/memory than matrices? Do I really need 3 quaternions to represent a rotation?

Greetings!

Staff Emeritus
Homework Helper
For some reason, you're getting things mixed up.

Matrices ARE used to do coordinate rotations, even in 3D graphics programming. They are an efficient way not only of storing data, but computer hardware is specially designed to process them faster than regular data streams.

Quaternions have representations in matrix form, just like complex numbers.

To accommodate rotations and translations in 3D, 4x4 matrices are used, as illustrated in this article:
http://inside.mines.edu/~gmurray/ArbitraryAxisRotation/ [Broken]

Last edited by a moderator:
Registred

Quaternions have representations in matrix form, just like complex numbers.
How do you mean that? A quaternion can be represented by a matrix?

I know that OpenGL and other graphics APIs work with 4x4 matrices internally, however, frameworks built around these APIs often implement Quaternions for rotation and transform them to rotation matrices when needed. (At least this is the way I understood it, feel free to correct me if I'm wrong).

I'm really curious about how many quaternions I need to store for a rotation. I mean, i have 3 axes, but this doesn't mean that I need 3 quaternions, does it?

Staff Emeritus
How do you mean that? A quaternion can be represented by a matrix?
A 2x2 matrix. Computer implementations? Probably not. Almost definitely not. Much more likely is as a 4 vector, or as a scalar (the real part) plus a three vector (the imaginary, or quaternionic part).

I know that OpenGL and other graphics APIs work with 4x4 matrices internally, however, frameworks built around these APIs often implement Quaternions for rotation and transform them to rotation matrices when needed. (At least this is the way I understood it, feel free to correct me if I'm wrong).
Those 4x4 matrices -- here are some appropriate adjectives. Ugly. Inefficient. Kludge. Don't go there.

I'm really curious about how many quaternions I need to store for a rotation. I mean, i have 3 axes, but this doesn't mean that I need 3 quaternions, does it?
Only one is needed. No matter how many times you turn an object, you can always find a single axis and rotation angle that completely describes the orientation of that object in three dimensional space. Always. It's the Euler rotation theorem. Note: This theorem does not apply to four dimensional space and higher. It's special to two and three dimensional space.

There are a lot of ways to represent rotations in three dimensional space. One approach is via 3x3 orthogonal matrices. This approach generalizes to any dimension. Rotations in four dimensional space are described by a 4x4 orthogonal matrix, in five dimensional space, a 5x5 orthogonal matrix, and so on. There's one big drawback to the matrix approach: There are a lot more numbers in the matrix than there are degrees of freedom. A 3x3 matrix contains nine numbers, but there are only three degrees of freedom in rotations in three dimensional space. Only three numbers are needed. A quaternion has four elements, so there's a slight bit of over-specification here. A 3x3 matrix has nine elements. That's not just over-specification. It's overkill.

One way to represent rotations in three dimensional space is via that single axis orientation. You need a unit vector and an angle. Multiply each element of the unit vector by the angle and you have just what is needed, three parameters that fully describe the orientation of an object. Unfortunately, this single axis rotation vector is hard to use and even harder to manipulate. (What happens if an object rotates about this axis by this number of radians, then about that axis by that number of radians? Good luck describing this with that three element single axis rotation representation. It can be done, but it is a mathematical nightmare.)

Unit quaternions are very closely allied with this single axis rotation, only now the mathematics are much better behaved. That problem of rotating about this axis, then that axis? This becomes a product of two quaternions. Any sequence of rotations is a product of unit quaternions.

MikeGomez
Obviously quaternions can be represented by a 4 vector (not a matrix).

When SteamKing mentioned “Quaternions have representations in matrix form”, I believe he meant that a rotation matrix can be constructed using the elements of a quaternion.

Staff Emeritus
One somewhat common representation of quaternions is as 2x2 complex matrices. Physicists use this scheme a lot; the Pauli spin matrices are isomorphic to the quaternions.

Registred
Thank you so much for this excellent explanation!

Only one is needed. No matter how many times you turn an object, you can always find a single axis and rotation angle that completely describes the orientation of that object in three dimensional space. Always. It's the Euler rotation theorem. Note: This theorem does not apply to four dimensional space and higher. It's special to two and three dimensional space.

This was the point I was unsure about - being able to represent every rotation with ONE quaternion is a reason to not use matrices. I'm already trying to implement a quaternion functionality and hope that I won't encounter any problems.

Staff Emeritus