 ok let us continue onward. So, we have 3 canonical rotations as I said last time yaw pitch and roll and um these are the 3 dimensional rotation matrices that achieve each of these. So, yaw is rotation about which axis though the y axis. So, it is rotation about that axis which means that it leaves the y coordinate alone and is a rotation that seems to occur in the x z plane. Similarly pitch is rotation about the x axis and roll is rotation about the z axis. So, with these 3 matrices you can put them together sequentially to get any rotation you like. So, if you want you just get any 3D rotation r by chaining these together rotate r alpha rotate r beta rotate r gamma. So, you end up with a result and if we constrain alpha to be between minus pi and pi um alternatively goes 0 to 2 pi if you do not like negative angles and beta to be between minus pi over 2 and pi over 2 and gamma to be between minus pi and pi again. So, if we impose these constraints then we can still reach every possible 3D rotation by picking some alpha beta and gamma and applying these rotations together in a chain. So, we can reach all of them. So, this is some kind of parameterization of the space of all rotations and it is very nice because it is very easy for us to understand what yaw pitch and roll mean. These are also sometimes called Euler angles there are many other ways to obtain Euler angles there is different variations. This one is the maybe is the simplest and easiest to understand. Note that the range for beta is not minus pi to pi, but I cut it in half because if I allowed it to go from minus pi to pi I will actually get a double representation it is a little bit too much. So, so the furthest extreme I want to go to with pitch is looking let us say straight up or straight down if the head is the thing that we are rotating which it is for a head mounted display if we are doing tracking for that. So, this turns out to be enough right. So, now I want to talk about some of the problems or difficulties with 3D rotations some of the issues. So, even though I can reach any rotation like this the order in which I apply these affects the outcome. So, that is one of the first problems that order matters. In other words 3D rotation is not commutative 2D rotation is commutative right all we are doing is combining a bunch of rotations let us say by theta, theta 1 plus theta 2 plus theta 3 it does not matter you can put your theta is in any order you like for a 2 dimensional rotation they are all rotating about the same axis it does not matter. Now, we are rotating about potentially different axes 3D rotation is commutative if all of your rotations are about the same axis, but because it can be rotating about different axes you end up with some kind of trouble. Let me give a very simple illustration with this block head this by the way I have a sentimental has sentimental value for me I bought this in Finland when I was doing a head tracking for Oculus in the very early days when the company was only a couple of months old and we did not quite have a full headset yet. So, I just have the one of the original sensor boards taped to this and then I would perform rotations with my hand to try to see if the tracking software was working correctly and then eventually we got a headset and was able to do more and more. So, let me try this let us try to do two rotations in one order and then do it in another order and see I will do two rotations by 90 degrees and each one of these if I perform one of these rotations I sort of imagine that I am grabbing some kind of skewer or metal rod that goes through the object and I grab onto it and twist. So, a pitch will be like this a yaw will be like this and a roll will be like this all right. So, let us see. So, let us first do a pitch by 90 degrees. So, I pitch by 90 degrees the face is looking up and now I which one is this roll I roll by 90 degrees all right. So, in this case see where the face is. So, it is looking to the side the top of the head is towards the board right. So, now I want to do a roll first. So, I grab here and I roll by 90 degrees and then I pitch by 90 degrees and now the face is pointing up right in the top of the heads that way very easy illustration right of non-commutativity of 3D rotation. I got two different results by applying these two essentially these two matrices right I applied a pitch and a roll in different orders and I got different results. So, everyone agrees you do not have commutativity if you mix these things up if you start changing the orders of your matrices around you are not quite sure what you are doing you will end up with a mess somewhere at the end trying to debug your code with all kinds of matrices in the wrong order and it ends up being very frustrating. So, if you understand it and get it right the first time you will be in good shape. There is another problem which is called kinematic kinematic singularities and a little more generally non-uniform representation. So, this is what I was talking about before in two dimensions you can vary theta by some amount and the amount of rotation of the object in physical space will vary by a consistent amount right it will be it will be the same regardless of you know how you rotate you vary theta by some amount and it does not matter what the original orientation was of the object that you are rotating it will it will vary by the same amount. If you start varying Euler angles you will not necessarily end up with a consistent amount of rotation that corresponds proportionally to the amount of variation that you did in alpha beta or gamma. Let me see if I can give a very simple explanation of this. The first thing I want to explain is what I mean by this kind of non-uniform representation. Well we have a very simple example that you may be familiar with if we look at the top of the earth and I imagine lines of longitude right. So, suppose we are at the north pole looking down on the top of the earth and then I have lines of latitude that go around like this right. So, today we are all located very close to the equator right. So, if I use latitude and longitude coordinates for our position around here on the earth it feels very much like being in the plane right just using x y coordinates right. We could say the y coordinate is latitude the x coordinate is the y coordinate is latitude and the x coordinate is longitude and everything seems fine. If I get all the way up near the north pole now if I just vary you know I start moving a tiny bit around the north pole my latitude is changing by a lot correct. No whoops got the wrong one the longitude is changing by a lot my latitude maybe is not changing at all if I am walking in a tiny circle around the north pole. So, along one direction you might think in terms of coordinates because the longitude is changing very quickly that I am moving a lot, but you know you are actually not it is a distortion because of the way that you have parameterized your position on the earth. So, the same kind of thing is what is happening when you pitch and you get very close to these boundaries when you get very close to plus or minus 90 degrees it turns out that very large changes in the parameters may correspond to little or no change in the orientation and that is quite confusing that makes sense, but it is one dimension higher and very hard to visualize. I think I will do a very quick algebraic demonstration of it, but beyond that it is going to be hard to visualize because this is a three dimensional surface that essentially lives in nine dimensional space right because we started with 3 by 3 matrices and we applied a bunch of constraints. So, there is three dimensions left some kind of strange surface and somewhere in that strange surface if I choose to parameterize it badly I end up with a bad point that is a lot like the north pole ok. Let me see if I can show you algebraically what is happening. So, let me let me imagine chaining these matrices together in some order right. So, I will just expand these out this is very closely related to the problem of gimbal lock you can look that up if you like as well which is known by people in aerospace the mechanical manifestation of this problem alright. So, with my example let us suppose I multiply this out 1 0 0 0 cosine alpha minus sine alpha 0 sine alpha cosine alpha I am going to use a very shorthand can shorthand convention here and just write C for cosine and S for sine otherwise it will take too much time to write them all out. So, I am just trying to give you a very quick example. So, if I multiply these matrices out here is the beta now the gamma matrix right. So, I have this chain of matrices right and I and we have said that we can reach any 3 dimensional rotation by doing this sequence of rotations of the canonical rotations of your pitch and roll.