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

In summary: 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.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
  • #1
Registred
4
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
  • #2
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:
  • #3
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?
 
  • #4
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.
 
  • #5
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.
 
  • #6
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.
 
  • #7
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.
 
  • #8
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.
 
  • #9
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.
 

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

1. What are quaternions and how are they used in 3D space?

Quaternions are mathematical entities that are used to represent rotations in 3D space. They consist of four components - a scalar and three imaginary numbers, and are often denoted as w + xi + yj + zk. Quaternions are used to describe rotations because they have certain properties that make them more efficient and less prone to errors compared to other methods, such as Euler angles.

2. How do quaternions differ from other methods of representing rotations?

Unlike Euler angles, quaternions do not suffer from gimbal lock, which is a limitation that occurs when two of the three rotation axes align and restrict the movement of the object. Additionally, quaternions are more compact and have simpler mathematical operations, making them more efficient to use in calculations.

3. Can quaternions be used for both 3D and 2D rotations?

Yes, quaternions can be used for both 3D and 2D rotations. In 2D space, the z-axis component is not necessary and can be set to 0, effectively reducing the quaternion to a complex number with the real and imaginary components representing the rotation angle.

4. How are quaternions multiplied and how does it relate to rotations?

Quaternions are multiplied by multiplying their components based on the rules of quaternion algebra. This multiplication can be thought of as a combination of two rotations, where the first quaternion represents the current orientation of an object and the second quaternion represents the desired rotation. The resulting quaternion is then applied to the object, resulting in a new orientation.

5. Can quaternions be used for interpolating between two rotations?

Yes, quaternions can be used for interpolating between two rotations. This is often used in computer animation, where smoothly transitioning between two rotations is important. Quaternions can be used to find intermediate orientations between two given rotations, resulting in a smooth and natural-looking transition.

Similar threads

Replies
3
Views
758
Replies
2
Views
793
Replies
7
Views
1K
Replies
8
Views
659
Replies
6
Views
1K
Replies
2
Views
2K
Replies
3
Views
2K
Replies
7
Views
951
  • Linear and Abstract Algebra
Replies
14
Views
5K
Back
Top