title: different results using quaternion and Euler angles
body: <p>I am using two methods to rotate a point <code>p0</code> (a vector) in 3D space. I have the world coordinate system (WCS), shown in black, and coordinate system 1 (CS1), shown in blue, which is defined to be rotated by 10 degrees around z-axis. I first calculate the directional cosine between WCS and CS1, by calculating dot products. Now I can easily calculate both the quaternion and the Euler angles using <code>dcm2quat</code> and <code>dcm2angle</code>. Then I can rotate the point <code>p0</code> using both quaternion and Euler angles.</p>
  
  <pre><code>p0  = [1 0 0]; % point in world CS
  ijk = [1 0 0;0 1 0;0 0 1];
  uvw1 = [0.9848 0.1736 0;-0.1736 0.9848 0;0 0 1.0000]; % CS1
  DC01 = [dot(uvw1(1,:),ijk(1,:)) dot(uvw1(1,:),ijk(2,:)) dot(uvw1(1,:),ijk(3,:))
          dot(uvw1(2,:),ijk(1,:)) dot(uvw1(2,:),ijk(2,:)) dot(uvw1(2,:),ijk(3,:))
          dot(uvw1(3,:),ijk(1,:)) dot(uvw1(3,:),ijk(2,:)) dot(uvw1(3,:),ijk(3,:))];
  
  [rz, ry, rx] = dcm2angle(DC01,'ZYX'); 
  q1 = dcm2quat(DC01);
  
  p1_1 = quatrotate(q1,p0);
  p1_2 = (rotz(rz*180/pi)*roty(ry*180/pi)*rotx(rx*180/pi)*p0').';
  </code></pre>
  
  <p>But at the end the results are different:</p>
  
  <pre><code>p1_1 = 
      0.9848   -0.1736         0
  p1_2 =
      0.9848    0.1736         0
  </code></pre>
  
  <p>I understand that using Euler angles can result in gimbal lock and make ambiguity, but in this case the result obtained using quaternion is not correct while the result obtained from the Euler angles is. What am I missing?</p>
  
  <p>The following image shows CS1 (blue), WCS (black), <code>p0</code> (black), <code>p1_1</code> (blue), <code>p1_2</code> (red).</p>
  
  <p><a href="https://i.stack.imgur.com/Da907.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Da907.png" alt="enter image description here"></a></p>