## From Euler Angle to Angle between 2 vectors

Asked by Simona Pernischova

### Simona Pernischova (view profile)

on 20 Aug 2019 at 8:49
Latest activity Edited by James Tursa

### James Tursa (view profile)

on 20 Aug 2019 at 17:15
Hi
I need the angle between two rigid bodies. Each has a local right handed 3D coordinate system, while the z axis is pointing at the direction of the body (bones in my case).
So I want the angle between the z axes. I don't know the length of the vectors but what my software is giving me are the euler angles.
I used acos(cos(alpha)*cos(betha)) to get to the angle, which is fine but does not work for small angles.
Now i have a task where i expect the angle to go from 0 to + 60 and then again to 0 and -60. But what happens is that the angles does not get smaller then 5°/-5° and then makes a jump. I have read that the issue is how acos & cos is computed and that i should use atan2d(norm(cross(u,v)),dot(u,v)); But i don't know how to apply that since i dont have the vectors, I only got the angles. To get to the vectors will take me a lot more computation time and I really don't want to do that. Is there another way?
Thanks,
Simona

James Tursa

### James Tursa (view profile)

on 20 Aug 2019 at 17:04
We need more precise definitions of your Euler Angles in order to help you. There are 12 different possible sets, and we don't know which set you are working with. Is it roll-pitch-yaw, or pitch-yaw-roll, or ...??? Once we have that sequence defined, it is a simple matter to form the z-axis of each and then find the angle between them (e.g., with that atan2 formulation).
Your statement that a formula works for big angles but not small angles is dubious ... a correct formula should work regardless of the size of the angle. Something is wrong.

### Jan (view profile)

on 20 Aug 2019 at 11:33

There is no mathematical definition of "one angle between 2 3D-bodies". There is more than 1 degeree of freedom. An angle between 2 axes is possible. What is "alpha" and "beta" in acos(cos(alpha)*cos(betha)) ? Why do you assume, that the formula "does not work" for small angles? How are the Euler angles defined in your case?
The ACOS is instable near to 0, but you get deviations in the result by up to SQRT(EPS), about 1-e8. This is no explanation for your observation, that you get +-5 deg, while you expect +-60 deg.
Of course you need the vectors to determine the angle between them. There is no magic abbreviation to determine angles between axes based on Euler angles without computations.
If your Euler Angles are defined in the order XYZ, the Z-axis points to:
M.Z = [sin(E2), -cos(E2).*sin(E1), cos(E2).*cos(E1)];
where E1, E2, E3 are the corresponding Euler angles. For other orders, other formulas are needed. There are 12 different sets of orders, so please post, which one you are using.
After the two Z axes have been calculated, this is a stable method to determine the angle:
atan2(norm(cross(Z1,Z2)), dot(Z1,Z2))