If represents this vector in the rotated device
body frame xyz, then
The transformation of due to the rotation about
the z axis can be represented by the following rotation matrix.
The transformation of due to the rotation about
the x axis can be represented by the following rotation matrix.
The transformation of due to the rotation about
the y axis can be represented by the following rotation matrix.
If resresents the vector
in the earth frame XYZ, then since the inital body frame is aligned with the
earth, is as follows.
The compass heading is given by
provided that and
are not both zero.
As a consistency check, if we set
, then
as expected.