%The function rotates the elastic stiffness matrix from the media symmetric coordinate frame to the borehole coodinate frame
%Inputs:
    %C1- the elastic stiffness matrix in the media symmetric frame;
    %alphazm1 The rotation angle of the medium symmetry frame around D-axis;
    %alphaym The rotation angle of the medium symmetry frame around y'-axis;
    %alphazm2 The rotation angle of the medium symmetry frame around zm-axis;
    %traj = [boreholeI boreholeA]: A 1 X 2 vector describing inclination and azimuth of the borehole; 
    %All the angles are input referred to the NED frame.
%Outputs:
    %C- the elastic stiffness matrix in the borehole coordinate frame.
function C=StiffnessRotation3D(C1, alphazm1, alphaym, alphazm2, traj) % input angles are all in radian
M1=BondZ(-alphazm1); % Function BondZ is the Bond rotation around Z-axis
M2=BondY(-alphaym); % Function BondY is the Bond rotation around Y-axis
M3=BondZ(-alphazm2);
M4=BondZ(traj(2));
M5=BondY(traj(1));
C=M5*M4*M1*M2*M3*C1*M3.'*M2.'*M1.'*M4.'*M5.'; % equation (6)
C(abs(C)<10^(-10))=0;