title: How to calculate Euler angles from Forward, Up and Right vectors?
body: <p>Because this is a complex question that usually results in much confusion (I've asked variations on this question previously, but never asked the question the right way and never got an answer), I'm going to try to make this as clear as possible.</p>
  
  <p><strong>Facts:</strong></p>
  
  <ul>
  <li>I'm using Unity.</li>
  <li>I'm can get the Forward, Up and Right vectors easily from any Quaternion rotation.</li>
  <li>I can't simply record my own Euler angles, modify them and apply the rotation through a new Quaternion because the object is controlled by physics.</li>
  <li>I don't understand maths very well at all unless it's written in code (or pseudo-code), so this would be most beneficial to me.</li>
  <li>A C++ style answer would be easiest for me to understand, but I can work out pretty much any kind of code.</li>
  <li>I'm NOT trying to get anyone to write the code for me! I'm only asking for the answer in code or pseudo-code because I never learned to read normal maths squiggles; I'm a programmer, not a mathematician.</li>
  <li>Unity uses a left-handed coordinate system. X = right, Y = up, Z = forward.</li>
  </ul>
  
  <p><strong>What I'm trying to do:</strong></p>
  
  <p>I'm trying to play an animation on a humanoid bone structure and, using torque (rotational force), push the physics ragdoll into approximately the same pose as the bone structure.</p>
  
  <p><strong>The problem:</strong></p>
  
  <p>I can work fully in Quaternions right up to the point where I need to apply the torque to the rigidbodies. The <code>AddTorque</code>  function effectively works in Euler angles, which means I can't use the Quaternions. I can easily extract Euler angles from the Quaternions, but they are unreliable and cause the ragdoll to spaz out severely.</p>
  
  <p><strong>What I need:</strong></p>
  
  <p>I need to calculate reliable 3D Euler angles (as in, ones that don't flip from + to - "randomly") from Forward, Up and Right vectors. I realise this is a bit complicated, but that's why I ask here: I lack the knowledge and experience to work out this problem myself.</p>
  
  <p>Given that the vectors themselves are reliable, I see no reason why it would not be possible to work out reliable Euler angles from them. Also, I don't know what order of rotation I would want or need for the Euler angles, but I believe that would be fairly easy to modify later.</p>
  
  <p>Any help would be much appreciated!</p>