function R = rotation_matrix(axN,ayN,azN,w); % function R = rotation_matrix(axN,ayN,azN,w); % Generates the rotation matrix for a rotation of the % coordinate axes about an axis N by a rotation w. % Input parameters % axN = direction cosine of angle between x-axis and N; % ayN = direction cosine of angle between y-axis and N; % azN = direction cosine of angle between z-axis and N; % w = rotation angle (in degrees); % Output parameters % R = rotation matrix % Example % R = rotation_matrix(1,0,0,90); cosw = cos(deg2rad(w)); sinw = sin(deg2rad(w)); a11 = axN.*axN.*(1-cosw) + cosw; a12 = axN.*ayN.*(1-cosw) + azN.*sinw; a13 = axN.*azN.*(1-cosw) - ayN.*sinw; a21 = ayN.*axN.*(1-cosw) - azN.*sinw; a22 = ayN.*ayN.*(1-cosw) + cosw; a23 = ayN.*azN.*(1-cosw) + axN.*sinw; a31 = azN.*axN.*(1-cosw) + ayN.*sinw; a32 = azN.*ayN.*(1-cosw) - axN.*sinw; a33 = azN.*azN.*(1-cosw) + cosw; R = [a11 a12 a13; a21 a22 a23; a31 a32 a33];