[Math] How to extract Euler angles from a a point in a plane

geometry

Given a certain coordinate frame, I can compute a new one by applying a set of rotations in a given order (what I call Euler $Z-Y-X$). So I yaw, then pitch then roll.

Now imagine that I want to do exactly the opposite: given two coordinate frames (same origin to simplify), how do I find out roll, pitch and yaw angles that were used to transform from one to the other?

Best Answer

The details will vary according to what you mean exactly by yaw, pitch, roll. But here is a general way of transforming the axes. It may not be the best theoretical way to do it, but it works fine computationally.

Let rotations about the $X$-axis by an angle $\theta$ be denoted by $R_{X,\theta}$, and similarly for the other axes. A frame is then obtained by $$T_{\theta,\phi,\psi}:=R_{X,\phi}R_{Y,\theta}R_{Z,\psi}$$

If I understand your question correctly, you want the three angles that would give $T_1T_2^{-1}$ given two frames $T_1$, $T_2$.

  1. Calculate the matrix $S:=T_1T_2^{-1}$
  2. Calculate $\phi=\arctan_2(S_{3,3},-S_{2,3})$, $\theta=\arctan_2(\sqrt{S_{1,1}^2+S_{1,2}^2},S_{1,3})$, $\psi=\arctan_2(S_{1,1},-S_{1,2})$.

Then $\theta$, $\phi$, and $\psi$ are the required angles. Here $\arctan_2(x,y)$ is the modified arctan function that gives the angle in the correct quadrant.

Note that there may be different values of $\phi$, $\theta$, $\psi$ that give the same transformation $S$.