From: Walter Roberson on
andy zhu wrote:
>
> "andy zhu" <chenhui.zhu(a)colorado.edu> wrote in message
> <hutn30$jto$1(a)fred.mathworks.com>...
>> Dear ALL
>>
>> I have a 3-D space, there are m, n, p points along x, y, z
>> respectively. at each (x,y,z), there is an density, I(x,y,z).
>> Physically, it is like a density map inside a 3-D box. and the density
>> are stored in a matrix, m by n by p.
>> I'd like to rotate this matrix using euler angles. The euler rotation
>> matrix, A, is 3 by 3, consisting of the rotation angles, theta, phi, psi.
>> The question is how I to do this, because the dimension of A (3 X 3)
>> does not quite match I (m X n X p).

for k = 1 : p
for j = 1 : n
for i = 1 : m
newxyz(:,i,j,k) = A * [x(i) y(j) z(k)];
end
end
end

Now you can proceed to vectorize this.

Note that this will return the new coordinates but will not move the contents
of the matrix. If you want to do the equivalent of the 2D imrotate() then you
could work an angle at a time, rotating slices of the matrix according to
which angle was fixed, then slicing the result and rotating those slices on
the second angle, and so on.