# 3x3 Identity and rotation matrices and how they work

by STENDEC
Tags: identity, matrices, rotation, work
 P: 14 I'm trying to rotate a point about the origin $(0,0,0)$ and starting with an identity matrix, this works fine for the x- and y-rotation axes, but fails with the z-axis, where the point just sits in place. $\begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix} M_{ID} \times M_Z \begin{bmatrix} cos(\phi) & sin(\phi) & 0 \\ -sin(\phi) & cos(\phi) & 0 \\ 0 & 0 & 1 \end{bmatrix}$ I imagine the point is sitting on the z-axis, thus rotating around itself. I'm not sure how to modify the identity matrix to reposition it so that it rotates around the origin like with the other axes. I hope someone can point out to me what's needed here. Thanks.
 P: 389 The matrix you have there rotates a point around the z axis. Look at http://en.wikipedia.org/wiki/Rotation_matrix under "Basic rotations" If you want to rotate around an arbitary axis you can use the equations under "Rotation matrix from axis and angle" To understand how a rotation matrix works you should know that each column represents a 3D Vector which in turn represents one of the axis of the rotated coordinate system. e.g. $\begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}$ consists of three Vectors $\left(\begin{array}{c} 1 \\ 0 \\ 0 \end{array}\right) \left(\begin{array}{c} 0 \\ 1 \\ 0 \end{array}\right) \left(\begin{array}{c} 0 \\ 0 \\ 1 \end{array}\right)$ Lets call the 3 vectors $\vec{xa}$, $\vec{ya}$ and $\vec{za}$ When you then have a coordinate $\left(\begin{array}{c} x \\ y \\ z \end{array}\right)$ and you apply your matrix to it what you are basically doing is moving along the x, y and z axis of the rotated coordinate system, i.e. $\vec{xa}*x + \vec{ya}*y + \vec{za}*z$
 P: 14 I'm trying to understand what you're saying. If I rearranged the 1's an 0's in the ID matrix, couldn't I get a point(vector) that would respond to the z-axis rotation? By analogy with a roundabout, couldn't I move the vector from standing straight up to pointing outward, lying on the rotating disc? I wrote a small program where i changed the identity matrix, but the point only changes its starting position - subsequent multiplications with the rotation matrix yet again do nothing. Surely it is not an inherent property of the z-rotation matrix? I will look into axis-angle if it is the only option to do what I'm looking for, but I'd like to understand this problem first.
 P: 389 3x3 Identity and rotation matrices and how they work Could you give an example? I have no idea what you mean. To rotate a vector around the origin with a matrix you create the rotation matrix by one of the methods explained on the wikipedia site and then multiply the matrix with your vector.
 P: 14 Ok, I'll try. This is what happens with the 3 rotation matrices multiplied by the identity matrix. X and Y rotate the point, Z just has it sitting there. The way I understood your vector explanation, I thought I could somehow move the "point" (I want to rotate) away from the Z-axis, e.g. along the X-axis, so that the Z-axis can rotate it. I suspect I have some major misconception here, but i read a lot of articles and just don't get it. I'm extracting the point location from the third column of the resulting matrix.
 Emeritus Sci Advisor HW Helper Thanks PF Gold P: 11,755 Think about it. If you're rotating about the z-axis, points on the z-axis can't move. They're on the rotational axis. For any rotation in 3D, there's going to be some axis along which points won't move. You need to specify exactly what kind of rotation you want.
 P: 14 I'm aware of that, check my first post. My question was about how to move the point away from the Z-axis; that part doesn't seem to work as I expect it to. In above image, I would want a rotation that adds the third circle to the existing two.
 Emeritus Sci Advisor HW Helper Thanks PF Gold P: 11,755 You're not being very clear then. You're saying you're using a rotation about the z-axis that you know does not affect points on the z-axis, but you don't understand why those points don't move away from the z-axis. You must be leaving an important detail out.
 P: 14 I have a 3x3 identity matrix. I have three rotation matrices as defined in online sources. I multiply the identity matrix with the rotation matrices (each separately). From the resulting matrix, I retrieve new point coordinates from the third column ([1][3], [2][3], [3][3] if you will). Optionally, I multiply the resulting matrix with the rotation matrix repeatedly, giving me a circle of points around that axis. This only works for X- and Y-axis rotation, the Z-axis matrix has no similar effect. Question: How is the identity matrix to be modified to give me a rotation around the Z-axis? If $\begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}$ yields no Z-axis rotation, would something like e.g. $\begin{bmatrix} 0 & 0 & -1 \\ 0 & 1 & 0 \\ 1 & 0 & 0 \end{bmatrix}$ change that? In my program it doesn't seem to.
 Emeritus Sci Advisor HW Helper Thanks PF Gold P: 11,755 Sorry, it's still not clear what you mean. A rotation matrix maps a vector (x, y, z) to a vector (x', y', z'). I'm not sure what your intended role is for the identity matrix here. I'm guessing that you're taking each column to represent a vector. (Actually rows, not columns, since you're multiplying by the rotation matrix on the right.) By modifying the matrix, all you're doing is reordering or choosing slightly different vectors to be rotated. If a rotation doesn't affect points on the z-axis, then it's not going to affect points on the z-axis regardless of which vectors you use or how you arrange them. If you want a rotation that does move points off the z-axis, you need to use a different rotation, not different vectors. It would help if you gave specific examples of rotations about the x and z axes to illustrate your point.
 P: 389 I also don't get why you use the identity matrix here? And why do you need 3 rotation matrices? No matter what the rotation axis is you only need one matrix. Maybe you should first try a few 2D rotations using a matrix to understand it better before going 3D. I could give you some Java source code for vector rotations with matrices if that would help.
P: 14
 Quote by vela I'm not sure what your intended role is for the identity matrix here. I'm guessing that you're taking each column to represent a vector. (Actually rows, not columns, since you're multiplying by the rotation matrix on the right.)
Yes, based on what DrZoidberg said, and on my positive results with X and Y rotations, I thought that somehow these triplets define a point's offset (or vector's magnitude). Replacing the 1's in the ID matrix with smaller/larger numbers, results in a corresponding offset change. When applying the rotation repeatedly, a smaller/larger circle of points results.

 Quote by vela If a rotation doesn't affect points on the z-axis, then it's not going to affect points on the z-axis regardless of which vectors you use or how you arrange them. If you want a rotation that does move points off the z-axis, you need to use a different rotation, not different vectors.
This is where my confusion stems from. I thought the matrix I start with prepares three points (vectors) by offsetting them from their respective axes.

 Quote by vela It would help if you gave specific examples of rotations about the x and z axes to illustrate your point.
Basically I want to draw three circles of points (with a certain radius) around the origin, one for each of the three spacial dimensions. This seemingly worked for two axes based on list items 1. and 2. in my post above, despite me not understanding the intrinsics. I understand that a vector can remain unaffected by one axis, but I don't understand how I can define said vector to be off this axis from the get go, so that it now points along e.g. the Y axis, thereby responding to X and Z rotations.

 Quote by DrZoidberg I also don't get why you use the identity matrix here? And why do you need 3 rotation matrices? No matter what the rotation axis is you only need one matrix.
So are you saying that I could start with a vector {x, y, z}, multiply that by a rotation matrix, take the resulting vector, multiply that by the rotation matrix, etc. to get the type of circle in my drawing? Would this also work just as well for a matrix that contains rotation around more than one axis?

I'm not sure I understand your second sentence. I do use one matrix per axis. I cannot tilt the rotation axis itself and just distinguish between clockwise/counter-clockwise rotation, can I?

Thanks a lot for your patience guys.
P: 389
 Quote by STENDEC Yes, based on what DrZoidberg said, and on my positive results with X and Y rotations, I thought that somehow these triplets define a point's offset (or vector's magnitude). Replacing the 1's in the ID matrix with smaller/larger numbers, results in a corresponding offset change. When applying the rotation repeatedly, a smaller/larger circle of points results.
By the way, in your original post the rotation matrix is incorrect. Compare it with the wikipedia article. The minus sign is at the wrong place. Furthermore in a matrix multiplication the order matters. The rotation matrix should be on the left and the vector/matrix you want to rotate on the right.

But if all you want to do is draw a circle in the plane of the x and y axes with $\left(\begin{array}{c} 0 \\ 0 \\ 0 \end{array}\right)$ as it's center you just ignore the z axis, i.e. z is always 0 and then you do a 2D rotation. Start with an angle of 0 and increase it in small steps until you reach an angle of $2\pi$. At each step you calculate the point on the circle with $r*\left(\begin{array}{c} cos(\phi) \\ sin(\phi) \\ 0 \end{array}\right)$ where r is the radius of the circle.
Then you repeat the process for the other axes.
For a circle around the x axis you do $r*\left(\begin{array}{c} 0 \\ cos(\phi) \\ sin(\phi) \end{array}\right)$
and for the y axis $r*\left(\begin{array}{c} sin(\phi) \\ 0 \\ cos(\phi) \end{array}\right)$
 P: 139 At the risk of too many cooks spoiling the soup, I'll try to help a little. It looks like you're trying to build up a general rotation matrix by combining three simpler rotations (rotating around the x, y, and z axes). That's the right idea, but the problem is that your rotation matrix in the first post only rotates around the z axis. I think the confusion is arising because on the one hand you say you don't want this, but on the other hand you use notation like M_z which suggests some knowledge of what that matrix does. It should be clear from the third column of M_z that the vector (0,0,1) is not changed by it, so it does indeed rotate around the z axis. Look again at the "Basic Rotations" and "General Rotations" in the wikipedia article and make sure you understand what R_x, R_y, and R_z mean. Do you see why R_x rotates around the x axis? Look at the columns to see what happens to the basis vectors. (1,0,0) is unchanged, and the other two are rotated in the yz plane. Only when multiplying all three of those matrices together can you build up an arbitrary rotation. You haven't done that. Lastly, I don't think your matrix is incorrect because it disagrees with wikipedia. It just means that it rotates vectors in the opposite direction as the article states, or it means that you can view it as rotating the axes to make a coordinate change. If you check the "Ambiguities" section or the talk page for that article, there is a ton of confusion because people can't agree on which interpretation is correct (they both are).
 Emeritus Sci Advisor HW Helper Thanks PF Gold P: 11,755 The way you typically use a rotation matrix R is you multiply it by vector x to get a new vector x'. For example, take a rotation about the z-axis by the angle ##\theta##. The matrix that represents that rotation is given by $$R = \begin{bmatrix} \cos\theta & -\sin\theta & 0 \\ \sin\theta & \cos\theta & 0 \\ 0 & 0 & 1 \end{bmatrix}.$$ If we apply it an arbitrary vector, ##\begin{bmatrix} x \\ y \\ z\end{bmatrix}##, we get $$\begin{bmatrix} x' \\ y' \\ z'\end{bmatrix} = \begin{bmatrix} \cos\theta & -\sin\theta & 0 \\ \sin\theta & \cos\theta & 0 \\ 0 & 0 & 1\end{bmatrix} \begin{bmatrix} x \\ y \\ z \end{bmatrix} = \begin{bmatrix} x\cos\theta - y\sin\theta \\ x\sin\theta + y\cos\theta \\ z \end{bmatrix}.$$ Note the multiplication by x is from the right. That's equivalent to the three equations \begin{align*} x' &= x\cos\theta - y \sin\theta \\ y' &= x\sin\theta + y\cos\theta \\ z' &= z \end{align*} The first two equations you should recognize as a rotation in the xy-plane by the angle θ. The z-coordinate is unaffected. Note that it's a rotation only in one plane, the xy-plane. I think you're misinterpreting your results with the identity matrix as a rotation in two different planes. What you actually calculated was the result of rotating the vectors (1, 0, 0), which is the first row of I, and (0, 1, 0), which is the second row of I, in the xy-plane. (It's rows, not columns, because you multiplied on the left.) In other words, you found the point (1, 0, 0) maps to the point (cos θ, sin θ, 0), which is in the xy-plane. Similarly, (0, 1, 0) maps to (-sin θ, cos θ, 0), which, again, is in the xy-plane. You're not rotating about different axes with one matrix.
 P: 14 Thanks a lot guys, sorry I didn't respond earlier. I won't reply to each post individually, but note that they've been very helpful to me! In doing further reading I realized that I'm using pre-multiplication and row-major matrices; I would have avoided confusion if I had mentioned that from the start but wasn't aware of the ambiguity. I was able to rotate a vector using the matrix from my fist post, and the way it works makes sense now. This also made me realize that I was essentially rotating three vectors in my first post. Treating the three rows of the 3x3 matrix as vectors, I now knew where to find the rotated coordinates (I had been looking in the wrong place). I have further questions, but I think they go beyond the scope of the thread title, so if I can't figure them out myself I'll make a new thread. Thanks.
 Math Emeritus Sci Advisor Thanks PF Gold P: 39,544 You seem to be thinking that you can define a single "rotation" that will move every point in space except the origin. You can't. A rotation is necessarily a 'planar' operation and must have an axis of rotation. Every point is moved on a plane perpendicular to that axis and every point on the axis is not moved. One can, in fact, show that in any operation in three dimensional that does not change the distance between points must have a "fixed line"- a line of points that do not move. You can rotate through angle $\theta$ around the x- axis using $$\begin{bmatrix}1 & 0 & 0 \\ 0 & cos(\theta) & -sin(\theta) \\ 0 & sin(\theta) & cos(\theta) \end{bmatrix}$$ around the y- axis using $$\begin{bmatrix}cos(\theta)& 0 & -sin(\theta) \\0 & 1 & 0 \\sin(\theta) & 0 & cos(\theta) \end{bmatrix}$$ and around the z-axis using $$\begin{bmatrix}cos(\theta) & -sin(\theta) & 0 \\sin(\theta) & cos(\theta) & 0 \\ 0 & 0 & 1 \end{bmatrix}$$ Rotations about other axes can be done by combinations of those but a rotation always has an axis.

 Related Discussions Linear & Abstract Algebra 3 General Math 2 Calculus & Beyond Homework 0 General Math 6 Calculus & Beyond Homework 2