title: Quaternions still have gimbal lock
body: <p>Instead of Euler angles I moved to Quaternions to represent and process the rotation of a cube in 3D. Although it would solve gimbal lock, I'm still experiencing this issue.</p>
  
  <p>My code is:</p>
  
  <pre><code>// p is the point to be rotated
  // angles is a Vector3D representing the rotation angles
  
  var xaxis = new Vector3D(1, 0, 0);
  var yaxis = new Vector3D(0, 1, 0);
  var zaxis = new Vector3D(0, 0, 1);
  
  p = rotate(p, xaxis, angles.x);
  p = rotate(p, yaxis, angles.y);
  p = rotate(p, zaxis, angles.z);
  </code></pre>
  
  <p>The <code>rotate</code> functions comes from <a href="http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation#Pseudo-code_for_rotating_using_a_quaternion_in_3D_space" rel="nofollow">http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation#Pseudo-code_for_rotating_using_a_quaternion_in_3D_space</a> (translated into JavaScript).</p>
  
  <p>I guess the problem is due to the fact that I still use an order of axes (<code>x y z</code>) which is the main problem of gimbal lock.</p>
  
  <p>How would one implement quaternion rotation in such a way that gimbal lock is solved?</p>
  
  <p>Thanks in advance.</p>