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

Discussion Overview

The discussion centers around the use of quaternions and matrices for representing rotations in 3D space, particularly in the context of graphics programming. Participants explore the differences between these representations, their advantages and disadvantages, and the number of quaternions required to represent a rotation.

Discussion Character

  • Debate/contested
  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • One participant suggests that quaternions are preferred in 3D graphics because they require less memory than matrices and avoid gimbal lock.
  • Another participant argues that matrices are efficient for coordinate rotations and are processed faster by computer hardware.
  • There is a question about how many quaternions are needed to store a rotation, with one participant initially suggesting three quaternions.
  • A later reply clarifies that only one quaternion is needed to represent a rotation, referencing the Euler rotation theorem.
  • Some participants discuss the representation of quaternions in matrix form, with differing views on whether they can be represented as 2x2 matrices or as 4 vectors.
  • One participant emphasizes that every rotation can be represented by a single matrix, countering the argument that this is a unique advantage of quaternions.
  • There are suggestions to use existing libraries for quaternion and matrix implementations rather than creating new ones.

Areas of Agreement / Disagreement

Participants express differing views on the advantages of quaternions versus matrices, particularly regarding memory usage and representation of rotations. The discussion remains unresolved on the best approach to use in practice.

Contextual Notes

Some participants note that while quaternions and matrices can both represent rotations, the mathematical properties and ease of manipulation differ, leading to various opinions on their practical applications.

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 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 7 ·
Replies
7
Views
2K