% rotationMatrix Rotation matrix ZYX for a set of Euler angles
%
%   Note: This is an internal undocumented function and its API and/or
%   functionality may change in subsequent releases.
%
%   TR 38.901 Section 7.1.3 and TR 36.873 Section 5.1.3. 
%   R = Rz*Ry*Rx is a 3-by-3 ZYX rotation matrix,
%   which is a sequential set of rotations around Z, Y, and X axis used for
%   the transformation from the local coordinates system (LCS) to the
%   global coordinate system (GCS)

%   Copyright 2020 The MathWorks, Inc.

%#codegen 
function R = rotationMatrix(angles)

    c = cosd(angles); % [cos(alpha) cos(beta) cos(gamma)]
    ca = c(1); cb = c(2); cg = c(3);
    
    s = sind(angles); % [sin(alpha) sin(beta) sin(gamma)]
    sa = s(1); sb = s(2); sg = s(3);
    
    R = zeros(3);
    R(1,1) = ca.*cb;
    R(1,2) = ca*sb*sg - sa*cg;
    R(1,3) = ca*sb*cg + sa*sg;
    R(2,1) = sa*cb;
    R(2,2) = sa*sb*sg + ca*cg;
    R(2,3) = sa*sb*cg - ca*sg;
    R(3,1) = -sb;
    R(3,2) = cb*sg;
    R(3,3) = cb*cg;
    
end