If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

Linear transformation examples: Rotations in R2

Linear Transformation Examples: Rotations in R2. Created by Sal Khan.

Want to join the conversation?

  • male robot hal style avatar for user Christiansen Lawhorn
    I'm a bit confused. The unit circle definition of trig functions shows that the Y-coordinate is acquired with sin, and the X-coordinate acquired with cosin. Why on the second vector was the X-coordinate set to -sin? Couldn't just cosin be used here to get the X-coordinate?
    (6 votes)
    Default Khan Academy avatar avatar for user
    • aqualine ultimate style avatar for user Kyler Kathan
      On the unit circle, you start from the point (1,0) and move counter-clockwise. That's exactly what he's doing around when he rotates e1. However, when he's rotating e2 at , he's starting from the point(0,1) and going counter-clockwise, making it different from the unit circle.
      (8 votes)
  • primosaur ultimate style avatar for user Lucas Muehleisen
    Why is A ( the transformation matrix) simply the columns of the transformation of the unit vectors?
    (4 votes)
    Default Khan Academy avatar avatar for user
    • aqualine ultimate style avatar for user Kyler Kathan
      Given A x⃑ = b⃑ where A = [[1 0 0] [0 1 0] [0 0 1]] (the ℝ³ identity matrix) and x⃑ = [a b c], then you can picture the identity matrix as the basis vectors î, ĵ, and k̂. When you multiply out the matrix, you get b⃑ = aî+bĵ+ck̂. So [a b c] can be thought of as just a scalar multiple of î plus a scalar multiple of ĵ plus a scalar multiple of k̂. So anytime we want a transformation to do something to any point [a b c], we just need to rotate and scale the basis vectors. The point that's a scalar multiple of them will also follow the same transformation. So when you transform the identity matrix into your transformation matrix, what you're really doing is changing the basis vectors to match your intended effect. I hope that was clear enough to make sense.
      (9 votes)
  • blobby green style avatar for user jefferson111
    I am still confused how when finding x you subtract the y axis sine from the x axis cosine and vise versa. Please help me understand this.
    (5 votes)
    Default Khan Academy avatar avatar for user
    • blobby green style avatar for user InnocentRealist
      Sometimes it helps to review the basics. Try this:

      1) If we can get a transformation matrix that works for both i = (1, 0) and j = (0, 1), that matrix will work for any vector. Why? I don't know, but he's been telling us this for quite a while.

      2) Sketch i and its rotation u by angle t, and then j on a separate xy plane with its rotation v by the same angle t.

      3) Find the coordinates of u (u1 and u2) and v (v1 and v2) from trig (the hypotenuse or the length of both u and v is 1. Try to answer this by yourself. i and j are rotated by the same angle, but the angles are in different quadrants, and the angle of v is 90 plus t, but (and this gets to your question) v1 and v2 need to be expressed in terms of t, just like u1 and u2, not 90+t.

      4) (u1, u2) = (cost, sint) and (v1, v2) = (-sint, cost).

      5) If you make a 2x2 matrix A whose column vectors are u = (cost, sint) and v = (-sint, cost), then A*i = 1*u + 0*v = u, and A*j = 0*u + 1*v = v, which is the transformation we're looking for.
      (3 votes)
  • female robot grace style avatar for user Markusdrealan7
    When I have an image in paint and I rotate it 90 degrees, is some type of code like this running? Or are there are other ways to do this? (On a windows computer, by the way).
    (3 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user Stefan James Dawydiak
    When Sal talks about rotating the square, doesn't he actually mean rotating the vectors defined by the DIFFERENCE between the vectors defining the square's corners, and not those vectors themselves? I believe this is how he defined the triangle he transformed several videos ago.
    (2 votes)
    Default Khan Academy avatar avatar for user
    • leaf green style avatar for user Anton Molina
      By considering the difference between the vectors, Sal was trying to show how linear transformations affected a given set, namely the line formed by the difference between two vectors. However, conclusion was that the only part that really mattered after the transformation was where the endpoints of the three position vectors that formed the triangle ended up. While both points of view are valid, working with the vectors themselves is considerably more simple to think about.
      (8 votes)
  • blobby green style avatar for user jturcotte166
    I suppose it isn't a coincidence that the determinant of the matrix Sal created is 1:
    cos(theta) x cos(theta) - (sin(theta) x -sin(theta)) =
    cos^2(theta) + sin^2(theta) = 1.

    Is there a reason for this?
    (3 votes)
    Default Khan Academy avatar avatar for user
    • spunky sam red style avatar for user Bernard Field
      There is indeed a reason for that. For a transformation, the determinant is the amount by which the area of some transformed object is changed. If we had a determinant of 2, this means we double the area. If we have a determinant of 1, as in this example, then the area stays exactly the same.

      (As a side note, if you have a negative determinant, you inverse the handedness of your vectors. A right-handed system has the x axis clockwise from the y axis. If you find that your x-unit vector gets transformed to be counter clockwise of the (transformed) y unit vector, then you have swapped the handedness, and thus get a negative determinant.)
      (4 votes)
  • leaf blue style avatar for user Ayman Munassar
    Is there a relation between what Sal has done in this video and "Integration" and "Differentiation"
    (3 votes)
    Default Khan Academy avatar avatar for user
    • leaf blue style avatar for user Matthew Daly
      It's an interesting connection to make. But if there is a connection between the two notions, I can't figure out what it would be.

      Here's the connection I make. If we imagine that x in the unit vector rotated by an angle of φ, its coordinates will be (cos φ, sin φ) like Sal was showing in this video. Now if we apply the transformation of a rotation by angle θ, the resultant vector would be (cos (φ+θ), sin (φ+θ)) which is the same as (cosφ cosθ - sinφ sinθ, sinφ cosθ + cosφ sinθ). So what 2x2 matrix A satisfies A(cos φ, sin φ) = (cosφ cosθ - sinφ sinθ, sinφ cosθ + cosφ sinθ)? Well, it would have to be exactly the matrix A that Sal came up with in this video. So, to me, the formula is really strongly connected to the sum formulas for sine and cosine. Hope that helps you to get an intuitive feel for it (and maybe help you memorize the matrix as long as you've already memorized the sum formulas). ^_^
      (4 votes)
  • leaf green style avatar for user Tabitha
    Can someone provide the worked out multiplication of:
    Rot45° (→x)= [√2/2, √2/2, √2/2, √2/2, ] →x
    This is the last equation Sal wrote starting at . I am new to this material and I am still confused by the notation involved in dot product as opposed to regular multiplication/distribution. For example, Sal wrote the formula starting at as:
    [cos⩉, sin⩉, -sin⩉, cos⩉] is multiplied by "[x1, x2]"
    rather than multiplied by "→x" as in the final example I referenced at the beginning of this post and I'm not quite clear on how those are interchangeable or when a • stands for dot product and when it means multiply. Thanks!
    (3 votes)
    Default Khan Academy avatar avatar for user
    • piceratops seedling style avatar for user Raynette
      So a very neat thing about matrix multiplication is that it actually is just the dot product of the rows and columns of the matrices you are multiplying together. Maybe this will be able to explain it better:
      http://mathinsight.org/matrix_vector_multiplication
      Also [x1, x2] are just the vector components of the vector x.
      For the Rotation example, let's say you have a square with vertices at the points [(0, 0), (0, 1), (1, 1), (1, 0)] then to find you new rotated square (by an angle of 45 degrees) multiply the transformation matrix with each of these points. The new postions will be [(0, 0), (-sqrt(2)/2, sqrt(2)/2), (0, 2*sqrt(2)), (sqrt(2)/2, sqrt(2)/2)]. If you draw that you'll see that the method worked!
      Hope this helped you. :-)
      (2 votes)
  • old spice man green style avatar for user KeynesNewton
    I understand the rotation of (1,0) and (0,1). But is there a good geometric visualization why the x-component of (1,1) becomes cos(x)-sin(x)? I tried to draw it, but couldn't figure it out.
    (2 votes)
    Default Khan Academy avatar avatar for user
    • blobby green style avatar for user InnocentRealist
      I feel you. This transformation works for any vector and for any angle, but the only ones I have any "spatial" understanding of are i and j.

      I can tell you this - that since T(x) + T(y) = T(x+y), then A(i+j) = Ai + Aj = (cost, sint) + (-sint, cost) = (cost-sint, sint+cost). It seems that the transformation of the sum of the 2 unit vectors = the sum of the 2 column vectors of the transformation.

      Wait... If you sketch i+j, then sketch a rotation of i+j, you can see clearly that T(i+j) is T(i) + T(j) (at least it seems like that to me). So this gives visual support for the specific formula for rotating i, j, and "i+j = (1, 1)", your question.
      (3 votes)
  • blobby green style avatar for user brownstone
    But you had 1,0 and 0,1, so when you apply the rot(col1) and rot(col2), why don't the zeroes cancel out the second entry in col1 and the first entry in col2?
    What is the reason of using the identity matrix? It had no impact or application.
    (2 votes)
    Default Khan Academy avatar avatar for user
    • blobby green style avatar for user amjadian.e
      Great question. The rotation/transformation is indeed applied to each standard basis just as done before. The difference is in the past some of these transformations involved multiplication and that's why some entries zeroed out before. The idea is to apply the transformation to each column of the identity matrix to create the transformation matrix A and Not necessarily to multiply unless the transformation is T: x-->2x for example. And when you apply the rotation to the vector [1, 0] you get [cos_theta, sin_theta]. And at that point you have applied the rotation transformation successfully to the first column of your identity matrix. In short the idea is to apply the transformation to each column of the identity matrix and when you do you will get the trigonometric values mentioned in the video. I hope this helps.
      (1 vote)

Video transcript

Let's see if we can create a linear transformation that is a rotation transformation through some angle theta. And what it does is, it takes any vector in R2 and it maps it to a rotated version of that vector. Or another way of saying it, is that the rotation of some vector x is going to be equal to a counterclockwise theta degree rotation of x. So this is what we want to construct using our new linear transformation tools. And just to make sure that we can actually even do this, we need to make sure there's an actual linear transformation. I'll just do that visually. I actually don't even have a mathematical definition for this yet. This is about as good as I've given you. So let me just draw some really fast axes right here-- I have to draw them a little bit neater than that-- so that's my vertical axes. That's my horizontal axes. I could call this one the x1 and I'll call this the x2-axis. In the last video I called them the x and the y. This is the first component of our vectors. This is our second component in our vectors, and so if I have some vector x like that, we know that a counterclockwise rotation of this will look like this. I'll do the rotations in blue. It will look like this, where this angle right here is theta. So this right here is the rotation for an angle of theta of x. That's what this vector right here is. So what do we have to do to make sure that this is a linear combination? We have to show two things. We have to show that the transformation, so the rotation through theta of the sum of two vectors-- it's equivalent to the sum of each of their individual rotations. The rotation of the vector x plus the rotation of the vector y. And I'll just show that to you visually. This is the vector x. Let's say that the vector y looks something like-- let me draw the original vectors in yellow. So let's say the vector y looks like that. So that's y. So what's x plus y? So let's put heads to tails. If we just shift y up here, that's also vector y, not drawn in standard position, but x plus y would then look pretty close to this. Let me draw it a little bit neater. x plus y would look like that. That would be the vector x plus y. And what would its rotation look like through an angle of theta? What's rotation if you just rotate this guy through an angle of theta? I'm just approximating-- it would look something like this. This right here would be the rotation through an angle of theta of x plus y. Now let's see if that's the same thing as if we rotate x and rotate y and then add them together. So what's y if we rotate it through an angle of theta? If we rotate y through an angle of theta, it's going to look something like-- this is all approximation. I should be doing it with a ruler and a protractor. Maybe it looks something like this-- the rotation of y through an angle of theta right there. That's the same theta that I've been doing the whole time. Let me make it in a color that you can actually see. So that's that vector right there. The rotation of x was right there. So if we add the rotation of x plus the rotation of y-- I'm kind of fudging it a little bit, but I think you get the idea-- so this is the rotation of x plus the rotation of y. You actually get the rotation of x plus y. So at least visually it satisfied that first condition. Now the second condition that we need for this to be a valid linear transformation, is that the rotation through an angle of theta of a scaled up version of a vector should be equal to a scaled up version of the rotated vector. And I'll just do another visual example here, so that's just my vertical axis. That's my horizontal axis, and let me say that this is my vector x. Now let's draw a scaled up version of it. So a scaled up version of x may be just like x, but it gets scaled up a little bit, so it goes all the way out here. So this is my c times x and now I'm going to rotate that through an angle of theta. So if we rotate that through an angle of theta, you'll get a vector that looks something like this. Rotating it counterclockwise. So this vector right here is the rotation by an angle of theta counterclockwise of c, x. That's what this is right there. Now what happens if we take the rotation of x first? So if we just rotate x first, we're going to get this vector right here. So this right here is just a rotation for an angle of theta of x and then we scale it up. What we see it's the same thing of this scaled up to that when you multiplied by c, than this thing is going to scale up to that when you multiply it by c. So at least visually, I've shown you that this is satisfied. So rotation definitely is a linear transformation, at least the way I've shown you. Now let's actually construct a mathematical definition for it. Let's actually construct a matrix that will perform the transformation. So I'm saying that my rotation transformation from R2 to R2 of some vector x can be defined as some 2 by 2 matrix. And it's 2 by 2 because it's a mapping from R2 to R2 times any vector x. And I'm saying I can do this because I've at least shown you visually that it is indeed a linear transformation. And how do I find A? Well, I start with-- since this where's mapping from R2-- I start with the identity matrix in R2 which is 1, 0, 0, 1. Its columns are the basis vectors for R2, right? We refer to this one as e1 and this column vector as e2. And to figure out A, we essentially just perform the transformation on each of these columns. So let me write that. So A-- our matrix A-- is going to be-- the first column of it is going to be a rotation transformation performed on the vector 1, 0. And our second column is going to be the rotation transformation-- there's a little theta here that I'm forgetting to write-- times the second column vector-- or the transformation of that one, 0, 1. This is what our A is going to look like. So how do we figure out what these are? I'm trying to get to some numbers and this doesn't get me there, so let's try to do that. Let me draw some more axes here. Let me pick a different color, I'll do it in grey. So that is my vertical axes. That is my horizontal axes. I could call this the x1-axis and this is the x2-axis. Now this basis vector e1, what does it look like? Well, it's 1 in the horizontal x1 is 1 and x2 is 0. So this is 1 out here, e1 will look like that. Let me do it in a more vibrant color. e1 will look like that right there. Now let me write what e2 looks like. e2 would look like-- I'll do it in yellow-- e2 would look like this right here. e2-- that's that vector, 0, 1. This is 1 in our x2 direction. Now if I rotate e1 by an angle theta, what will it look like? So if I rotate e1 in angle theta -- I'll do it in this color right here-- it will still have a length of 1, but it'll be rotated like that and that angle right there is theta. So this right here is the rotation of e1 by theta. These are all vectors, of course. That's what that is. Now what are the coordinates for this? Or how do we specify this new vector? Well we can break out a little bit of our trigonometry. Its new x1 coordinate-- we could call it-- or its x1 entry is going to be this length right here. So if we draw a right triangle, it is the side that is adjacent to theta. This side is a hypotenuse which is length 1. So how do we figure out this side? If we call this side the adjacent side. The adjacent side over the hypotenuse. Adjacent-- let me write it over here. Adjacent over the hypotenuse which is just 1, is equal to the cosine of theta. That comes from SOH-CAH-TOA Let me write that. Cosine is adjacent over hypoteneuse, and the adjacent side is going to be our new x1 coordinate, right? Well, we can obviously ignore that 1, a divided by 1 is equal to cosine theta, which means that a is equal to cosine theta, which means that this length of our rotated vector is equal to cosine theta. Its horizontal component, or its horizontal coordinate is equal to cosine of theta. Now, what's its vertical component going to be? Its vertical component is going to be this height right here, which is the same thing as that height right there. Or we could say sine of theta-- and call this the opposite-- sine of theta is equal to the opposite over 1. So this is going to be equal to sine of theta, right? This over 1, which is just this, is equal to sine of theta from SOH-KAH-TOA. So this vertical component is equal to sine of theta. So the new rotated basis vector could be written as cosine of theta for its x component, or for its horizontal component. And sine of theta for its vertical component. This is the new rotated basis vector. Now what about e2? We could do something very similar there. e2 is going to end up looking like this when you rotate it by an angle of theta. It's going to look like that. That angle right there is theta. We can create a little right triangle right there. And so if we want to know its x coordinate-- so now we're concerned with the rotation through an angle of theta of e2, which is that right there, of e2. This is e2 right there. This is going to be equal to what? Its new x coordinate or its first entry in this vector if we wanted to draw it in standard position. Or the point that it is specifying is going to be equal to this distance, which is equal to this distance on this triangle. But the coordinate is going to be the negative of this, right? If this is a distance of 2, this coordinate is going to be minus 2. So what's this? We have an angle. It's a right triangle. This is opposite to the angle. Opposite over 1, opposite over hypotenuse is equal to cosine of theta. So this opposite side is equal to the cosine of theta. So the x-coordinate right here. Oh sorry, my trigonometry is messing up. This is the opposite side-- SOH-CAH-TOA. Sine is equal to opposite-- let me write it-- sine of theta is equal to opposite over hypotenuse. So the sine of theta-- the sine of this angle is equal to the opposite over the hypotenuse. The hypotenuse is 1, has length 1 because these are the standard basis vectors. So this is equal to the sine of theta. Now, this distance is equal to the sine of theta that's going in the negative direction, so it's going to be equal to the minus sine of theta. And then what it's new y component going to be of this rotated version of e2? Well, we just look right here. We have our angle. This is adjacent to the angle. This adjacent side over the hypotenuse-- adjacent over 1-- which is just this is adjacent right here is just going to be equal to cosine of theta. So its new y-coordinate going to be cosine of theta. So when we apply the transformation to each of our basis vectors, we get A is equal to the transformation applied to e1 which is cosine of theta and sine of theta. And the transformation applied to e2, which is minus sine of theta times the cosine of theta. So now this is a big result. We've now been able to mathematically specify our rotation transformation using a matrix. So we can now say that the rotation transformation-- and it's a transformation from R2 to R2-- it's a function. We can say that the rotation through an angle of theta of any vector x in our domain is equal to the matrix cosine of theta, sine of theta, minus sine of theta, cosine of theta, times your vector in your domain, times x1 and x2. And you might be saying, oh Sal, we did all this work and that's kind of neat, but how do I apply this? I still have all these cosines of thetas and sines of thetas there-- how I do it? Well, what you do is, you pick an angle you want to rotate to, and just evaluate these, and you'll just have a normal matrix with numbers in it. So let's say we wanted to rotate through an angle of 45 degrees some vector. Well, this is going to be equal to what? We just apply, or we evaluate each of these ratios at 45 degrees. A cosine of 45 degrees is the square root of 2 over 2. Sine of 45 degrees is square root of 2 over 2. Sine of 45 is the square root of 2 over 2. We have a minus there-- so minus the square root of 2 over 2. And then cosine is just square root of 2 over 2. So we multiply it times our vector x. So this matrix, if we multiply it times any vector x, literally. So if we have some coordinates right here. And let's say that I were to have a bunch of vectors that specify some square here. Let me see if I can do it properly. Well, maybe it has some triangle here--maybe that will be a little easier for me to draw. I'll do a square. Let's say it has some square here in my domain. So this is in R2. If I literally multiply this times each of the basis vectors, or actually all of the vectors that specify this set here, I will get, when I transform it, I'll get a rotated version of this by 45 degrees. Just to draw it, I'll actually draw a little 45 degree angle right there. And then it will map it to this image right there, which is a pretty neat result. And if you ever attempted to write any computer game that involves marbles or pinballs going around, this is a very useful thing to know-- how you rotate things. In the future, we'll talk about other types of transformations. But this is a super useful one and this is super hard to do. And I remember the first time I wrote a computer program to try to do this type of thing, I just did it by hand. But when you have this tool at your disposal, all you have to do is evaluate this matrix at the angle you want to rotate it by, and then multiply it times your position vectors. And so obviously you have a bunch of position vectors here. But here you can just do it times the vertices and then you can say OK. And everything else is just connect the dots between them. And then you have your rotated image. And just to be clear, these are the points specified by a set of vectors and I always want to make this clear, right? This point right here is specified by some position vector that looks like that. When you apply the rotation on 45 degrees of that vector, this vector then looks like this. And the vector that specified this corner right here-- we'll do it in a different color-- that specified this corner right here, when you're rotated by 45 degrees, then becomes this vector. And the vector that specified that corner over there, that now becomes this vector. That's what actually being mapped or actually being transformed. Anyway, hopefully you found this pretty neat. I thought this was, at least for me, the first really neat transformation. And you can already start thinking about how to extend this into multiple dimensions especially three dimensionals. If you ever try to actually do it by hand, three dimension rotation becomes very confusing. But in the next video we'll actually figure out a way to do three dimensional rotations around certain axes.