Alison's New App is now available on iOS and Android! Download Now
Virtual Reality
Prof. Steve Lavalle
Department of Applied Mathematics
Indian Institute of Technology, Madras
Lecture – 05
Geometry of Virtual Worlds (matrix algebra and 2D)
I now want to get to rotation and in order to do that I want to generalize a little bit and I want to talk about linear transformations and I am going to drop 1 dimension down and generalize a bit. So, I am going to instead of going directly to 3 D rotations, I am going to talk about 2 D linear transformations. And then I want to talk about the kinds of properties that a 2 D rotation should have because 2 D is very easy for us to understand then when we understand those properties will generalize back up to 3 D and we will see some structure I think that is interesting that perhaps you haven’t seen before.
(Refer Slide Time: 00:50)
So, let us think about 2 D linear transforms; 2 D linear transformations; so, I will just have a 2 by 2 matrix M 1 1, M 2 1, M 1 2 and M 2 2 just 2 by 2 matrix with real valued entries and I have a 2 dimensional point. So, instead of having X, Y, Z I just have X, Y, I am writing it vertically. So, that we can perform matrix operations someone thought it was a good idea to write it that way. So, we consistently and do that in linear algebra.
So, if I perform a linear transformation I get let us say X prime Y prime right. So, in other words I have some point X Y and by applying that matrix I get some X prime Y prime right. So, some kind of transformation has been performed again we are just in 2 dimensions here let us lets, lets write a 2 D coordinate system; Cartesian coordinate system.
(Refer Slide Time: 02:01)
So, I have X axis Y axis and I want to think about simplest case this is the point 1 comma 0 right here and this is the point 0 comma 1, these are the standard basis that we use for Cartesian coordinates all the time and I want to think about what happens to these when we perform our transformations. So, we have M 1 1, M 1 2, M 2 1, M 2 2.
Let us transform this first point here 1 comma 0, right. So, if we transform that 1 0. So, I put the point here, I look at what we get when we perform the multiplication.
(Refer Slide Time: 03:02)
And we get M 1 1, M 2 1, right.
So, I perform this multiplication and it drops off the second column all I get remaining here is the first column by doing this operation.
So, very interesting; so, it looks like when I perform this linear transformation it tells me exactly what happens to the X coordinate axis right. So, basically this column here tells me exactly what is going to happen to the X coordinate all right because I have just taken it exactly of length one I am lined up perfect with this axis. So, it is telling me what happens to this basis element right you may write these as i hat and j hat and engineering and if there is a third dimension you may write these as k hat right these are just the unit basis elements for Cartesian coordinates when you start doing basic vector calculus correct.
So, I am just saying that what happens is with the linear transformation you may have seen this before just pay attention that every column here is going to correspond to what happens to the coordinate axis in its particular place. So, the first column says what happens or indicates what happens directly happens to the X coordinates and if we do similar thing for the Y coordinate M
one maybe write the matrix again M 1 1, M 1 2, M 2 1, M 2 2 and now I put the 0 1 here.
Now, it is how it just nicely selects right I have picked this point here which is representing the Y part the Y basis element.
(Refer Slide Time: 04:38)
Then it just nicely picks the second column 1 2, M 2 2 right.
So, just wanted to point that out right just you may have heard this before somewhere in linear algebra it is very very simple in 2 dimensions to see it happening. So, each one of these columns just tells what happens to be corresponding basis element or the corresponding coordinates. So, if I think like this, then it is very helpful now to take some very simple matrices and look at what they do.
So, let me just make some examples here and again I am trying to set this up I am reminding you about basics of linear algebra most of you have seen before I assume, but I am also going to connect it a little bit later to something more complicated. So, so please bear with me if this is painfully simple. So, so, but I want it to be very clear.
(Refer Slide Time: 05:24)
And then we will get to more complicated things. So, if my matrix now is this and I apply it to my point X Y should be very clear what happens then again I just look at these columns if I apply this to one 0 it is no change, right.
So, if I apply; if I take this matrix and substitute it in here I apply it to 1 0 it remains 1 0 if I apply it to 0 1, it remains 0 1 perfect. So, this is the identity matrix.
So, it has no effect right just think about how it is going to transform this space. So, if I now put something in the space here right. So, now, put some kind of object in here and I start transforming all of the points in it. So, I can transform anything in this space here including a simple triangle of course, I just want to think about what happens to it; this one has no effect well good thing we call it the identity matrix; it should have algebraically no effect.
Let us try another one. So, what if I have 2 0, 0 2, right what will it do in that case it just scales it
right. So, this should stretch along the X axis by a factor of 2 stretch along the Y axis by a factor of 2 simply scales it if I pick one half instead it will shrink it right. So, it is a scaling of some kind and of course, I could put different numbers for different axis and then I will get different kinds of stretchings, right, I can stretch it out along one axis or another that will distort what do we call it the aspect ratio when it comes to monitors and things like that right. So, it will distort the aspect ratio all right negative 1 0, 0 1.
So, what will that give us, right? So, it is a kind of flip right. So, it gives us a mirror image let us say or as an informal way to say it. So, we get a mirror image now that is not something I am going to consider to be satisfying from the perspective of rigid body transformations you should not be able to move a body through space and then say it is been mirror image now right it does not seem like something that happens right. So, so this one's not going to be a legal kind of motion the scaling is also not legal when you move a body through space it should not all of a sudden be a different size.
So, very interesting to think about let us try this one let us do a double mirror image. So, what if I go and see your draw a line here what if I do this I do negative one 0 0 negative one right.
So, what will that do? So, if I flip with respect or did the mirror kind of flip with a symmetry flip I do the flip with respect to the X axis and then the flip with respect to the Y axis after flipping twice I have mirrored the mirror which makes it unmirrored and I have turned this object upside down right. So, very nice.
So, that actually is a rotation because it is upside down and it is not been mirror image. So, this one is rotate by hundred and eighty degrees which when we put our math hats on will use radians. So, so rotate by pi there is some other more complicated ones which we do end up needing somewhere else only outside of rigid bodies, but what would this do? Right, if I apply this transformation. So, now, for the X coordinate it will start increasing as Y gets greater right this X is going to get replaced by X+Y. So, that will have an effect of taking something that is means draw it here I will if I start off with a square.
(Refer Slide Time: 09:21)
It will turn into something like this right. So, it is what it is called a shearing transformation.
So, if I do this I get in X shear and if you want a Y shear you can just go the other way and you get a Y shear which will be stretching upward in the other direction you can have combinations of shears of all different scales and you can have mirror images all of these things combined together is the power of 2 D linear transformations right. So, the question now is if I only want to apply rotations what am I allowed to do; let us just add constraints, let us tear away or delete all of the things we do not like and see what is left how many degrees of freedom do we have if we can make any 2 by 2 matrix we want.
Student: 4.
4, right, just 4 independent real numbers we can put in here and. So, we have 4 degrees of freedom to start with. So, I want to think about it from the elimination perspective I want to eliminate degrees of freedom that I do not want to allow happening and eliminate anything else I might need to be on that. So, that I am satisfied that what I am left with is just rotations, all right. (Refer Slide Time: 10:46)
So, 4 rotations and you know we are still in 2 D what am I not allowed to have. So, I want no and again very informal no stretching of axes. In other words, I want to preserve scale. So, let us start off we have 4 degrees of freedom in this matrix M 1 1, M 2 1, M 1 2, M 2 2, right.
(Refer Slide Time: 11:15)
We have 4 degrees of freedom in it and now I am going to start imposing constraints. So, constraint number one here if I have no stretching of axis; that means, these columns remember I told you what that each column represents the distortion of the axis or the transformation of the axis it must have length one and that the column overall has to have length one.
Otherwise, if you think about it right, the matrix multiplication is just performing a simple dot product or inner product and so, if the magnitude of the vector that you are multiplying with is not normalized then you get a different scale. So, it has to have unit length. So, constraint number one here means that columns. So, have length one. So, in other words when I have this matrix I look at the columns and I must have the case that M 1 1 squared plus M 2 1 squared equals one right. So, I get this constraint right and I must have this constraint here very similarly M 1 2 squared plus M 2 2 squared equals one how many degrees of freedom did I just lose.
Student: 2.
2. So, I lost 2 degree difference I had 4 each one of these circles here I am like you know matching out on the professor marking off points here right at taking off points from your grade. So, let us say you lost one for that you have one degree of freedom less you lost one for that now you only have 2 degrees of freedom left. 2, I want to have no shearing right and I do not like these strange shearing effect that is not natural for rigid body transformations.
So, what it means in that case is that these coordinate axes here right remember each one of these is the transformed coordinate axis they have to remain orthogonal or perpendicular right. So, in basic when you when you multiply vectors together using a dot product or inner product what is the condition you have for that what has to be satisfied for them to be perpendicular 0, right.
So, that is the condition you just have to say that these columns when you take the inner product right because these each one of these represents a vector by itself that says where the coordinate axis is getting transformed to right the coordinates basis is getting transformed too. So, when I take these 2 and take their inner product I get a constraint that looks like this. So, this is the number 2 condition there which is M 1 1, M 1 2 plus M 2 1, M 2 2.
(Refer Slide Time: 14:25)
So, just a dot product or inner product these 2 columns have to equal 0 how many degrees of freedom did I lose their 1; 1 lost 1 degree of freedom one nice constraint here lost one degree of freedom. So, let us say that 1 minus 1, I hope we have some degrees of freedom left alright well the time we are done with us maybe we are done are we done we got down to one degree of freedom and you said it was and you; you and I we all agree that one degree of freedom was appropriate for 2 dimensional rotation. So, how are we done do we have all the constraints or not.
What do you this democratically who thinks we are done and we just say therefore, the majority thinks. So, then we will just finish who thinks we are not done the majority is not sure I think this video ok well there is one more constraint remaining we got the number of degrees of freedom right, but we do we do not tolerate mirror images all right. So, we have to fix that. So, after we impose these 2 constraints the last thing I want to think about now is I want to say no mirror images.
The formal way to say that in mathematics is you need to preserve orientation. So, no orientation changing if you do not pay attention to that then your left handed coordinate system can become right handed all kinds of bad things can happen right. So, we need to preserve orientation alright. So, no mirror images after we perform these 2 constraints it turns out that there is not very many options left for the determinant of that matrix, it can only be 1 or minus 1.
So, it ends up being a beautiful detector of whether or not someone is trying to perform a mirror image right by making that matrix. So, the only thing you have to have happen for the remaining case I will write it over here is to implement that is determinant of the matrix put the whole matrix and there is writing dots, but I should put the ms in there needs to be equal to one not negative one those are the only 2 possibilities left how many degrees of freedom did I lose there.
Student: 0.
0, I did not lose any degrees of freedom. So, what is interesting is that what remains is going to be a circle of possible 2 dimensional rotations before I did not constraint number 3 I actually had 2 circles there is a circle of the standard rotations and then there is a circle of mirror image rotations and. So, this last constraint just eliminates the bad circle the circle that does not correspond to rigid bodies right. So, that is the next kind of interesting question is which matrices remain right because these are going to be the ones that are rotations.
So, after I perform all of this and. In fact, when I look at these equations here that looks somewhat familiar right. So, if I instead of writing M 1 1, M 2 1, if I just wrote that with X and Y coordinates you recognize this as the equation of a unit circle in the plane. So, it is enough to just parameterize this circle and then derive the other 2 parameters of the matrix from the point on the circle. So, that is what turns out to be fairly easy to do and ends up working very nicely.
So, that if I do it in that way then I can just parameterize the circle. So, what I just said there let me do it along here then I just say M 1 1 is equal to cosine theta M 2 1 is equal to sin theta that is
just a standard parameterization of the unit circle all right and. So, a standard parametrization of the unit circle some amount theta I guess my coordinate system in this particular case is the M 1 1 axis and the M 2 1 axis right. So, that is all I have done I am just taking these the first column here and showing that you can parameterize it nicely as a circle.
So, the matrices I get are cosine theta sin theta and now I just do simple substitutions to figure out from the algebra here in these equations in number one and number 2 to figure out the rest of it I get minus sin theta and cosine theta and you can do simple substitution up here for example,
to verify that constraint number 2 is just fine you can easily see that constraint number one is satisfied for the second column this one here because it is still when I square these and add them up I get that famous trigonometric identity sum of squares of sin and cosine is one. So, that happens for the columns the inner product clearly works and adds up to be 0.
So, these are the matrices that remain and a beautiful parameterization has been found by simple recognition that these fall onto a unit circle. So, 2 D rotation ends up being very easy for that reason.
Virtual Reality
Prof. Steve Lavalle
Department of Applied Mechanics
Indian Institute of Technology, Madras
Lecture – 3-3
Geometry of Virtual Worlds (3D rotations and yaw, pitch and roll)
Questions about that. So, I am going to get to the 3D case now, which is the reason why I dragged you through all of this. One very nice property that I want to point out here because it is harder to visualize on 3 dimensions is that, I have used this parameter theta if I change theta by some small amount, say I change by a tenth of a radian or something.
(Refer Slide Time: 00:43)
Then the amount of rotation changes by a small amount right the rigid body will move by a small amount, and it does not matter if I change by let us say if I go from 0 to 0.1 or if I go from one to
1.1 a change of point one corresponds to the same amount of change for the rigid body.
In 3 dimensions for 3D rotation it is very very hard to get that property back, until you know how to do it. But if you were just to design something yourself that has that property so, if I vary my parameters of rotation by a little bit how do I make the variation in 3D rotation be the same amount of little bit. And this is going to be very important if you do something like say design of filtering and tracking method, because you want to measure the errors in your tracking and you want to do that in a consistent way. You know otherwise you will get confused you will think you have huge errors over in this part of the rotation space and very tiny errors over in this other part when. In fact, the errors might be the same in terms of how much the body is actually rotating.
So, that is the kind of difficulties we get into in 2 D very easy to see these things it gets harder in 3D questions about this.
(Refer Slide Time: 01:43)
So, I am going to go to the 3D case. So, now, we go to try 3D rotations I do not think I feel like riding 3 by 3 matrices with a bunch of m s and subscripts and all of that. So, I will just write it with dots inside. So, we have bigger matrices is now, I will just write some dots here and make it fast you can fill in the m s if you like.
So, now I have 9 degrees of freedom for a 3 by 3 linear transformation with real valued entries here. So, we start off with 9 dots and I want to use the same kind of reasoning now, let us give names to these column vectors here. So, I will call this ?1, ?2 ??? ?3. So, I will use that to refer to these columns because if you remember in the 2 D case we kept referring to the columns. So, I would just refer to those as ?1, ?2, ?3 one may also want to refer them as ??, ?? ??? ??, but I am I can be careful if I do not want to make them look like scalar subscripts.
So,. So, just take ?1, ?2, ?3 alright. So, constraint number one what was constraint number one anybody remember?
Student: (Refer Time: 03:01).
See yeah. So, the length of the vector should be 1 and. So, if I take the if I square each of the components and add them up.
(Refer Slide Time: 03:13)
I should get equal to 1. I guess I can just write that using norm notation from an algebra, but if you comfort anymore just square each element add them up. So, the norm of V 1 should be equal to the norm of V 2, should be equal to the norm of V 3, should be equal to 1.
(Refer Slide Time: 03:36)
And. So, we started off with 9 dots, how many did I just lose?
Student: (Refer Time: 03:42).
Three right. So, I lost 3 there. So, I have this reconsider this thing gives me a degree of freedom penalty of 3 you know.
So, I lost 3 degrees of freedom right 2, 2 was this thing about inner products right you have to avoid shearing. So, you have to have the inner products be equal to 0 right the dot products between the columns which columns, do I pick once that all of them all let us see well dot products there is not really a triple way product here right. So, we got to do it in pairs very good. So, we do all pairs from (Refer Time: 04:20) see if re choose 2 is equal to 3. So, there is 3 pairs it does not matter, what the ordering is because dot products do not care about ordering cross products do.
So, I guess I just need to pick the pair s here. So, I say I need to have V 1 dot V 2 equals 0, I need to have V 2 dot V 3 equals 0, and V 1, V 3 right get the other pair. So, I need to have V 1 dot V 3 equals 0.
So, when I put all that together I guess I have lost 3 more degrees of freedom. Hey not bad at doing the same kind of pattern as for 2 D. So, we lost 3 more with these we still have the third condition which is on we do not want mirror images.
So, 3 we need to have the determinant of this take 3 by 3 matrix be equal to 1 and again this is not going to drop the degrees of freedom, this is going to keep it the same it is just going to eliminate half of the cases. In fact, because every mirrored transformation has a corresponding one that is unmirrored, it is getting rid of exactly half of them. So, in the 2 D case as I said there was like a good circle and a mirrored circle, there was the true rotation circle and the mirrored circle.
We now have remaining some 3 dimensional set or 3 dimensional space of rotations we have 3
degrees of freedom we have to get our fingers on it somehow describe it in some good way we have 3 degrees of freedom left and it was in 2 different components there s like the mirrored part and the unmirrored part. This constraint eliminates the unmirrored part. So, if you want to have the mirrored part then just make the determinant be negative one and. So, we are going to avoid that. So, by the time we are done we finally, have which we should have we get all the way down here past 3 constraints.
And we have 3 dots for 3 dots four 3D rotations all right.
(Refer Slide Time: 06:48)
So, I am going to start off with a simple way to describe 3D rotations, and then after that get to the more let us say appropriate way for doing the things that we want to do. So, to start off here and we will take a break shortly, let me just start off here with the 3 canonical the 3 canonical rotations which are yaw, pitch and roll. So, these are going to be 3 independent parameters we can use to describe rotations, they are the most I would say intuitive and easy for people to understand, but they cause a lot of trouble and damage later. So, I am going to first introduce them we can talk about them, they are they are they are helpful if you keep them separated, but when you combine them together you sometimes end up with a mess.
First of all make sure we all know what we are talking about. So, yaw is going to be this right let us all do this together. So, yaw is like this right good then pitch. So, yaw is like no right and pitch is like yes and then roll is like this, which if I understand head gestures around here means maybe you know. So, I am not sure is that right. So, so we have yes no and maybe. So, so let us all do this together. So, yaw say it together yaw.
Student: Yaw Pitch.
Student: Pitch.
And roll.
Student: Roll.
Roll and. So, keep those straight it is very very helpful yaw pitch and roll. So, let me just write out the matrices for these and then we will and then we will break yaw, I will write it like this I will say it is a rotation matrix, with a parameter alpha and it looks like this cosine alpha 0 sin alpha 0 1 0 minus sin alpha 0, cosine alpha. This looks a lot like the 2 dimensional rotation matrix, if you look at the corners and the center part looks a yaw like the identity matrix right. So, the center part looks like the identity matrix because it is basically saying do not disturb the y coordinate.
If I do a yaw back and forth notice that the yeah notice that, the y coordinate is not changing right y is up I forgot my coordinates for a bit here yeah y is upward. So, notice y is not changing when I do this correct only x and z are. So, it is essentially a rotation in the x z plane, that is why it looks like the 2 D rotation matrix. This is a little bit of change with respect to it, but that is because these are appearing in the corner if you do a circular shift downward and over then it will look exactly like the 2 D rotation matrix being applied.
So, pitch is very similar we write R of beta let us say, which which access is left undisturbed for pitch sorry do this x is undisturbed. So, we can already guess that the x part is going to look like an identity matrix, and then here in this remaining part this remaining block we just make the 2 by 2 rotation matrix, but with a beta cosine beta, minus sin beta sine beta cosine beta and then
finally, roll; roll should leave the z coordinate alone then right. So, z is going back and forth z is the depth. So, z goes back and forth when I do a roll I should not be interfering with that, we did alpha beta gamma. So, gamma parameter represent that we get cosine gamma minus sin gamma, sin gamma, cosine gamma. So, the upper block is exactly this 2 dimensional rotation matrix.
But corresponding to the x y plane, and then the z part is the identity 0 0 1 0 0 0 1 right. So, that is what we get and now if you want to generate any other 3D rotation, you just need to pick some amount of yaw, some amount of pitch, and some amount of roll and then you can apply them sequentially and that will generate any rotation, but it might not provide and it. In fact, does not provide a beautiful representation in the sense that I mentioned where a small change in these parameters, may or may not correspond to the same amount of change in actual physical rotation, and that is the difficulties we will be getting to after the break.
Log in to save your progress and obtain a certificate in Alison’s free Introduction to Virtual Reality online course
Sign up to save your progress and obtain a certificate in Alison’s free Introduction to Virtual Reality online course
Please enter you email address and we will mail you a link to reset your password.