The problem: There is a vector with coordinates X,Y,Z. This vector is in a coordinate sytem that has been rotated by A degrees along the X axis and B degrees along the Y axis. I would like to know the Z component of this vector in a non-rotated coordinate system.
The question: I can't seem to understand the usage of matrices and it seems that would be needed. Is their a series of operations after which I get the Z coordinate?
A little backstory for those interested: I'm writing a drone flight controller and I can calculate the rotation of the drone using an accelerometer and a gyroscope. Now I would like to use the accelerometer to help with altitude controls. The XYZ values of that change depending on the rotation of the drone, but I need the change in altitude relative to the ground.
The rotation matrices (taken from Wikipedia) are:
\begin{align} Q_{\mathbf{x}}(A) &= \begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos A & \sin A \\ 0 & -\sin A & \cos A \end{bmatrix}, \\[8px] Q_{\mathbf{y}}(B) &= \begin{bmatrix} \cos B & 0 & -\sin B \\ 0 & 1 & 0 \\ \sin B & 0 & \cos B \end{bmatrix}, \\[8px] Q_{\mathbf{z}}(C) &= \begin{bmatrix} \cos C & \sin C & 0 \\ -\sin C & \cos C & 0 \\ 0 & 0 & 1 \end{bmatrix}, \end{align}The way to use them is to multiply one matrix by the current position $(x,y,z)$ vector to get the rotated vector $(x',y',z')$ and then multiply the other matrix by the resulting vector to get the result $(x'',y'',z'')$. However, from the information you provided I can't tell the exact order ad the angles may have their sign exchanged.
$$ \begin{pmatrix} x' \\ y' \\ z' \end{pmatrix} = \begin{pmatrix} 1 & 0 & 0 \\ 0 & \cos A & \sin A \\ 0 & -\sin A & \cos A \end{pmatrix} \cdot \begin{pmatrix} x \\ y \\ z \end{pmatrix} $$
And $$ \begin{pmatrix} x'' \\ y'' \\ z'' \end{pmatrix} = \begin{pmatrix} \cos B & 0 & -\sin B \\ 0 & 1 & 0 \\ \sin B & 0 & \cos B \end{pmatrix} \cdot \begin{pmatrix} x' \\ y' \\ z' \end{pmatrix} $$
However, you may want to track your position and have the velocity vector in the drone coordinates and you may want to update your estimated position using numeric integration.
$$ x (t+\Delta t) = x(t) + v_x(t) \cdot \Delta t \\ y (t+\Delta t) = y(t) + v_y(t) \cdot \Delta t \\ z (t+\Delta t) = z(t) + v_z(t) \cdot \Delta t $$
With the velocity vector $(v_x(t),v_y(t),v_z(t))$ being computed using the rotation matrices as before, starting with a vector like $(v_{fw},0,v_{up})$ or $(v_{fw},v_{up},0)$, where $v_{fw}$ is the velocity forward in the coordinate system of the drone and $v_{up}$ is the velocity upward in that coordinate system.