What are the pros and cons of using Matrices, Euler Angles, and or Quaternions for rotation representation? [closed]
Asked Answered
B

4

9

Matrices and Euler angles can suffer from Gimbal lock but what are some other arguments for using one over the other?

What do you think DirectX favors?

What do you use in daily C++/C/DirectX programming?

Benoit answered 4/2, 2010 at 8:12 Comment(4)
Jestro: Reading here: en.wikipedia.org/wiki/Gimbal_lock it would seem that the verdict is to use quaternions. But I have no Direct (pun intended) experience.Fini
@Mitch: This is certainly programming related, anyone who works with 3d graphics deals with these things on a daily basisDefamation
Pretty much any kind of standard 3D API is going to want matrices as input. Most 3D modeling and animation tools seem to represent rotations as Euler angles by default. If you need to interpolate general rotations properly, quaternions make sense and nothing else does. You'll need to convert quaternions into matrices for your API; modern 3D animation tools will doubtless have their own facilities for using them...Charlenecharleroi
Not Programming Related?!?!!! There is NO other context in which this question makes ANY sense than programming! Why do people think that they should comment on things that they are so ignorant of? OMG, this is just freakin embarassing.Peavey
B
15

Euler angles only require three parameters, as opposed to storing a matrix (or three, but that sounds excessive). When you apply the Euler rotation, however, you will possibly end up with something equivalent to three matrix multiplications to create the transformation. If you were only using a matrix, you might not incur such an expensive cost (depending on how the matrix was constructed). Besides Gimbal Lock, there is also a problem with cancellation effects when interpolating matrix representations of rotations that you need to be careful about.

You might want to consider quaternions. They require four parameters of storage, so they are not very heavy. They avoid Gimbal lock and can be interpolated for rendering smooth rotations. One thing that can be interpreted as a downside for the quaternion is that they may not be very intuitive for some. Matrix transformations and Euler angles have a type of roll-yaw-pitch or spin-precession-nutation that is pretty intuitive. Quaternions are more akin to a single rotation about some end-result axis sticking out this or that way.

There are probably cases where someone would prefer one method over the others, so these are just some things to consider when making a decision.

Bonspiel answered 4/2, 2010 at 9:11 Comment(2)
+1. interpolation and solving gimbal lock is why I would prefer quaternions. But the fact that most people seem to use Matrices has its own advantages.Opia
I think it should be noted that Matrices cannot go into Gimbal Lock (they store directions, not rotations).Accolade
M
7

Euler Angles suffer from singularities and are difficult to work with. Matrix representations DO NOT have that problem contrary to a number of answers here. A matrix representation of orientation can suffer from accumulated errors because you're using 9 numbers for something that only has 3 degrees of freedom. Quaternions are very interesting mathematically, but at the end of the day they're really doing a 4x4 matrix multiply.

A quaternion can also be seen as a 3vec that represents a rotation axis and its length is related to the angle of rotation about that axis (sin squared?). The 4th parameter is computed to make the length of the 4vec equal to 1. This interpretation can be converted to an equivalent orientation matrix.

Matrix representation can include scaling information, and can be extended to 4x4 to include position information as well as orientation. You can transform both position and direction vectors using the matrix transform which is not possible using the other two.

You can do an incredible amount of stuff very simply with a 4x4 matrix. Quaternions and Euler angles just do orientation. Yeah, just that one thing. I guess my preference/bias on this issue is rather clear :-)

Medicate answered 4/2, 2010 at 15:12 Comment(1)
In general, I prefer affine transformations, too. But if I was animating something, I'd probably go the quaternion route for interpolation reasons. For scene graph composition, affine transformations sound like the better choice. If someone was writing a rotation tool for a modeler or something, Euler angles might feel more natural.Bonspiel
M
1

Quaternions are by far the hardest to master, but once you understand what they're about you'll find them surprisingly easy to use. I consider them to be a better solution then Euler Angles/Matrix transforms because they deal with a problem that the other 2 solutions don't. The "Gimball lock".

Mien answered 4/2, 2010 at 9:13 Comment(1)
Another post mentioning "Gimbal Lock" as the redeeming property of Quaternions. This is only a problem with Euler Angles, neither matrices or quaternions are susceptible.Accolade
C
0

It's not really related to directx. You can use either method, but arguably quaternions are easier to deal with for animation data. Otherwise you don't have a single standard way to deal with it and therefore it makes it harder to interpret data across programs.

Coz answered 4/2, 2010 at 9:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.