From direction cosine matrix to Cardan angles - Two different Matlab codes, different results

189 Views Asked by At

I have two Matlab codes to get the Cardan angles (ZXY sequence) starting from a given direction cosine matrix (dcm), but the results are different. Why?

The dcm is:

dcm = [0.5972   -0.7833   0.1729;
       0.7990   0.5987    -0.0553;
       -0.0592  0.1719    0.9832];

First code (alpha=angle around x, beta=angle around y, gamma=angle around z):

[gamma, alpha, beta] = dcm2angle(dcm,'ZXY');
% Result:
%   -0.9277   -0.0553   -0.1741

Second code:

if abs(dcm(3,2)) ~= 1
    alpha = asin(dcm(3,2));
    %
    if dcm(3,3) >= 0
        beta = asin(-dcm(3,1)/cos(alpha));
    else
        beta = pi - asin(-dcm(3,1)/cos(alpha));
    end
    %
    if dcm(2,2) >= 0
        gamma = asin(-dcm(1,2)/cos(alpha));
    else
        gamma = pi - asin(-dcm(1,2)/cos(alpha));
    end
end
% Result:
%   0.9192    0.1728    0.0601

The dcm for the sequence ZXY in terms of sin and cos is:

enter image description here

Thank you so much for your willingness.