# Order of matrices when rotating a vector

I would like to calculate the vertical velocity of a drone by integrating accelerometer data, problem is that the accelerometer measures in the frame of reference of the drone and not the the earth.

I know how much the frame of reference is rotated along the x and y axes and I know the position of the vector in this frame of reference.

I would like to rotate the vector back to get actual vertical acceleration but the order of operations matter for matrix rotations. The drone rotated on both axes simultaneously so I don't know which rotation to calculate first.

I don't necessarily believe that this is the right place for this question but other communities suggested I try here.

• We can not anser the question because you dont include any info that would let anybody solve the thing – joojaa Apr 23 '19 at 15:58
• This is largely a matter of engineering conventions. It's the right place alright. – Phil Sweet May 23 '19 at 23:23

I know how much the frame of reference is rotated along the x and y axes and I know the position of the vector in this frame of reference.

If you know how much, then you must know the order. How much is dependent on the order. The problem is, there are several ways to get from one reference frame to another via rotations. You need to look at what you mean above and use the system of transforms that makes the most sense.

TLDR If what you have is azimuth, elevation, and roll from Earth frame to Body frame; then the matrix operations are performed in that order, meaning the matrices are written in the opposite order followed by a column vector and evaluated last first. To go from Body to Earth, the operations are performed in the opposite order, or you use the transpose of the combined direction cosine transformation matrix

Let's say you start by considering a level flight scenario. You have a RHR body frame and a RHR local earth frame. Conventionally, the Earth frame is NED - positive x,y,z is North, East, Down. The body frame is usually FSU - positive x,y,z is Forward, Starboard, Up. But Aft, Starboard, Down; and Forward, Port, Down are also pretty common. Pick one - it doesn't matter as far as the construction of the transform is concerned, the difference is only in the angles that you feed the transform and whether positive pitch is nose up or nose down, positive roll is port side up or port side down, etc.

It is assumed that the earth frame is an inertial frame here. If you need to treat it as a non-inertial frame, things can quickly get tedious.

Since we habitually write x,y,z, that is the order conventionally used to construct the direction cosine transformation matrix from the three square simple rotation matrices based on the Euler angles. The Euler angles are the appropriate angle set for this arrangement of operations. Starting in the Earth frame, Phi is the angle in the xy plane from earth x axis to the projection of xBody axis, yielding x',y',z (this is the azimuth angle). Theta is the angle in the new rotated x',z plane from x' to xBody, yielding xBody, y', z' (this is the elevation angle). Phi is the roll angle about xBody from y' to yBody, yielding xBody, yBody, zBody (this is the roll angle).

Of course, you want to go the opposite way. No problem. The inverse transformation matrix from body frame to earth frame is just the Matrix Transpose of the original matrix.

A very good reference for this is Mark Drela's Flight Vehicle Aerodynamics. It is well worth acquiring, relatively cheap in paperback, and can be viewed online via the EDX website, in the course archives for Flight Vehicle Aerodynamics.

You can apply a matrix coordinate transformation. Basic dynamics class has the development of these matrices.

This document provides a review of the matrices and also contains some practical ones.

https://ocw.mit.edu/courses/aeronautics-and-astronautics/16-07-dynamics-fall-2009/lecture-notes/MIT16_07F09_Lec03.pdf

Look at the end, you can make a T matrix for each rotation and then multiply them in together.