I can see where some of the confusion comes from because I didn't post the full explaination of how I got those values. It comes from the
Euler->Matrix(inertial->object) formula. Here is how you convert from Euler->Matrix(I know you already know how to do this, DaZ_MaN_Ym, I'm just showing it to explain where I got the Matrix->Euler equations):
X angle = Pitch = p
Y angle = Heading = h
Z angle = Bank = b
{cos(h)cos(b)+sin(h)sin(p)sin(b) -cos(h)sin(b)+sin(h)sin(p)cos(b) sin(h)cos(p)
sin(b)cos(p) cos(b)cos(p) -sin(p)
-sin(h)cos(b)+cos(h)sin(p)cos(b) sin(b)sin(h)+cos(h)sin(p)cos(b) cos(h)cos(p)}
Since m23 = -sin(p) I could solve for p by rearranging the equation to this asin(-m23) = p as I did in my previous post.
Now that p has been defined we can also know the value of cos(p).
m13 = sin(h)cos(p)
m13/cos(p) = sin(h)
m33 = cos(h)cos(p)
m33/cos(p) = cos(h)
So to get the heading we would do this:
heading = atan2(sin(h), cos(h))
Which is the exact same thing as this:
heading = atan2(m13/cos(p), m33/cos(p))
This is why are trick here won't work when the pitch = 0 because all of the matrix elements involved are zero and we can't divide by zero.
But as I explained before, When we know that pitch is 0 that means we are looking straight up or down. So we can simplify rotation by lobbing all of it into heading and setting bank rotation to zero.
When we know that pitch and bank are equal to zero we can make the following assumtions:
cos(p) = 0
b = 0
sin(b) = 0
cos(b) = 1
And then we can simplify the above inertial->object equation from this:
{cos(h)(1)+sin(h)sin(p)(o) -cos(h)(0)+sin(h)sin(p)(1) sin(h)(0)
(0)(0) (1)(0) -sin(p)
-sin(h)(1)+cos(h)sin(p)(0) (0)sin(h)+cos(h)sin(p)(1) cos(h)(0)}
Which can be simplified to:
{cos(h) sin(h)sin(p) 0
0 0 -sin(p)
-sin(h) cos(h)sin(p) 0}
Then heading can be computed from -m31 and m11 which contain the sine and cosine of the heading respectively.
Anyway, now that how I got the heading, pitch, and bank is clear(or at least I hope so) I can give you the object->inertial Euler->Matrix formula so you can convert it to Matrix->Euler:
Euler->Matrix
Object->Inertial
{cos(h)cos(b)+sin(h)sin(p)sin(b) sin(b)cos(p) -sin(h)cos(b)+cos(h)sin(p)sin(b)
-cos(h)sin(b)+sin(h)sin(p)cos(b) cos(b)cos(p) sin(b)sin(h)+cos(h)sin(p)cos(b)
sin(h)cos(p) -sin(p) cos(h)cos(p)}
Just post if you need help getting the Matrix->Euler values out of it or if you need any clarification on anything.I can see where some of the confusion comes from because I didn't post the full explaination of how I got those values. It comes from the
Euler->Matrix(inertial->object) formula. Here is how you convert from Euler->Matrix(I know you already know how to do this, DaZ_MaN_Ym, I'm just showing it to explain where I got the Matrix->Euler equations):
X angle = Pitch = p
Y angle = Heading = h
Z angle = Bank = b
{cos(h)cos(b)+sin(h)sin(p)sin(b) -cos(h)sin(b)+sin(h)sin(p)cos(b) sin(h)cos(p)
sin(b)cos(p) cos(b)cos(p) -sin(p)
-sin(h)cos(b)+cos(h)sin(p)cos(b) sin(b)sin(h)+cos(h)sin(p)cos(b) cos(h)cos(p)}
Since m23 = -sin(p) I could solve for p by rearranging the equation to this asin(-m23) = p as I did in my previous post.
Now that p has been defined we can also know the value of cos(p).
m13 = sin(h)cos(p)
m13/cos(p) = sin(h)
m33 = cos(h)cos(p)
m33/cos(p) = cos(h)
So to get the heading we would do this:
heading = atan2(sin(h), cos(h))
Which is the exact same thing as this:
heading = atan2(m13/cos(p), m33/cos(p))
This is why are trick here won't work when the pitch = 0 because all of the matrix elements involved are zero and we can't divide by zero.
But as I explained before, When we know that pitch is 0 that means we are looking straight up or down. So we can simplify rotation by lobbing all of it into heading and setting bank rotation to zero.
When we know that pitch and bank are equal to zero we can make the following assumtions:
cos(p) = 0
b = 0
sin(b) = 0
cos(b) = 1
And then we can simplify the above inertial->object equation from this:
{cos(h)(1)+sin(h)sin(p)(o) -cos(h)(0)+sin(h)sin(p)(1) sin(h)(0)
(0)(0) (1)(0) -sin(p)
-sin(h)(1)+cos(h)sin(p)(0) (0)sin(h)+cos(h)sin(p)(1) cos(h)(0)}
Which can be simplified to:
{cos(h) sin(h)sin(p) 0
0 0 -sin(p)
-sin(h) cos(h)sin(p) 0}
Then heading can be computed from -m31 and m11 which contain the sine and cosine of the heading respectively.
Anyway, now that how I got the heading, pitch, and bank is clear(or at least I hope so) I can give you the object->inertial Euler->Matrix formula so you can convert it to Matrix->Euler:
Euler->Matrix
Object->Inertial
{cos(h)cos(b)+sin(h)sin(p)sin(b) sin(b)cos(p) -sin(h)cos(b)+cos(h)sin(p)sin(b)
-cos(h)sin(b)+sin(h)sin(p)cos(b) cos(b)cos(p) sin(b)sin(h)+cos(h)sin(p)cos(b)
sin(h)cos(p) -sin(p) cos(h)cos(p)}
Just post if you need any help getting the Matrix->Euler formulas out of that or need if you need any clarification on anything that I've said(I think I've forgotten to say something but I'm just not sure what right now).