From: andy zhu on
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).

Thanks a lot.
Andy
From: andy zhu on

"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).
>
> Thanks a lot.
> Andy
From: Bruno Luong on
"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).

When you rotate an object, the 3D coordinates get transformed by the rotation matrix. So the first step is building the coordinates if not already done:

[X Y Z] = ndgrid(xgrid, ygrid, zgrid)

where xgrid, ygrid, zgrid are 1xm, 1xn, 1xp vectors (or transposed).

Now Rotate the old to new coordinates

XYZR = A*[X(:) Y(:) Z(:)].'; % Or multiply by inv(A) depending on the convention of A.

Then use INTERP3() function to rotate the intensity

XR = XYZ(1,:);
YR = XYZ(2,:);
ZR = XYZ(3,:);
IR = interp3(X,Y,Z,I,XR,YR,ZR);
IR = reshape(IR, [m n q]

Bruno
From: andy zhu on
Bruno, Walter
Thanks a lot for your help. Appreciate it.
Been busy with work these last a few days.
Andy

"Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <huvlnd$d1p$1(a)fred.mathworks.com>...
> "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).
>
> When you rotate an object, the 3D coordinates get transformed by the rotation matrix. So the first step is building the coordinates if not already done:
>
> [X Y Z] = ndgrid(xgrid, ygrid, zgrid)
>
> where xgrid, ygrid, zgrid are 1xm, 1xn, 1xp vectors (or transposed).
>
> Now Rotate the old to new coordinates
>
> XYZR = A*[X(:) Y(:) Z(:)].'; % Or multiply by inv(A) depending on the convention of A.
>
> Then use INTERP3() function to rotate the intensity
>
> XR = XYZ(1,:);
> YR = XYZ(2,:);
> ZR = XYZ(3,:);
> IR = interp3(X,Y,Z,I,XR,YR,ZR);
> IR = reshape(IR, [m n q]
>
> Bruno