46

Hi
What is the pros and cons of "Quaternions" and "Euler Angles" Method
- Which one is faster?
- Which one need less Computational Effort?
- which one is more accurate, (in round off error)?

Colin Desmond
  • 4,824
  • 4
  • 46
  • 67
mrbm
  • 1,136
  • 1
  • 12
  • 36
  • 2
    personally I prefer using matrices – David Heffernan May 14 '11 at 14:52
  • I found this my self [http://biomch-l.isbweb.org/threads/11415-Summary-Quaternions-vs.-Euler-angles](http://biomch-l.isbweb.org/threads/11415-Summary-Quaternions-vs.-Euler-angles) But its some obscure – mrbm May 14 '11 at 15:21
  • @David quaternions are represented as matrices. – Ross May 15 '11 at 06:15
  • @ross I mean rotation matrices – David Heffernan May 15 '11 at 07:38
  • Thank you all, - which one is more accurate, (in round off error)? I think Quaternions is faster and more accurate, so why some one may uses Euler Angles? – mrbm May 15 '11 at 09:24
  • I think Quaternions are not used because they are difficult to interpret, Is this right? – mrbm May 15 '11 at 09:42
  • 2
    @mrbm Could be. But just do not let it confuse you with it's "3-dimensional complex number" explanation. Just take it as is. Except for the multiplication by sin and cos it's just another representation of rotation axis and angle, but in a more efficient way (with the encoded sin/cos) to facilitate fast multiplication and matrix conversion. – Christian Rau May 15 '11 at 11:50
  • @mrbm I have named one reason for using them (euler angles) in my answer, but that for me is the only reason where they make sense, as they just have too many disadvantages. Often people prefer them for their more human-understandable form, but that is really the only advantage of euler angles. – Christian Rau May 15 '11 at 11:54
  • @Christian Rau : Ok, thank you again. I think I got my answer. – mrbm May 15 '11 at 12:03

6 Answers6

39

Euler angles are more human understandable and also good for decomposing rotations into individual degrees of freedom (for kinematic joints and the like) but have disadvantages like ambiguity and gimbal lock. In practice I would prefer quaternions, as they are easier to compute with (for the computer, not for humans) and more efficient. You have to make three rotations and multiply them together when rotating by Euler angles, whereas a Quaternion is only one rotation and as it already encodes the sin and cos, the conversion from quaternion to matrix is quite efficient.

Christian Rau
  • 45,360
  • 10
  • 108
  • 185
16

Quaternions avoid Gimbal lock. More here.

YXD
  • 31,741
  • 15
  • 75
  • 115
  • Thank you for link, It seems useful, I am on it – mrbm May 14 '11 at 15:24
  • I can conform this. Used quaternions in Molecular Physics simulations and Gimbal lock is the main reason to use them. This makes one numerical problem less. – Ross May 15 '11 at 06:14
11

Expanding a bit on a point from Christian Rau's answer:

There's an ambiguity in the specification of Euler angles: which angle applies to which axis? Code that uses the convention (yaw, pitch, roll) won't interoperate with code that assumes (roll, pitch, yaw), and it may not be obvious, from looking at the code, which interpretation is being used.

Quaternions don't suffer from this ambiguity, since they only represent a single rotation, with a well-defined axis.

Jim Lewis
  • 43,505
  • 7
  • 82
  • 96
  • 4
    I also meant the ambiguity, that different angle triples (of a single convention) can refer to the same rotation. – Christian Rau May 14 '11 at 16:30
  • 2
    This needn't be the extreme gimbal lock case, every rotation can be represented by multiple euler angle triples, even in the same convention. – Christian Rau May 14 '11 at 16:35
7

Quaternions have many advantages over Euler angles, as pointed out in the other answers. However, Euler angles do have one advantage over Quaternions:

Euler angles can tell you the direction and magnitude of a rotation. When you convert a Euler angle to a Quaternion, that information is lost. For example, the Euler rotations of (-270°, 0, 0) and (1170°, 0, 0) produce the identical Quaternions (-0.7071, 0, 0, -0.7071).

Fax
  • 384
  • 2
  • 9
  • 2
    Yes no one knows this basically. Internally one should always store orientation values as Euler Angles to prevent this information loss. Only temporarily convert that value into a quaternion to do other calculations. Should you ever need the Magnitude of Yaw from an orientation and you only stored the Quaternion in memory give it up... that information is lost to you forever. This is a definitive benefit. – Brian Yeh Jun 12 '21 at 20:10
  • This is a very situational advantage though. If you have an application where there is the need to keep track of how often you've rotated about an axis (for example due to winding numbers or something) then you would probably not take care of this with euler angles anyway. – Blackclaws Feb 04 '23 at 14:18
  • @Blackclaws That may be true, but you'd still use something other than Quaternions. Otherwise you'll be faced with the same problem as trying to determine RPM from video footage - once you rotate more than half a revolution in one frame, there's no way to tell which way or how fast anymore (assuming infinite shutter speed). – Fax May 05 '23 at 18:28
3

Euler angles are better than quaternions. You should always store Euler angles in memory and use quaternions only for calculations. Nobody knows this but what I say is absolutely true. If you're lurking around, know that this is important. Hear me out.

The reason is because you can always easily derive a quaternion from a Euler angles. The conversion is trivial. However the conversion from quaternion to Euler angles is fundamentally broken. There are two possible Euler angles for every quaternion and you cannot know which of the two possibilities your quaternions came from.

For virtual worlds and 3D games you can always just use quaternions. This is because your computer can just draw a picture of the object at an orientation without actually yawing and pitching an actual physical gimbal to achieve that orientation. However for robots and other real world applications there is real information loss when converting to a quaternion.

If you have a real physical gimbal and you are given a quaternion that represents the orientation of that gimbal you absolutely cannot ever extract the original yaw, roll or pitch the gimbal used to achieve that orientation UNLESS the gimbal is restricted in it's range of motion somewhere.

Remember this. If you're in robotics or some mechanical setting save the orientation value as the original Euler angles. Only convert to quaternions temporarily only for a calculation.

There's basically no return trip back to Euler once you convert to quaternion. So don't make that trip permanent, store all your information as Euler angles.

Brian Yeh
  • 3,119
  • 3
  • 26
  • 40
  • 1
    While I find your answer useful and informative, I still don't think that it makes Euler "better" than quaternions. If anything I'd say Euler has its uses and it *could* be better in some scenarios. Even in robotics you can get away without them, and the only place where it'd make sense to use them would be when controlling a physical gimbal, as you mentioned. – Trap Jan 26 '22 at 10:00
  • @Trap I should say Euler angles are better for storage or data transfer. Temporarily convert to quaternions for calculations and transforms but for data storage keep it as a Euler angle. – Brian Yeh Jan 27 '22 at 17:41
  • @BrianYeh Stating that the conversion is trivial is not quite true. There are 4 cosines and one sine involved in the calculation which, depending on your use case, might take quite a long time to calculate especially if you have to do it often. In the use case of a single robot with 3 joints this might not be significant however. – Blackclaws Feb 04 '23 at 14:20
  • @Blackclaws actually coming back to this question a year later. Pitch is limited from -180 to 180 deliberately in the official definition of euler angles to prevent this problem from occurring. That means only one euler angle represents 1 orientation. This makes my statement wrong from the perspective of how a euler angle is officially defined. However if your robot has joints that exceed the artificial limits imposed by the official definition of euler angles then this problem still applies. And yes I see what you're saying as well. – Brian Yeh Feb 15 '23 at 20:00
0

Euler angles is faster.

Euler angles requires less computational effort.

Quaternions are absolutely more accurate.

There is a problem called Gimbal lock which was found in Euler angles. It happens when two axis align together. On the other hand quaternions are more flexible and solved this problem as it is more axis oriented. Yet, it is complicated to understand.

Well, to make it easy to understand Quaternions. Let's divide the four components to two: An angle and x,y,z point that is connected to the origin of the axis say P. The (x,y,z)-P line representing a new axis. The angle represents the angle between the axis and real orientation. To visualize this answer you need to check this 5-minutes video. https://eater.net/quaternions/video/intro

M.Noufale
  • 55
  • 5