Search code examples
matlabrotationrotational-matriceseuler-angles

Matlab angle2dcm different definition


I am using MATLAB function angle2dcm which gives me different results from what I expected. By digging into the code (angle2dcm.m) I found the definition of forming the rotation matrix is different from the standard one.

For example, rotation RxRyRz (i.e. 'xyz' order) is defined as:

%     [          cy*cz, sz*cx+sy*sx*cz, sz*sx-sy*cx*cz]
%     [         -cy*sz, cz*cx-sy*sx*sz, cz*sx+sy*cx*sz]
%     [             sy,         -cy*sx,          cy*cx]

while normally it should be (please refer to the link): http://inside.mines.edu/fs_home/gmurray/ArbitraryAxisRotation/

Is it different definition of direction cosine matrix and rotation matrix? Thanks!


Solution

  • It's an issue with notation conventions, since the two cases (MATLAB versus the link you posted) refer to opposite orders of rotation. If you want to use the MATLAB function and continue to use the convention from the link you posted, as a possible workaround you can call the function with 'zyx' and invert the signs of all the angles, i.e.

     dcm = angle2dcm( -r1, -r2, -r3,'xyz');       *EDITED*
    

    which uses the following rotation matrix (see matlab documentation)

             [          cy*cz, sz*cx+sy*sx*cz, sz*sx-sy*cx*cz]
             [         -cy*sz, cz*cx-sy*sx*sz, cz*sx+sy*cx*sz]
             [             sy,         -cy*sx,          cy*cx]
    

    If this is confusing you could even wrap everything in a helper function that does the sign and order inversion for you, something like

     function dcm = angle2dcm_mines( r1, r2, r3);
     dcm = angle2dcm( -r1, -r2, -r3,'xyz');
    

    There are other ways to work around this but that should work.