The Murder / Suicide flight is almost certain to be due to a bug in the current Matrix:

```
|Xe| = |cos(pitch), 0, sin(pitch)||Xq|
|Ye| = |0, cos(roll), sin(roll)||Yq|
|Ze| = |sin(pitch), sin(roll), cos(pitch)cos(roll)||Zq|
```

I’ve arranged it such that if Phoebe is nose down, or left-side down, the pitch and roll angles are negative respectively.

Forward, leftward and upward movement results in positive accelerometer values.

The diagram below shows the vectors representing Phoebe pitching nose down and moving right to left as a result. Her sensor vectors are in gold, and their translation to earth axis vectors in black. Phoebe is pitched nose downwards, so the angle of pitch is negative.

Here’s the revised value of the Matrix that ensures the earth vectors match those shown in the picture.

`|Xe| = |cos(pitch), 0, -sin(pitch)||Xq|`

`|Ye| = |0, cos(roll), -sin(roll)||Yq|`

`|Ze| = |sin(pitch), sin(roll), cos(pitch)cos(roll)||Zq|`

Critically, this means that when calculating eax based upon the faz vector, because the pitch angle is negative, so is sin(pitch), yet the eax vector is showing forward (and therefore positive) acceleration. Hence right hand column of the matrix where it shows -sin(pitch) and -sin(roll).

The same is not necessary when deriving eaz from the fax vector; eaz is shown as negative, and so fax*sin (pitch) already produces the correct negative result.

The case for the y axis is identical.

Hopefully there will a slot in the weather tomorrow for me to test this.

Somehow I’m annoyed with myself for not catching that… you are rotating something (the axes), so of course half the non-diagonal entires shoudl be negative! See http://en.wikipedia.org/wiki/Rotation_matrix (NB:, if you had “positive pitch” = “tilting down”, then you’d still have a positive and a negative, just the other way round).

With yaw you get:

|Xe| |cos(pitch)cos(yaw), -sin(yaw), -sin(pitch)| |Xq|

|Ye| = |sin(yaw), cos(roll)cos(yaw), -sin(roll)| |Yq|

|Ze| |sin(pitch), sin(roll), cos(pitch)cos(roll)||Zq|

… but only if postive yaw angle is *clockwise* rotation as viewed from above. (Which is the geographer’s way, not the mathemtician’s way… but that makes dealing with a compass easier.)

Oooh, using an obscure unicode “space” made things align 🙂

🙂