 morning let us continue for the next day of lectures. So, one thing I want to remind you of which I finished up last time we were talking about 3D rotations and we went through four different representations. So, there is the native representation of rotations which is the rotation matrix 3 by 3 matrix for the 3D case. And the first thing we gave was yaw pitch roll representation which we talked about these canonical rotations right. We had yaw being looking like a no gesture we had pitch looking like yes and roll being like this. And we also gave you unit quaternions as a better representation and the reason why it was better is because it is very closely connected with another very natural representation of rotations which is axis angle representation due to Euler's rotation theorem that every 3D rotation can be represented as some amount of twist if you like about an axis through the origin. And that is very natural and very helpful when you start doing algebra of rotations you start combining rotations this the algebra of unit quaternions will combine the axes very well. And so, the transformation between these two was very simple right we had a very simple formula for that not difficult at all it is also computationally efficient. Rotations going back and forth between quaternion yaw pitch roll and rotation matrices are a bit more cumbersome. There is a very simple matrix full of quaternion components it ends up being very simple expressions in the matrix. So, it is not too hard to go from quaternions to rotation matrix if you want to go from yaw pitch roll to matrix you just multiply your yaw pitch and roll matrices together. So, that is not very difficult either, but it may be time consuming or expensive in terms of computation you know try it by hand and you will see you know. However, if you want to go from r down to these then you have to do considerable more work it usually involves some equation solving. And then there are sometimes numerical issues because you are essentially finding numerical roots, but it all has closed form expressions there is code for doing that it is not so bad, but you just have to pay attention if you write such code yourself that there are some subtle numerical issues going from r down to here. So, generally because of the the way these work out people very often prefer to remain in this part of the space and not do other conversions right. So, if we can work directly in there then there are a lot of advantages and that is one of the reasons why I gave you quaternion multiplication as an alternative to the matrix multiplication. So, that you do not have to convert to matrices you can just stay complete completely in quaternion land and do your algebraic computations there. In fact, you can go further and do your quaternion transformations there. So, if you want to just I should say you can do your rotations directly using quaternions. So, I just want to give you a quick expression for that I am not deriving the algebra of that here it would take considerable more time, but suppose you have a point x, y, z that you would like to transform I will extend it by 1 dimension. So, I will just write it like this x, y, z, 1 and I will pretend that that is another quaternion. And now if I want to rotate this point x, y, z that is let us say perhaps it is in well just say anywhere in r 3. If I want to rotate this then I get some p prime, but I calculate as q quaternion multiplication with p quaternion multiplication with q inverse. And this q is representing the rotation that I want to apply to the point x, y, z right that make sense. So, in other words let me summarize given q some rotation that I would like to apply it does of course, correspond to a rotation matrix, but instead of converting to that rotation matrix I can directly do this algebra and apply q to p using this chain of two multiplications in order to get out the result. So, the resulting p prime that I get I just read off the first three components and that will tell me the rotated point. So, the quaternion algebra has been nicely defined in a way that makes this work. So, that it gives you the same result, but I am not deriving it here you can look that up on your own. Does that make sense? And you remember how easy it is to make q inverse right. For example, you can just negate the last three components. Speaking of that we had an interesting question last time which I just want to cover. We talked about the double representations of every 3D rotation when you use axis angle. And so, if you have axis v and some amount of rotation theta then if you take minus v I said that it is equivalent to a rotation of minus theta and then when we looked at the formulas for converting from quaternion to axis angle we noticed that there was a sign problem. Well normally if I apply trig functions to some angle theta if I add 2 pi to it the trig functions yield the same result right. So, it seems like it should not matter, but it turns out it does matter for this axis angle conversion formula because it has a term that says cosine theta divided by 2. So, the fact that you are dividing by 2 here means that if you do add 2 pi to it it will give a different result right because you are dividing by 2 before applying it. So, it is better if you are using this formula to write it as 2 pi minus theta. So, that is where that little bit of confusion came in last time and it seemed like the signs did not work right ok. One more thing I want to say about quaternions and then we will get on to the next bit of topics. Remember that we have this two different representations there are two different unit quaternions for every rotation. What could we say about those quaternions? Where are they located on the unit sphere? Opposites right they are called antipodal points. So, one thing that happens is suppose you are rotating your head around and you have some tracking algorithm and it is essentially moving through that space. So, this is let us suppose that sphere that sits in 4 dimensional space it is a 3 dimensional unit quaternion sphere and then as you move your head around you are essentially moving along the sphere somehow right is that an ok kind of visualization. So, imagine the quaternion is changing. So, as a function of time you are moving around this this transformation moves along this sphere. Now, I can in viewing it as a sphere I can imagine it has an equator. So, that sometimes I am in the northern hemisphere and sometimes I am in the southern hemisphere. What does that mean? Well above I could be saying it is a greater than 0 and below I could be saying it is a less than 0 where I remember a quaternion is a b c d. So, I could go moving around and if I am not careful if I start doing lots of transformations like this going back and forth converting I should say lots of conversions. If I do lots of conversions between rotations it may be the case that if I convert one way and come back I might all of a sudden jump to the opposite side of the sphere and I might conclude that something absurd has happened with my tracking algorithm right. How did I end up on the other side? It looks like a huge error, but in terms of rotation it may be exactly right because it just jumped to the opposite point. So, that causes a lot of trouble and confusion sometimes encoding these algorithms and in dealing with these kind of tracking algorithms and a lot of transformations in these spaces. So, some people might like to say I will just prohibit the lower hemisphere for example, I may just say stay away from here right. So, that as soon as you come down the northern hemisphere as soon as a is changing and getting smaller and smaller if it hits 0 you could just jump to the anti-podal point and then continue upward. Does that make sense? So, you can keep it trapped in the in the upper hemisphere the northern hemisphere in this case if you if you view north being a a increasing. So, you can force to change however, there is still some subtleties right when you come exactly to the equator because it is not it is not exactly clear what you could do what you should do exactly on the equator because you can still jump to the anti-podal point along the equator itself and you may have to protect that and divide that in half and so forth as you go all the way down to the final remaining dimension. So, it is a bit complicated at the equator itself, but I just wanted to point that out this 2 to 1 representation that we have sometimes causes confusion if you make very simple tests like how far apart are these 2 quaternions using simple Euclidean distance. They may be in fact very very close together, but they appear very far apart and attempts to fix that will help, but you have to be very careful about them. So, it helps to visualize it on a on a sphere I think and just remember that it is one dimension higher. Questions about that right. So, I am going to move on to the next topic I am getting up to homogeneous transformation matrices today. I want to remind you of a couple of properties of matrices before we get to that which I believe I mentioned last time, but I will quickly mention them again here. If I want to for example, rotate some point x y z. So, I put it in vertical column form and then I apply a rotation matrix to it just write it as r this is what I get right. So, I do this multiplication and I get out the result if I want to then apply a second transform a second rotation to the result of that the rotation comes out here correct. So, if I wanted to first apply the rotations together by multiplying the matrices it is just important to understand right. So, if I instead were to first do these multiplications and then apply the result it is just important to understand that the first one happening is is R 1 getting applied and the second one is R 2. So, it goes in this direction from right to left and since in many languages were very custom reading from left to right it annoys people right. So, it looks like it is going backwards. So, it is just something to pay attention to it is easy to get confused by that and remember the other thing is that if you want to make an inverse of a chain of matrices for example, if I want to have R 1 R 2 R 3 inverse just remember and this is going to become important as we start chaining matrices together and if you start digging into the software R 3 inverse R 2 inverse R 1 inverse and this is very easy to see if I just take my R 1 R 2 R 3 and I apply this inverse next right. So, that is the next thing I apply. So, it is goes on this side. So, if I apply this inverse next here I get R 1 inverse R 2 inverse R 3 inverse and then you can just follow all of these cancellations. So, R 1 times R inverse that should be the identity and then the whole thing collapses together and then these two cancel and then it collapses together and then these two cancel and you just get the identity right. A matrix times it is inverse should give you the identity. So, that is what we get right. So, just remember that just basic property of shows up in group theory which is very general. So, this is the reason why it holds here because of non commutativity we have to be very careful. I will give you a great example of that in just a little bit right. Questions probably seen these things before somewhere, but just emphasizing that they are becoming important now. They may or may not have been immediately useful to you before.