2

How do I rotate a 3D array in matlab?

My input data is a matrix n*n*n. I want to rotate it around its center to an arbitrary angle (theta, phi) and have another n*n*n matrix at output (wherever the values are defined, of course).

For example, given

a(:,:,1) = [0 0 0; 
            0 0 0;
            0 0 0];
a(:,:,2) = [0 0 0; 
            0 0 1;
            0 0 0];
a(:,:,3) = [0 0 0; 
            0 0 0;
            0 0 0];

being rotated to [pi/2; pi/2] (thus, 45 deg around Z and 45 deg around x) should produce smth like

a(:,:,1) = [0 0.1 0.5; 
            0 0.05 0.1;
            0   0   0];
a(:,:,2) = [0 0.1 0.05; 
            0   0 0.1;
            0   0   0];
a(:,:,3) = [0   0   0; 
            0   0   0;
            0   0   0];

(Values are approximate).

If there is a built-in function for this? Of what would you suggest me to create it?

Andrew
  • 201
  • 1
  • 3
  • 10
  • 5
    I imagine the image processing toolbox has this built in but otherwise: http://blogs.mathworks.com/steve/2006/08/17/spatial-transformations-three-dimensional-rotation/, http://www.mathworks.com/matlabcentral/fileexchange/25596-transform-a-3d-volume-by-using-an-affine-transformation-matrix, http://www.mathworks.com/matlabcentral/fileexchange/30864-3d-rotation-about-shifted-axis and finally http://www.mathworks.com/matlabcentral/fileexchange/27300-image-rotate-scale-and-translate – Dan Oct 18 '13 at 13:18

0 Answers0