Mastering 3D Rotations: Quaternions Explained | Finite Rotation Series (Part 4 of 4)

Channel: Good Vibrations with Freeball Published: 2025-03-04 4,293 words Source: auto_caption
Advanced Mathematics & Geometric Physics

Transcript

cians were introduced by Hamilton in 1843 that's the same Hamilton as in Hamilton's principal Fame and Hamilton was inspired by The Works of oer and Rodriguez who had published his rotation Theory just a few years before this he knew that complex numbers could be interpreted as points on a plane and the multiplication of complex numbers as the rotation of vectors and he was looking to extend this ter rotations in three dimensions by extending complex number Theory into three and ultimately it turned out four dimensions when you realized that the three dimensions were not enough to handle 3D rotations and for some of you who might be confused by what I'm saying let's embark on a quick digression just to talk about complex analysis and how these represent rotations to some of you I recognize that this might be review but just bear with me okay so a digression into complex analysis complex analysis by the way was ultimately formalized by Koshi in 1820 if we consider the complex plane and let's draw the unit circle on that plane we of course have a real axis and imaginary axis now if I consider a point on that plane I can draw a vector from the origin to that point and we can represent that point as a plus bi I where A and B are both scalers and I is known to be the square root of minus1 we can similarly represent this Vector in polar coordinates by describing it as some radius R and an angle from the real axis which we'll call Theta 1 and then by using oil's formula we can write this as r e to the I Theta 1 I could draw a second Vector on the unit circle this Vector we will assume as an angle Theta 2 from the real axis and of course we can describe this vectors e to the I Theta 2 since the radius is 1 now if I multiply these two vectors or these two numbers together I get r e to the I Theta 1 * e to the I Theta 2 and we know the result of this this is equal to re e to the I Theta 1 + Theta 2 and if I were to draw this Vector re I to the Theta 1 + Theta 2 it would look something like this and this has had the effect of taking this Vector R and rotating it to this new position which is at an angle of an additional Theta 2 from the real axis so in effect by performing this multiplication what I've done is I've rotated this Vector R another way of saying it is I've taken this unit vector and the reason it's on the unit circle is if it weren't then in addition to rotating the vector I also would have scaled the resulting vector by changing its magnitude so this was the idea that Hamilton was working on when he wanted to extend this concept to three dimensions so he considered a a complex number A Plus bi I and ultimately realized he had to extend this not to three but to four dimensions hence the name querian so if we call the querian Q we would then have to add CJ plus DK and this is the form of a querian where a is a scalar component and then the remaining three components are imaginary or could be thought of as a vector now if this idea of a scalar component plus a vector sounds familiar having just considered Rodriguez rotation formula this is no accident at this point Rodriguez had all but invented quorans only he never quite called them that and he didn't formalize it into an algebra like Hamilton did but this idea of a rotation amount about a given aess has Rodriguez's idea all over it let's give this a number we're up to 37 and Hamilton it has said wrestled with this idea of how to multiply so-called triples for years and finally one night Hamilton had his Eureka moment this came on October 16th 1843 while walking along the Royal Canal in Dublin the key insight as to how to multiply triples of numbers led him to carving the defining equation into the stones of the broom Bridge across which he was walking at the time and these equations are as follows he knew of course that i^2 was equal to minus1 we know this from complex analysis but what occurred to him on that evening is that j^ 2 is also equal to minus1 and so is k^2 and all of these are equal to I * J * K which is also equal to minus1 and this is the equation that he carved into the bridge now his carving has since faded but today has been replaced by a plaque memorializing the equation and for the last 35 years or so now there's been an annual pilgrimage called The Hamilton walk for scientists and mathematicians where they retrace his walk in the remembrance of his Discovery so again the idea behind Quan is that it's a four-dimensional complex number in fact complex number algebra can be thought of as a subset of querian algebra and again we have a scalar part and we have a vector part now quorans in themselves don't merely describe rotations much as the same way as complex analysis can be used for far more than just rotations but handling 3D rotations is a very useful and convenient feature of quorans I should also mention at this point that the magnitude of a querian much like the magnitude of a complex number or a vector is equal to the square root of its components squared put a box around that and give it a number 38 and catonian really were inspired by The Works of Oiler because of course everything was in those days and also Koshi and Rodriguez as mentioned earlier now this idea of the multiplication of triples can be summarized as follow follows we consider the cyclic order I J K and in the order drawn in this case in a clockwise direction if we follow the arrows and we can derive this as a result of this last part of the equation if I multiplied both sides of this equation by K then over here I would get a k^ 2 which is just minus one and over here on this side I would end up with minus K and what that looks like is that I * J is just equal to K if I go in the direction of the arrows I * J = K well similarly J * k = i j * k = i and you might have guessed it that K * I is equal to J now what happens if we go in the reverse order well then we get negative so J * I is equal to K because J * I I'm going in the reverse order K * J is equal to I and of course I * K is equal to J and an important feature to point out here with querian unlike complex numbers it's one of the things that makes these algebras different is that multiplication of querian is not commutative in the event where we multiply two complex numbers together I can switch the order of multiplication and the product Remains the Same not so in the case of querian order in querian is important when it comes to multiplication not addition however but multiplication we'll call these all number 39 and let's consider consider now the multiplication of two querian we'll call one querian q1 and a second querian we'll call Q2 40 and 41 multiplying these together produces something that is called the Hamilton product why because querian space is otherwise known as Hamilton space so taking 40 and 41 and multiplying them gives us q1 * Q2 and it is as follows so notice we have a Scala part and then we have an i j and k part to it and we find each of these components just by multiplying the Scala parts of each of the querian as a result this calculation the product requires very little computational overhead unlike all the other methods we've presented up until now these do not require any trig functions and for those of you who are not aware trig functions actually add a lot of computational overhead they're relatively slow to perform one of the real benefits of quan is that they process very very quickly and not surprisingly have found a home in 3D rotations of computer Graphics largely for the reason that computers even the slowest computers can process rotations this way very very rapidly also it doesn't require any matrix multiplication which can also be a rather slow tedious process equation 42 and a box around that and let me also just mention at this time for those of you who are like what the hell just happened here I'm really presenting you some of the results without going through all the math detail but for those of you who are wondering how I came up with this equation if I'm multiply q1 and Q2 you do this just the way you would expect to do this where I've got to multiply A1 times each of these components and that's what gives me the A1 A2 A1 B2 I A1 C2 J and A1 D2 k for example when I multiply the components containing i j and k i would for example get a B1 I and a B2 I this would give me B1 B2 * I * I but I * I is minus1 so that's where I get the minus B1 B2 from on the other hand If I multiply B1 I * C2 J that would give me B1 * C2 * I * J but we know I * J is K so there's my B1 C2 K on the other hand if I multiplied C1 J by b2i I would get C1 * B2 J * I remember the order of those are important J * I is minus K so C1 B2 * - K of course the Scala part C1 B2 are commutative I could have written this as B2 C1 but the imaginary or vector parts are not commutative and those need to follow these rules here in equation 39 after this discovery Hamilton spent most of the later portion of his life in fact until his death discovering and inventing Quan theory he published several volumes on the topic one in the 1840s one in the 1850s and another one shortly after his death in the 1860s this last volume ran over 800 pages so This truly is a vast topic and we can't expect to do a real deep dive into it in the few minutes that I'm presenting it here but I want to point out just the Salient features of it and enough so those of you are interested in how it works can get some practical knowledge and querian generally are not used very much in structural mechanics they're used today in all sorts of other areas which I'll present to you in a short while but if any of you would like me to do a separate video where we Deep dive into querian then leave that in the comments below and if enough of you express interest then we can make a video on that for a while after Hamilton's death in 1865 catonian were mandatory pre examination Topic in Dublin and then with the advancement of vector Theory querian fell by the wayside but they reemerged in the 1900s when they were found to be extremely useful both in computer Graphics as I mentioned before but also attitude control of spacecraft Robotics and even quantum theory but more about that later so let's consider how querian may be used to describe rotations in 3D consider a rotation of the form of an angle Theta about an axis U and to keep things even simpler we'll assume that U is a unit Vector that points along the axis of rotation we know how to find unit vectors from any general Vector we just divide the vector by its magnitude and this part is exactly along the lines of how Rodriguez parameterized rotations it turns out to be a very intuitive way of thinking about rotations it's just an angle about a certain direction and Hamilton used the same idea now we can form a quatern as follows we take the rotation angle Theta and we write it in the form of cine Theta / 2 plus sin Theta over 2 times the components of the unit Vector in the i j and k directions as far as why we use Theta over two here and not Theta that requires quite a detailed explanation and it's not something I want to cover in this video if we do a deeper dive video we can talk about it then but the idea is that we've constructed this querian with a scale part and then a vector part which includes the i j and k imaginary or vector components however you prefer to think of that equation 44 then from before we know that the general form of a quan is a plus b i + CJ plus DK and by comparing these two equations we can see that a is cine Theta / 2 so a itself is not the rotation angle but it represents the rotation angle as you can see by this relationship similarly what happens here is that sin Theta / 2 is scaling each of the components of the unit vector by the same amount and the components of that scaled unit Vector are b c and d okay so this is a very clear way of how we take our rotation described here convert it into a querian and find our components a b c and d this is our rotation querian and this querian happens to be normalized why because this is a unit Vector so that's normalized and then if we Square each of the components we get cosine 2 + sin 2 * 1 and we know that cosine 2 + sin 2 is equal to 1 that's a well-known trigger identity let's just make the point that this querian is normalized much in the same way how in complex analysis we used a normalized rotation vector or as we described it a vector that lies on the unit circle so we've done the same thing here only instead of a unit circle we're dealing with a unit sphere here so so we know as a result of this that a 2 + B2 + C2 + d^2 is equal to 1 this gives us a magnitude of 1 I also want to introduce at this time the concept of a conjugate we'll call that Q star and much in the same way how in complex analysis we would say a minus bi we do the same thing here the Scala part remains a and the imaginary part we flip the signs on each of the terms now minus bi minus CJ minus DK this is completely analogous to finding the complex conjugate and let's just make a note here that this is the conjugate of Q number 45 and 6 the magnitude of Q can be found by taking the square root of Q * its conjugate why is that because if we multiply q and Q conjugate we get a * a that's a 2 we get minus b^ 2 here but the multiplication of the I's give us a minus1 so that's a plus b^ 2 similarly we get a plus c^ 2 here and a plus d^2 so Q * Q conjugate is this a 2 + b 2 + C2 + D2 and of course taking the square root gives us the magnitude all right so how do we use this rotation Vector to rotate an arbitrary Vector now in 3D well let's define a vector we'll call it V and it has components VX v y and VZ and what we do is we convert this Vector now into a querian well how do we do that we just assume that the scalar part is zero so vatan I'll call it is equal [Music] to0 VX v y VZ by just using the vector part in the vector part of the Quan and a zero in the scalar part this is something called a pure querian so pure querian is something with a zero scalar part that's its definition 47 and 48 here's how simple it is to rotate a 3D Vector using querian V querian Prime I'll call it the rotated Quan is simply equal to Q * V Quan * Q conjugate we know what q and Q conjugate are from up above we know what V querian is from here and we know from before how to multiply two Quan together so we use that method of multiplying Quan to First multiply the first two and then take the result of that and multiply it by Q conjugate very simple and very quick mathematical operation the result of that will give us the rotated Quan in the form of a pure querian again where I've called the component Zer VX Prime v y Prime and v z Prime to indicate that these are the rotated values anytime that this is a pure querian meaning a zero Scala value the result of this product will always yield a pure querian so you will always get a zero here and then obviously with the results of that we can find our rotated vector trivially by saying that our rotated Vector which will denote V Prime is just equal to the vector components of this rotated querian so VX Prime VY Prime VZ Prime and that is it that's how simple it is to perform a 3D rotation using querian so again we construct our querian this way I remind you that it's a normalized querian this Vector however does not need to be normalized remember in the case case of our complex analysis the rotation Vector was normalized and lay on the unit circle but the vector that we were rotating could be of arbitrary magnitude well it's exactly the same way here Q our rotation querian is on the unit sphere so it's normalized if for whatever reason it's not normalized you could take the querian and divide it by its magnitude but if you're using a unit Vector here then it by definition will be normalized and then we just perform this multiplication that's it that's how simple it is to rotate a vector in 3D number 49 and 50 and 51 and a big red box around it cuz that's our final answer turning the page let's talk about some of the advantages in using querian for 3D rotations first of all this method is immune to gimbal lock which can be a problem when using Oiler angles Catans are also advantageous when it comes to combining rotations and then something that's a very important point in the field of computer Graphics is something called spherical linear interpolation for those of you who use 3D packages such as blender or Maya or Unity or the Unreal Engine for example all of these by default use Oiler angles but under the hood you can use querian too to describe rotations and the idea is that with these tools what often happens is one uses key frames and at these key frames you would set the orientation of a 3D object object and then leave it to the software to interpolate between the key frames a commonly reported problem is that when you do this using oil angles it provides some really weird and inconsistent interpolations there are any number of videos on YouTube that talk about this so spherical linear interpolation is a technique used for smoothing the interpolation between two orientations in 3D space it's particularly important in computer graphics and in robotics and the idea is is that while linear interpolation moves in a straight line between these two points slurp moves along the surface of a sphere which is crucial for rotations because it maintains a constant angular velocity and it produces the shortest path along the sphere's surface another advantage of catonian is the compact representation that they provide and as we mentioned earlier they're very computationally efficient even since the 1950s and using computers with minimal processing power it was found that using querian could produce very smooth 3D rotations so that brings us to the uses of querian we mentioned already computer graphics and Robotics in the context of using slurp but they're also used in aerospace engineering for attitude control of spacecraft they're used in virtual reality and also believe it or not cians have found a home in quantum theory and for all of these reasons and more Quan Theory which had all but Fallen by the wayside in the late 1800s found a Revival in the mid 1900s and Beyond and any of you that use an iPhone for example iPhones use querian for device orientation tracking through their motion senses the core motion framework in iOS uses querian to represent 3D rotation smoothly and avoid gimal lock issues so just about all of you whether you realize it or not are making use of querian every day and with that we've come to the end of this video and not just the end of the video but the end of this minseries but before we go and as I've promised I'm going to go all the way back to the beginning of part one and do a comprehensive review of all four parts where I will summarize and compare the various methods that we've talked about in Parts 1 through 4 okay so starting at the beginning we first started with the oiler angle method and we talked about the fact that Oiler angles invol olved three successive rotations about three different axes by multiplying these rotations together we got an overall transformation for the full 3D rotation we talked about how the rotation sequence is important when it comes to Oiler angles and once we Define a rotation sequence we need to stick to that rotation sequence throughout the modeling process we ended up with a rotation sequence that looked something like this which involved matrix multiplication and a lot of trig functions the advantages of using Oiler angles include that they're simple to understand and very intuitive rotations in terms of roll pitch and Y they're very good for user interfaces for manual inputs or interpretation of rotations such as in CAD software or flight simulators but they tend to be relatively slow to calculate and of course for large rotations we run the risk of the possible gimbal lock condition where we lose a degree of Freedom we also Ong the way spoke very briefly about the difference between instant rotation rates versus Oiler angles or really Oiler angle rates and how these are actually measured about different axes then we considered Direction cosine matrices Direction cosine matrices have the advantage of being very high precision and give you an explicit representation of rotations especially in the case of complex or chained Transformations they're very good for applications like inertial navigation or orbital mechanics where explicit transformation matrices simplify coordinate changes so they are suitable for high precision and long duration computations and they're also directly usable in systems that require Matrix operations the downside of Direction cosine matrices are that they come with a high computational cost and a large storage requirement because you're storing nine different parameters then we took a look at the Rodriguez rotation formula they're very efficient for a single known axis and angle they compute very quickly they require minimal parameters for representation it's just a vector and a rotation angle and it avoids the complexity of matrices and querian in simpler cases its weaknesses include that they're not suitable for general or complex 3D rotations and then that brought us to the topic of querian querian are best for efficient smooth precise rotation in 3D applications it avoids gimbal lock like we see in the oiler Ang method and really the big Plus in the case of querian is the compact storage and reduced computational cost the weakness with querian is that they tend to be harder to visualize and to interpret and that brings us to the end of this video I hope you found something useful in it somewhere if you did and you'd like to support more of this content please go ahead and hit those like buttons below this really helps with the YouTube algorithm or better still click the Subscribe button the Bell icon so that you can be notified of any future video releases if you have any questions comments criticisms or found my video just plain boring I'd like to hear from you in the comment section below as always you can download a copy of these lecture notes from the link in the video description thank you very much for watching and I will catch up with you in the next one