Get permutation matrix from rotation matrix Rout = get_transform_axis(RS) RS : rotation + flip + scaling [3 x 3] Rout : transform matrix corresponding to axis permutation + flip + scaling
0001 function Rout = get_transform_axis(RS) 0002 % Get permutation matrix from rotation matrix 0003 % Rout = get_transform_axis(RS) 0004 % RS : rotation + flip + scaling [3 x 3] 0005 % Rout : transform matrix corresponding to axis permutation + flip + scaling 0006 0007 % R = [ex; ey; ez] : rotation matrix 0008 % RS = diag(ss) * R = diag(ss) * [ex; ey; ez] : rotation matrix with scaling 0009 % X_to = X * RS 0010 0011 % RS * RS' = diag(ss.^2) 0012 % ss = sqrt( diag( RS * RS' ) ) 0013 0014 % Get scaling factor 0015 % RS = diag(ss) * R = [sx*ex; sy*ey; sz*ez ] 0016 ss = sqrt( sum( RS.^2, 2 ) ); 0017 0018 % Get Rotation matrix corresponding to permutation with flip 0019 % each element is (plus/minus) ones and zeros 0020 R = zeros(3,3); 0021 0022 [tmp, ix] = max(abs(RS), [], 2); 0023 0024 for i = 1:3 0025 R(i, ix(i)) = sign(RS(i, ix(i)) ); 0026 end 0027 0028 Rout = diag(ss) * R;