Main content

## Linear transformation examples

Current time:0:00Total duration:17:52

# Linear transformation examples: Rotations in R2

## 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 data 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 of data 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 data 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.