[Math] Combine a rotation matrix with transformation matrix in 3D (column-major style)

conventionmatricesrotationstransformation

I'm trying to concatenate a rotation matrix with a 4×4 homogeneous transformation matrix with column-major convention.

I want this rotation matrix to perform a rotation about the X axis (or YZ plane) by an angle theta in a 3D space.

$$
\begin{pmatrix}
1 & 0 & 0 & 0 \\
0 & \cos{\theta} & -\sin{\theta} & 0 \\
0 & \sin{\theta} & \cos{\theta} & 0 \\
0 & 0 & 0 & 1 \\
\end{pmatrix}
$$

I use column-major matrices so I know I have to post-multiply them to concatenate them.

$$
\begin{pmatrix}
1 & 0 & 0 & 0 \\
0 & \cos{\theta} & -\sin{\theta} & 0 \\
0 & \sin{\theta} & \cos{\theta} & 0 \\
0 & 0 & 0 & 1 \\
\end{pmatrix}
\begin{pmatrix}
x_x & y_x & z_x & \Delta_x \\
x_y & y_y & z_y & \Delta_y \\
x_z & y_z & z_z & \Delta_z \\
0 & 0 & 0 & 1 \\
\end{pmatrix}
$$

It gives me:
$$
\begin{pmatrix}
x_x & y_x & z_x & \Delta_x \\
x_y \cos{\theta} – x_z \sin{\theta} & y_y \cos{\theta} – y_z \sin{\theta} & z_y \cos{\theta} – z_z \sin{\theta} & \Delta_y \cos{\theta} – \Delta_z \sin{\theta} \\
x_y \sin{\theta} + x_z \cos{\theta} & y_y \sin{\theta} + y_z \cos{\theta} & z_y \sin{\theta} + z_z \cos{\theta} & \Delta_y \sin{\theta} + \Delta_z \cos{\theta} \\
0 & 0 & 0 & 1 \\
\end{pmatrix}
$$

Which is obviously wrong but I don't know how to get it to work with respect with the column-major convention…

EDIT: What is my goal?

What I want to do is to concatenate my rotation matrix $R$ and a transformation matrix $T$ (which can have translation, rotation, scaling…) by using matrix product $C = R * T$ so that when I'll apply this matrix to a 3D (homogenous) set of points, the points will be transformed in accordance with both $T$ and $R$.

I think the above result matrix is wrong because as you can see, the location point $\Delta$ is affected by the rotation while I didn't expect it to be. Indeed, I just want points to be rotated in relation to an arbitrary object upright space not the world space.

I would expect column 2 and 3 to be modified instead of row 2 and 3. Reversing the matrix product $C = T * R$ could solve the problem but I was told that as far I use column-major convention, I have to post-multiply transformations.

Maybe I'm completely wrong and matrix concatenation has nothing to do with whether I pre- or post- multiply them…
In fact, it may just specify in which order to apply transformations (first rotate with $R$, then transfroms with $T$…)

Can you tell me if I'm wrong somewhere?

Best Answer

By "column major convention," I assume you mean "The things I'm transforming are represented by $4 \times 1$ vectors, typically with a "1" in the last entry. That's certainly consistent with the second matrix you wrote, where you've placed the "displacement" $\Delta$ in the last column. Your entries in that second matrix follow a naming convention that's pretty horrible -- it's bound to lead to confusion.

Anyhow, the matrix product that you've computed is correct (that is, you did the multiplication properly). The result is something that first translates the origin to location $\Delta$ and the three standard basis vectors to the vectors you've called $\vec{x}$, $\vec{y}$, and $\vec{z}$, respectively, and having done so, then rotates the result in the $(2,3)$-plane of space (i.e., the plane in which the second and third coordinates vary, and the first is zero. Normally, I'd call this the $yz$-plane, but you've used up the names $y$ and $z$.) The rotation moves axis 2 towards axis 3 by angle $\theta$.

I don't know if that's what you want or not, but it's what you've got. Perhaps if you described the goal more clearly I could give a clearer answer.