3
votes

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).

enter image description here

2

2 Answers

0
votes

In MATLAB:

If I use directional cosine or the quaternion in order to rotate the point, I am actually rotating the reference frame:

pdc = (DC01*p0')'    % rotation using directional cosine matrix
pdc =

    0.9848   -0.1736         0

equivalent to:

p1_1 = quatrotate(q1,p0);
p1_1 = 

     0.9848   -0.1736         0

On the other hand, using Euler angles and rotation matrices, I can rotate a point (a vector) w.r.t a coordinate system:

p1_2 = (rotz(rz*180/pi)*roty(ry*180/pi)*rotx(rx*180/pi)*p0').';
p1_2 =

    0.9848    0.1736         0

Conclusion: Using quaternion or directional cosine matrix, we rotate the coordinate systems while the point (vector) stays fixed. Whereas, using rotation matrices we are able to rotate a vector w.r.t a coordinate system.

0
votes

I have encountered same phenomenon with you when I use dcm and quaternion to rotate a vector.

We can consider WCS as the only one reference. Abovementioned DCM rotates a vector counterclockwisely, quaternion rotates a vector clockwisely.