Quaternions & Rotations in 3D Space: What You Need to Know

  • Context: Graduate 
  • Thread starter Thread starter Registred
  • Start date Start date
  • Tags Tags
    3d Rotations Space
Click For Summary
SUMMARY

Quaternions are the preferred method for representing rotations in 3D graphics programming due to their efficiency and ability to avoid gimbal lock. Unlike matrices, which require nine values for a 3x3 rotation, a single quaternion suffices to describe any rotation in three-dimensional space, as established by the Euler rotation theorem. Quaternions can be represented in matrix form, but they provide a more manageable mathematical framework for combining rotations. Developers should utilize existing libraries for quaternion functionality rather than implementing their own solutions.

PREREQUISITES
  • Understanding of 3D graphics programming concepts
  • Familiarity with quaternions and their mathematical properties
  • Knowledge of rotation matrices and their applications
  • Experience with graphics APIs such as OpenGL
NEXT STEPS
  • Research the Euler rotation theorem and its implications for 3D rotations
  • Learn how to implement quaternion functionality using libraries like GLM (OpenGL Mathematics)
  • Explore the conversion between quaternions and rotation matrices
  • Investigate common pitfalls in 3D rotation implementations and how to avoid them
USEFUL FOR

3D graphics developers, game developers, and anyone involved in implementing rotation systems in computer graphics.

Registred
Messages
4
Reaction score
0
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!
 
Physics news on Phys.org
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/
 
Last edited by a moderator:
Thanks for your answer!

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?
 
Registred said:
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.
 
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.
 
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.
 
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.
 
Registred said:
This was the point I was unsure about - being able to represent every rotation with ONE quaternion is a reason to not use matrices.
This is not an advantage of quaternions over matrices. The exact same thing applies to matrices. Every rotation can be represented by a single matrix.
 
There is no reason to implement that. Use an existing library. For that matter, do not sweat over matrices/quaternions - use whatever 3D rotation library works for you. As long as it works, leave it alone. Premature optimization is the root of all evil.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 18 ·
Replies
18
Views
2K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 1 ·
Replies
1
Views
3K