# What is the matrix for change of basis from unrotated to an airplane with yaw, pitch and roll?

From the wiki page on rotation matrix:

I find this rather confusing. I understand that the resulting matrix rotates a vector roll around the fixed $$x$$-axis followed by pitch around the fixed y-axis and yaw around the fixed z-axis. Since the axes are fixed this is an extrinsic rotation. And since the point is moving while the coordinate system is fixed this is an active rotation.

However the words yaw, pitch and roll are usually used to describe the orientation of an airplane:

• the plane starts flying horizontally (level) towards north

• then the plane is rotated yaw ($$\alpha$$) relative to north (around z)

• next it is rotated pitch ($$\beta$$) around the lateral axis (y)

• finally it is rotated roll ($$\gamma$$) around the logitudinal axis (x)

The axes are moving at each step (intrinsic rotation). Since the axes are moving while any point stays fixed this is an passive rotation.

Let us denote the basis vectors in the first step of the sequence above with $$\{\hat{x},\hat{y},\hat{z}\}$$ and in the final step $$\{\hat{x''},\hat{y''},\hat{z''}\}$$.

This can be expressed as a repeated change of basis: $$\{\hat{x},\hat{y},\hat{z}\} -> \{\hat{x'},\hat{y'},\hat{z}\} -> \{\hat{x''},\hat{y'},\hat{z'}\} -> \{\hat{x''},\hat{y''},\hat{z''}\}$$ in matrix form: $$\begin{bmatrix} \hat{x''} \\ \hat{y''} \\ \hat{z''} \end{bmatrix} =T_x(\gamma)*T_y(\beta)*T_z(\alpha)*\begin{bmatrix} \hat{x} \\ \hat{y} \\ \hat{z} \end{bmatrix}$$

What are the expressions for the change of basis matrices $$T_x$$, $$Ty$$ and $$T_z$$, and how does these relate to the R matrices from the wikipedia article?

• Same as above for roll, pitch and yaw. See article on elementary rotation matrix and see for example $$T_z (\alpha) = \begin{bmatrix} \cos\alpha & -\sin\alpha & 0 \\ \sin\alpha & \cos\alpha & 0 \\ 0 & 0 & 1 \end{bmatrix}$$ your question has the answer already there. Mar 19 at 19:45
• "I find this rather confusing." Yes, you're not alone. I don't know what is sticking for you, but rotations are hard to really fully understand. In fact, in my office there's a block of wood with a car, and another with the continents. Each has x, y and z axes on it. When I have to figure out translations from vehicle to ECEF, those blocks come out, and if you looked in on me you'd see me staring at the block, wrinkling my brows, and with my right hand making the international sign of "trying to understand the right-hand rule". Mar 19 at 19:55
• So you are just showing $T_z(-\tfrac{\pi}{2})$. This is because going to the local coordinate you do reverse rotations. By convention, rotation matrices have positive angles relating to local → world transformation and not the other way around. Mar 19 at 20:42
• "As an example consider a 90 degrees rotation around z:" - what you are showing is a -90° rotation about z when going from world → local basis vectors. Mar 19 at 20:43
• The rotation matrices as given all have determinant=1 so the rotated basis states still satisfy the RHR. Mar 20 at 2:44

There are two equivalent ways to perform the rotations. The approach you describe I would call the moving axes convention: at each step we rotate the coordinate system and perform the next rotation about axes in the new coordinates. We end up with three rotations about axes that are not orthogonal to one another, and requiring four different coordinate systems to be combined (the start and end coordinates, and two intermediate coordinate systems.) It can be done, but it is messy and more complicated.

However, it turns out that this combination is equivalent to performing the three rotations about fixed axes in the reverse order. I call this one the fixed axes convention. The mathematical expressions are a lot simpler, and the algebra is much faster to do, which is why the Wikipedia article cites it. But it is perhaps not as intuitive that they give the same result.

We can prove the relationship with a bit of algebra:

$$T_x=R_zR_yR_xR_y^{-1}R_z^{-1}$$

$$T_y=R_zR_yR_z^{-1}$$

$$T_z=R_z$$

so

$$T_xT_yT_z=(R_zR_yR_xR_y^{-1}R_z^{-1})(R_zR_yR_z^{-1})(R_z)=R_zR_yR_x$$

The fixed axes convention gives the same answer as the moving axes convention, but much more simply.

The moving axes convention comes from the fact that airplane controls rotate the plane about lateral and longitudinal axes. These are really terms for angular velocity. As angular velocity acts like a vector, velocities about these axes can be combined by adding, and order doesn't matter.

Orientation works differently, because rotations don't commute, and so the order in which you apply them matters. The moving axes definition based on aircraft controls now becomes mathematically quite inconvenient. There are lots of different conventions possible. If the three rotations follow an ABA pattern (one of the axes is repeated) they're called (classic) Euler angles, and if the three rotations follow an ABC pattern (3 distinct axes) they're called Tait-Bryan angles. Sometimes 'Euler angles' is used for either convention. (See here for details.) You can also define rotations to be positive-clockwise or positive-anticlockwise about each axis.

There are also many choices for XYZ axes - I have seen East-North-Up (ENU), North-East-Up (NEU), North-East-Down (NED) fairly frequently, and others are less common but do occur. (Some people use Earth-Centred Earth-fixed (ECEF) XYZ coordinates for both position and orientation.) It's a very good idea to always check what conventions are being used in any particular application.

The proper terms for the orientation angles in aeronautics are actually heading, bank, and elevation, but it is common usage (and so now completely conventional and correct) to mix the terms up.

You have described the following steps to pitch/roll/yaw your hand:

1. Face some direction that we will take as North, raise your hand flat and level in front of you, this is the start position.
2. Sweep it right/left by Y degrees, maintaining it level relative to the ground.
3. Raise your hand with your arm locked until your arm makes an angle of P degrees with level,

Consider now if you didn't know the exact angles involved and you wanted to characterize the flight from some ATC’s perspective rather than your hand’s. This problem can be looked at as trying to find a transformation which would return the hand to its original state, with the constraint that the axes of rotation are fixed. So you will yaw around the up/down axis, you will pitch around the east/west axis, and you will roll around the north/south axis.

Then the following procedure will return the plane to level-North:

1. Rotate the arm (the longitudinal axis) until it points forward/North, leaving its pitch and roll undisturbed, moving it by -Y degrees about the up/down axis.
2. Lower the arm until it points straight in front of you, moving it by -P degrees about the East-West axis.
3. Roll the plane by -R degrees, which will be around both the plane’s longitudinal axis and directly North.

Note that the angles end up exactly the same! To use this procedure to generate the necessary position for your hand, you will have to reverse the steps: roll it first, then tilt the longitudinal axis up, then swing out.

• Thank you. So in other words: $$R_z^{intrinsic}(\alpha)*R_y^{intrinsic}(\beta)*R_x^{intrinsic}(\gamma)=R_x^{extrinsic}(\gamma)*R_y^{extrinsic}(\beta)*R_z^{extrinsic}(\alpha)$$ ? Which would show that the R from the wikipedia article is in fact the rotation matrix for the yaw (z), pitch (y), roll (x) Tait-Bryan sequence that defines yaw, pitch and roll?
– Andy
Mar 23 at 14:42
• Yes, the final matrices end up being the same, there are just two different derivations of it, you could use extrinsic coordinates and roll first then pitch then yaw, or intrinsic coordinates where you yaw first then pitch then roll, by the same angles Mar 27 at 18:27

Rotation of axes around Z

Decompose rotated basis vector $$\hat{x'}$$ into unrotated basis vectors $$\hat{x}$$ and $$\hat{y}$$:

$$\hat{x'} = (\hat{x'} \cdot \hat{x})\hat{x} + (\hat{x'} \cdot \hat{y})\hat{y}$$

where the $$\cdot$$ denotes the vector dot product.

Decompose rotated basis vector $$\hat{y'}$$ into unrotated basis vectors $$\hat{x}$$ and $$\hat{y}$$:

$$\hat{y'} = (\hat{y'} \cdot \hat{x})\hat{x} + (\hat{y'} \cdot \hat{y})\hat{y}$$

thus $$T_z(\alpha)=\begin{bmatrix} cos(\alpha) & cos(\pi/2-\alpha) & 0 \\ cos(\pi/2+\alpha) & cos(\alpha) & 0 \\ 0 & 0 & 1 \end{bmatrix}= \begin{bmatrix} cos(\alpha) & sin(\alpha) & 0 \\ -sin(\alpha) & cos(\alpha) & 0 \\ 0 & 0 & 1 \end{bmatrix}$$

Rotation of axes around Y

Decompose twice rotated basis vector $$\hat{x''}$$ into once rotated basis vector $$\hat{x'}$$ and unrotated basis vector $$\hat{z}$$:

$$\hat{x''} = (\hat{x''} \cdot \hat{x'})\hat{x'} + (\hat{x''} \cdot \hat{z})\hat{z}$$

Decompose rotated basis vector $$\hat{z'}$$ into once rotated basis vector $$\hat{x'}$$ and unrotated basis vector $$\hat{z}$$:

$$\hat{z'} = (\hat{z'} \cdot \hat{x'})\hat{x'} + (\hat{z'} \cdot \hat{z})\hat{z}$$

$$T_y(\beta)=\begin{bmatrix} cos(\beta) & 0 & cos(\pi/2+\beta) \\ 0 & 1 & 0 \\ cos(\pi/2-\beta) & 0 & cos(\beta) \end{bmatrix}= \begin{bmatrix} cos(\beta) & 0 & -sin(\beta) \\ 0 & 1 & 0 \\ sin(\beta) & 0 & cos(\beta) \end{bmatrix}$$

Rotation of axes around X

Decompose twice rotated basis vector $$\hat{y''}$$ into once rotated basis vectors $$\hat{y'}$$ and $$\hat{z'}$$:

$$\hat{y''} = (\hat{y''} \cdot \hat{y'})\hat{y'} + (\hat{y''} \cdot \hat{z'})\hat{z'}$$

Decompose twice rotated basis vector $$\hat{z''}$$ into once rotated basis vectors $$\hat{y'}$$ and $$\hat{z'}$$:

$$\hat{z''} = (\hat{z''} \cdot \hat{y'})\hat{y'} + (\hat{z''} \cdot \hat{z'})\hat{z'}$$

$$T_x(\gamma)=\begin{bmatrix} 1 & 0 & 0 \\ 0 & cos(\gamma) & cos(\pi/2-\gamma) \\ 0 & cos(\pi/2+\gamma) & cos(\gamma) \end{bmatrix}= \begin{bmatrix} 1 & 0 & 0 \\ 0 & cos(\gamma) & sin(\gamma) \\ 0 & -sin(\gamma) & cos(\gamma) \end{bmatrix}$$

Chained change of basis $$T=\begin{bmatrix} 1 & 0 & 0 \\ 0 & cos(\gamma) & sin(\gamma) \\ 0 & -sin(\gamma) & cos(\gamma) \end{bmatrix}*\begin{bmatrix} cos(\beta) & 0 & -sin(\beta) \\ 0 & 1 & 0 \\ sin(\beta) & 0 & cos(\beta) \end{bmatrix}*\begin{bmatrix} cos(\alpha) & sin(\alpha) & 0 \\ -sin(\alpha) & cos(\alpha) & 0 \\ 0 & 0 & 1 \end{bmatrix}=R^{-1}$$

The matrix T is sometimes referred to as the Direct Cosine Matrix (2). In aerospace the angles are usually denoted: yaw: $$\psi$$, pitch: $$\theta$$ and bank (roll): $$\phi$$ (2).

For readability I will hereafter drop the double apostrophe and instead use a single apostrophe to denote the 3x rotated coordinate system: $$\begin{bmatrix} \hat{x'} \\ \hat{y'} \\ \hat{z'} \end{bmatrix} =T*\begin{bmatrix} \hat{x} \\ \hat{y} \\ \hat{z} \end{bmatrix}$$

Expanding T into a system of linear equations:

$$\hat{x'}=T11*\hat{x}+T12*\hat{y}+T13*\hat{z}$$ $$\hat{y'}=T21*\hat{x}+T22*\hat{y}+T23*\hat{z}$$ $$\hat{z'}=T31*\hat{x}+T32*\hat{y}+T33*\hat{z}$$ Any vector in the (3x) rotated coordinate system, $$\vec{v'}$$ may be expressed as a linear combination of the basis vectors of the (3x) rotated coordinate system: $$\vec{v'}=v'_x*\hat{x'}+v'_y*\hat{y'}+v'_z*\hat{z'}$$ Substituting the expressions for the rotated basis vectors into this equation we find:

$$\vec{v'}=v'_x*(T11*\hat{x}+T12*\hat{y}+T13*\hat{z})+v'_y*(T21*\hat{x}+T22*\hat{y}+T23*\hat{z})+v'_z*(T31*\hat{x}+T32*\hat{y}+T33*\hat{z})$$

collecting terms: $$\vec{v'}=(v'_x*T11+v'_y*T21+v'_z*T31)*\hat{x}+(v'_x*T21+v'_y*T22+v'_z*T32)*\hat{y}+(v'_x*T13+v'_y*T23+v'_z*T33)*\hat{z}+$$ thus $$v_x = v'_x*T11+v'_y*T21+v'_z*T31$$ $$v_y = v'_x*T21+v'_y*T22+v'_z*T32$$ $$v_z = v'_x*T13+v'_y*T23+v'_z*T33$$ putting these equations back into matrix form: $$\begin{bmatrix} v_x \\ v_y \\ v_z \end{bmatrix} =T^T*\begin{bmatrix} v'_x \\v'_y \\ v'_z \end{bmatrix}$$ since T is orthogonal: $$T^T=T^{-1}$$ and from before we know that: $$T^{-1}=R$$: $$\begin{bmatrix} v_x \\ v_y \\ v_z \end{bmatrix} =R*\begin{bmatrix} v'_x \\v'_y \\ v'_z \end{bmatrix}$$

thus given a vector in the coordinate system of an airplane $$[v'_x,v'_y,v'_z]$$ we can find the same vector in the unrotated (NED) coordinate system: $$[v_x,v_y,v_z]$$ by the equation above.

And $$\begin{bmatrix} v_x' \\ v_y' \\ v_z' \end{bmatrix} =T*\begin{bmatrix} v_x \\v_y \\ v_z \end{bmatrix}$$ where $$T=R^{-1}=R^T$$

thus given a vector in the in the unrotated (NED) coordinate system: $$[v_x,v_y,v_z]$$ we can find the same vector in the coordinate system of an airplane $$[v'_x,v'_y,v'_z]$$ by the equation above.

Example
$$\alpha = \gamma = \pi/2$$

$$\vec{v'}=[1,0,1]$$

$$R=\begin{bmatrix} 0 & -1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \end{bmatrix}* \begin{bmatrix} 1 & 0 & 0 \\ 0 & 0 & -1 \\ 0 & 1 & 0 \end{bmatrix}= \begin{bmatrix} 0 & 0 & 1 \\ 1 & 0 & 0 \\ 0 & 1 & 0 \end{bmatrix}$$

$$\vec{v} = \begin{bmatrix} 0 & 0 & 1 \\ 1 & 0 & 0 \\ 0 & 1 & 0 \end{bmatrix} * [1,0,1] = [1, 1, 0]$$

References