I am using two methods to rotate a point p0
(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 dcm2quat
and dcm2angle
. Then I can rotate the point p0
using both quaternion and Euler angles.
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').';
But at the end the results are different:
p1_1 =
0.9848 -0.1736 0
p1_2 =
0.9848 0.1736 0
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?
The following image shows CS1 (blue), WCS (black), p0
(black), p1_1
(blue), p1_2
(red).