I'm looking for a way to convert direction vector (X,Y,Z) into Euler angles (heading, pitch, bank). I know that direction vector by itself is not enough to get the bank angle, so there's also another so-called Up vector.
Having direction vector (X,Y,Z) and up vector (X,Y,Z) how do I convert that into Euler angles?
Let's see if I understand correctly. This is about the orientation of a rigid body in three dimensional space, like an air plane during flight. The nose of that airplane points towards the direction vector
Towards the roof is the up vector
Then heading
H
would be the direction vectorD
projected onto the earth surface:with an associated angle
Pitch P would be the up/down angle of the nose with respect to the horizon, if the direction vector
D
is normalized you get it fromresulting in
Finally, for the bank angle we consider the direction of the wings, assuming the wings are perpendicular to the body. If the plane flies straight towards
D
, the wings point perpendicular toD
and parallel to the earth surface:This would be a bank angle of 0. The expected Up Vector would be perpendicular to
W0
and perpendicular toD
with
×
denoting the cross product.U
equalsU0
if the bank angle is zero, otherwise the angle betweenU
andU0
is the bank angleangle_B
, which can be calculated fromHere 'abs' calculates the length of the vector. From that you get the bank angle as
The normalization factors cancel each other if
U
andD
are normalized.we need three vectors: X1, Y1, Z1 of local coordinate system (LCS) expressed in terms of world coordinate system (WCS). The code below presents how to calculate three Euler angles based on these 3 vectors.