Problem calculating rotation matrix around arbitrary axis

840 Views Asked by At

I'm trying to calculate the rotating matrix around the Z axis in a counter clockwise direction.

In-order to do that I've decided on a vector A [1 0 0] and I wish to rotate it around the z axis so it'll end up as At [0 1 0] (90 degrees rotation around the z axis)

Let's consider our matrix R. Now, what I've done is set At coefficients to the product of the matrix R by the vector A as follows:

At.x = A.x * R00 + A.y * R10 + A.z * R20
At.y = A.x * R01 + A.y * R11 + A.z * R21
At.z = A.x * R02 + A.y * R12 + A.z * R22

Now, replacing the A and At coefficients we get:

0 = 1 * R00 + 0 * R10 + 0 * R20
1 = 1 * R01 + 0 * R11 + 0 * R21
0 = 1 * R02 + 0 * R12 + 0 * R22

Next, to make these equations right I've deducted the following:

R00 must be 0
R01 must be 1
R02 must be 0
others R coefficients are irrelevant to me

Creating the matrix so far:

0     1     0
0     0     0
0     0     0

Since we rotated around the z axis by 90 degrees we can say the following about the earlier deduction of the matrix coefficients:

R00 = cos(θ)
R01 = sin(θ)
R02 = cos(θ)

And finally, applying this to the matrix:

cos(θ)     sin(θ)     cos(θ)
  0          0          0
  0          0          0

After building my matrix, I've tested it here: Matrix Calculation Online Website

With the following same vector A [1 0 0] and matrix R I ended up with And got the desired Result of At [0 1 0]

So, summing it all the process I've done, my question is why for every resource I looked for the answer the rotating around the z axis matrix should look like this: Z axis rotation matrix

What have I done wrong / missed calculating to get the same matrix ?

1

There are 1 best solutions below

1
On BEST ANSWER

It seems like you've designed a set of equations specifically for the case of $\theta=90^\circ$. If you want to derive the more general rotation matrix about axis $z$, then you have to allow for any rotation $\theta$.

Consider rotating some vector like your vector $\begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix}$ or slightly more generally $\begin{bmatrix} r \\ 0 \\ 0 \end{bmatrix}$ around the $z$ axis by an arbitrary angle $\theta$.
enter image description here (https://en.wikipedia.org/wiki/Rotation_matrix#/media/File:Counterclockwise_rotation.png)

The position of the head of the new vector can be calculated using trigonometry. It's really the same mathematics as polar coordinates where here you're rotating a radius of $r$.

So the new $x$ and $y$ coordinates of the vector head position can be found with $$ x = r \cos(\theta) $$ $$ y = r \sin(\theta) $$ Writing this with matrices gives $$ \begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} \cos(\theta) & 0 \\ 0 & \sin(\theta) \end{bmatrix} \begin{bmatrix} r \\ 0 \end{bmatrix} $$ This gives a slightly more general formula but requires the vector start parallel to the $x$ axis. We can generalize further by considering rotating any vector $\begin{bmatrix} v_x \\ v_y \\ v_z \end{bmatrix}$ in 3D about the $z$ axis. Using the same trig we can deduce that the new $x$ position of the vector head is $$ x = v_x \cos(\theta) - v_y\sin(\theta) $$ the new $y$ position is $$ y = v_x \sin(\theta) + v_y\cos(\theta) $$ and since we're rotating around $z$ the $v_z$ value does not change $$ z = v_z $$ which writing with matrices gives you the rotation matrix you'll recognize $$ \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} v_x \\ v_y \\ v_z \end{bmatrix} $$