0
$\begingroup$

I am a bit confused right now in 3D rotations. I have searched this question in many different ways but have not found a resource that could help me mentally/visually understand what is going on.

I'm familiar with matrices and utilizing them quite frequently in graphics, but this particular situation is making me realize I have a flaw in my reasoning at a base level.

I want to take two 3D (3x3 rotational information stored in a 4x4 matrix with last column and row staying as 0, 0, 0, 1 in the following examples) rotational matrices and combine them to perform a rotation in this order: x-axis then y-axis.

so I simply multiply them together to perform the operation. When I apply the matrices individually against a vector of [1, 1, 1, 1] I get the expected results:

Assuming +x toward the screen, +z to the right, +y is up

x-axis matrix (of 90 degrees) produces [1, -1, 1, 1] (a clockwise spin of the x-axis)

y-axis matrix (of 90 degrees) produces [1, 1, -1, 1] (a clockwise spin of the y-axis)

Now when I combine the matrices to rotate x then y and apply it against my vector (both still represent 90 degrees on their respective axis) it produces [1, 1, 1, 1].

I have tested this result against many online calculators that express this result as correct; however, to achieve that result would mean you did a counter-clockwise spin on the x-axis and a counter-clockwise spin on the y-axis.

I do not understand why this is happening. Again as a mental model...mathematically it just works just fine, but it really breaks down some of my perceptions on ordered rotations.

I feel like this has to deal with gimble lock somehow, just not sure how it plays into this especially since I split up the rotations and applied it to my vector one step at a time an lo! The result is more what I expected.

$\endgroup$
5
  • 1
    $\begingroup$ A 3D rotation matrix is not a 4x4 matrix, it is a 3x3 matrix. $\endgroup$ – runway44 Jul 4 '19 at 21:22
  • $\begingroup$ Yeah I could have expressed it all in 3x3. It's just helpful for me to keep it all in the dimensions I'm using currently to make sure I'm not doing something stupid. I realize, strictly speaking, 3x3 is where the 3d rotational information is stored, but for consistency I assume 4x4 with the last column and row staying as 0, 0, 0, 1. Technically in this case, the vector being 1 does not alter the results anywho. I realize I'm on a math forum though, would it be more proper to be a bit more explicit and less implied here? $\endgroup$ – Diniden Jul 4 '19 at 21:42
  • $\begingroup$ So, it would seem if you use a "left-hand rule" for rotations around an oriented axis, rotating $90^{\circ}$ around the $x$-axis and then rotating $90^{\circ}$ around the $y$-axis does indeed get the point $(1,1,1)$ back to where it started. This is relatively easy to visualize by coloring the vertex of a cube and watching it rotate appropriately. That means the composition of these two rotations must be a rotation around the axis through $(1,1,1)$. Also, if you use a "right-hand rule" to rotate $90^{\circ}$ around the $x$ then $y$-axis, the point $(1,1,1)$ ends up somewhere else. $\endgroup$ – runway44 Jul 4 '19 at 21:54
  • $\begingroup$ @runway44 If you’re working in homogeneous coordinates (usually so that translations can also be represented by matrix multiplication), which is what is going on here, transformation matrices for $\mathbb R^3$ are $4\times4$. $\endgroup$ – amd Jul 6 '19 at 1:52
  • $\begingroup$ Yes, OP pointed that out after my first comment. $\endgroup$ – runway44 Jul 6 '19 at 4:19
1
$\begingroup$

It doesn’t really have to do with anything fancy-sounding like gimbal lock or that the matrices for rotation about the $y$-axis look “backwards” because the $y$- and $z$-axis form a left-handed coordinate system. It’s simply because matrix multiplication is not commutative: the order in which you multiply them matters. In particular, 3-D rotations don’t commute unless they have a common rotation axis. You’re almost certainly multiplying the two primitive rotation matrices together in the wrong order when computing the combined transformation matrix.

You haven’t said whether you’re working with row or column vectors, but either way, when you chain transformations together like this, remember that the input to the next transformation in the chain is the output of the preceding transformation. If you’re working with column vectors so that left-multiplication by a matrix gives you the transformed vector, the result of applying the first rotation is $\mathbf v'=R_x\mathbf v$, and the result of applying the second rotation to that is $R_y\mathbf v' = R_y(R_x\mathbf v) = (R_yR_x)\mathbf v$, therefore the matrix that represents the combination of the two rotations is $R_yR_x$. You likely computed $R_xR_y$ instead, which corresponds to first rotating about the $y$-axis and then rotating about the $x$-axis. An easy way to remember this is that if you left-multiply by a matrix to transform a vector, then the chain of matrices grows to the left.

If you’re instead working with row vectors, then you’d be right-multiplying by the transformation matrices, and the chain would grow to the right. In that case, $R_xR_y$ would give you the correct result, since $\mathbf v(R_xR_y)=(\mathbf vR_x)R_y$.

Now, since any combination of rotations is itself a rotation, and every rotation in 3-D has a unique axis that is unchanged by the rotation, there is a set of vectors for which the order in which you apply the rotations doesn’t matter. Those vectors all lie along the effective axis of the combination of individual rotations.

$\endgroup$
1
  • $\begingroup$ Thanks for the feedback. I had re-analyzed my combined transforms and that certainly was the case that I had some negatives go awry in my combination. All of the feedback here helped me out in making sure I remembered which handed rule I was using and helped me debug my math! $\endgroup$ – Diniden Jul 7 '19 at 3:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.