title: Calculating Roll, Pitch and Yaw from angles
body: <p>I am working on a simulation of an aircraft with three axes of motion (roll, pitch and yaw).
  I have the roll angle (number of degrees the wings are tilted about the nose-tail axis of the aircraft), pitch angle (angle between the nose and the horizon) and yaw angle (the compass heading of the aircraft).</p>
  
  <p>What I am trying to determine is the unit vector of lift (ie. the vector which is "up" from the aircraft) - ie. when the aircraft is straight and level the vector for lift should point straight up, when the aircraft's nose is straight up the lift vector is given by <code>180 - roll_angle</code>, etc.</p>
  
  <p>I have made partial progress with only two angles (eg. roll and yaw) by simply taking the spherical co-ords of the new point and converting to cartesian and taking the normal to the plane given by the resultant vector. However, I am unsure how to take into account the third angle (pitch).</p>
  
  <p>What I am looking to achieve is a function which accepts the three angles (roll, pitch and yaw) and gives the unit vector of lift.</p>
  
  <pre><code>function get_lift_vector()
  {
      var lift_vector_heading = 0;
      var lift_vector_elevation = 90;
  
      // Adjust to range (-180, 180]
      roll_angle %= 360;
      if(roll_angle &gt; 180)
      {
          roll_angle = 180 - roll_angle;
      }
  
      // Roll
      if(roll_angle &gt; 0)
      {
          lift_vector_heading = 90;
          lift_vector_elevation = 90 - roll_angle;
      }
      else if(roll_angle &lt; 0)
      {
          lift_vector_heading = 270;
          lift_vector_elevation = 90 - roll_angle;
      }
  
      // Yaw
      lift_vector_heading += aircraft_compass_heading;
      lift_vector_heading %= 360;
  
      // Pitch
  
  }
  </code></pre>