Euler vs Quaternion - What's the difference?
Transcript
it's good to be with you welcome to class outside today we're going to learn about the difference between Euler and quaternion values first thing to know is that Euler is actually not pronounced Euler it does not rhyme with Bueller Bueller instead it's pronounced Euler and it rhymes with spoiler Oiler and quaternions are a series of values that represent the angle between a subject and some reference point this angle is called orientation you can visualize it as where the object is pointing this is what three different orientations for the same object might look like rotation is the process of changing between two orientation it is the movement from one angle to another any set of Euler or quaternion values represents a single orientation these values can be used to interpret a rotation from some reference point that rotation may not be the one you expect usually it's best to only think about these values as the orientation they represent so why do we have two ways to represent the same thing well they both have their own benefits and consequences the most obvious difference is that quaternion has four values and Euler only has three that's because quaternity represents four dimensions an Euler only has three dimensions Euler values are usually a lot easier to think about after all we see the world in three dimensions so adjusting something along one of three dimensions X Y or Z can be easy to understand in four dimensions we have x y z and also W in quaternions W is the fourth dimension and it does not represent time it represents something called the scalar value four-dimensional math is complicated and really difficult to visualize with three-dimensional eyes so if Euler values are easier to visualize and to talk about why don't we just use those well any times we do Euler values are currently the default way rotations are displayed in many popular programs what makes them less easy to talk about is that Euler values are concerned with the sequence of rotations in Euler order matters we can see this in action if we increase the x value and then the Y value we get this if instead we increase the y value and then the x value we get this quaternions do not care about order therefore every set of quaternion values represents one and only one orientation order and Euler don't just make reading the values less useful it can also make two values mean the same thing [Music] how does that even happen we can visualize Euler order by using three nested rings around an object the innermost ring is the first value and the outermost is the last each ring rotates and when it does it affects everything inside of it let's do the X and Y changes again if the innermost ring is X and the middle ring is y this is how they rotate and if the innermost ring is y and the middle ring is X this is what will happen it looks just like before now do you see how some of the Rings lined up this happens whenever the middle value rotates 90 degrees if we were to rotate the outermost ring we get the same change as when we increase the value for the middle rate so two values now represent the same thing we basically lose a whole dimension of rotation because Euler cares about order the three ring structure is called a gimbal the problem when two rings line up is called gimbal lock gimbal lock reduces the ability to rotate and makes it harder to work with Euler values gimbal lock doesn't really exist unless you're inside a gimbal the phenomenon is only concerned with Euler values the 3D World never really loses an axis it can't the math behind Euler values cares about order and the gimbal rings are just a visual tool to show us that when we care about order things can get weird if a spaceship rotates sideways and then up it won't lose any ability to rotate Real World objects don't exist inside gimbals except actual gimbals if we try back those rotations using Euler values we will see those values quickly become harder to interpret rotating around the world's x-axis rotates the object around the y-axis visualizing the gimbal for this might look even more strange so this is another Plus for quaternions they do not experience gimbal law as we have seen so far Euler values and quaternions can both Define every orientation quaternions do it with 4D math that's sort of hard to visualize Euler values have an easier to visualize concept You could argue that it's even easier to visualize when it removes a degree of rotation whether we use eulers or quaternions they both result in an orientation it's common to take multiple orientations and animate the changes between them Euler and quaternion values affect how the rotation between two orientations will be interpreted when math is used to interpret between two points over time we call that interpolation if we give a domino the starting orientation standing up in the second orientation lying down we can animate between these states the 3D software uses math to determine what each orientation should look like while the Domino moves the results for how this will look and change between Euler and quaternion some rotations will look the same like the Domino some will look different in this example we will display our orientations in x y z Euler values our first orientation will be the starting position our second orientation will increase the x value 90 degrees our third orientation will increase the Y value 90 degrees and our fourth orientation will subtract 90 degrees from the EXO the first interpolation works great just like the Domino the second interpolation looks clean too the third one is where things get weird this again is because Euler angles must be ordered and this changes the map and again because quaternions are not ordered they smoothly interpolate between each orientation let's take a look at one more animation a backflip here's the starting value the finishing value will be 360 Degrees around the x-axis here's what it looks like when calculated using x y z Euler values easy Euler can work pretty well when only concerned with one axis let's see how the quaternion interpolation looks it won't move at all this is because when you interpolate with quaternions it will always take the shortest path since a full backflip returns you to the same orientation the quaternion values do not need to change to reach the final orientation they're already there if instead we did an incomplete backflip and only went 270 degrees the interpolation wouldn't go all the way around it would go directly to the nearest Value the scientific name for this is called spherical interpolation basically when using quaternions each orientation for your animation needs to be less than 180 degrees so for a proper backflip we could Define an orientation at 100 degrees and another at 200 and now the spherical interpolation or slurp for the quaternion will look like this it now cleanly changes orientation around to the backflip overall Euler and quaternion values describe the same thing orientation as we have seen they do it very different Euler values are 3D and can be much easier to visualize and talk about because Euler values are concerned with order and suffer from gimbal lock these quickly become less easy to see and to discuss on the other hand quaternions are four-dimensional and really hard to visualize however they are not concerned with order and you won't lose any degrees of rotation when moving between orientations we see that Euler values can more easily do a backflip what we also see is that complex interpolation leads to strange changes for Euler value attorneys do not experience these regardless of what you use in software like blender or Unity you should mostly avoid changing the values directly and instead rotate the object around the world axis and let the values adjust themselves so what should you use if you don't personally need to know the numbers and you can just rotate around the world axis then you should work with quaternions and remember to keyframe each orientation less than 180 degrees apart if you do need to know the numbers still work in quaternions and when you need to see those numbers use a function to convert the quaternions to Euler values and look at that together we have learned the differences between Euler and quaternion values please have a great day and thank you for attending class outside