From: Andy on
Hi all,
I am currently having trouble rotating my matrix so that I can use it in further calculations.

The matrix is 64X64X64 and consists of numerical values representing a magnetic field strength at the point indicated by it's location in the matrix (the value of field(a,b,c) shows the field's strength at x=a y=b z=c on a conventional axis).

I am using myslicer to interactively view slices of the field, which are color coded corresponding to field strength value (the fourth dimension).

What I would like to do is rotate the entire matrix 0.3722 rad clockwise around a vector running through it's center parallel to the y axis. I know how to do this using the viewer, but I would like the matrix representation of the rotated field as well for use in calculations.

Is there a way to do this? I have been trying to relocate the center of the matrix at the origin so that it spans from -32 to +31 in all three directions but have been unable to do so because the coordinates for each point come from it's location in the matrix, which cannot be negative.

Let me know if you require additional information.
Thanks so much!
From: Jan Simon on
Dear Andy,

> What I would like to do is rotate the entire matrix 0.3722 rad clockwise around a vector running through it's center parallel to the y axis. I know how to do this using the viewer, but I would like the matrix representation of the rotated field as well for use in calculations.
>
> Is there a way to do this? I have been trying to relocate the center of the matrix at the origin so that it spans from -32 to +31 in all three directions but have been unable to do so because the coordinates for each point come from it's location in the matrix, which cannot be negative.

Do not confuse the indices of the matrix and the position in space.
You cannot rotate a mtrix, but its values. The 64x64x64 array are the values and the positions are determined by the indices - correctly?
Then create a further array, which contains the 3D coordinates of the points. The values of these coordinates can be rotated easily by a multiplication with a rotation matrix. Now the value array is not changed, but you need the location array in addition to display it.

Good luck, Jan
From: Andy on
"Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message
> Do not confuse the indices of the matrix and the position in space.
> You cannot rotate a mtrix, but its values. The 64x64x64 array are the values and the positions are determined by the indices - correctly?
> Then create a further array, which contains the 3D coordinates of the points. The values of these coordinates can be rotated easily by a multiplication with a rotation matrix. Now the value array is not changed, but you need the location array in addition to display it.
>
> Good luck, Jan

Jan,
I am still a bit confused about this location array. Are it's elements the coordinates of all my points? Ex: " 1 1 1", "1 1 2", ..., "64 64 64"

Also, I can't seem to figure out the correct rotation matrix because my object is not centered at the origin. Can you help me with this as well?

Thanks so much!
From: Jan Simon on
Dear Andy,

> I am still a bit confused about this location array. Are it's elements the coordinates of all my points? Ex: " 1 1 1", "1 1 2", ..., "64 64 64"

Correct. I'd store the coordinates in a C = [64^3 x 3] matrix.

> Also, I can't seem to figure out the correct rotation matrix because my object is not centered at the origin. Can you help me with this as well?

You can center the coordinates:
Ccentered = C - (64 + 1) / 2;
Then the rotation matrix:
Crotated = Ccentered * [cos(a), 0, -sin(a); 0, 1, 0; sin(a), 0, cos(a)]
The sign before the SIN depends on the (counter)clockwise orientation of the rotation, so please adjust this to your demands.
Finally you can uncenter the coordinates again:
C = C + 32.5
But to be correct: If you have the coordinate matrix, you could stay at the centered coordinate values for simplicity.

Good luck, Jan
From: Andy on
"Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <i14vlo$i9m$1(a)fred.mathworks.com>...
> Dear Andy,
>
> > I am still a bit confused about this location array. Are it's elements the coordinates of all my points? Ex: " 1 1 1", "1 1 2", ..., "64 64 64"
>
> Correct. I'd store the coordinates in a C = [64^3 x 3] matrix.
>
> > Also, I can't seem to figure out the correct rotation matrix because my object is not centered at the origin. Can you help me with this as well?
>
> You can center the coordinates:
> Ccentered = C - (64 + 1) / 2;
> Then the rotation matrix:
> Crotated = Ccentered * [cos(a), 0, -sin(a); 0, 1, 0; sin(a), 0, cos(a)]
> The sign before the SIN depends on the (counter)clockwise orientation of the rotation, so please adjust this to your demands.
> Finally you can uncenter the coordinates again:
> C = C + 32.5
> But to be correct: If you have the coordinate matrix, you could stay at the centered coordinate values for simplicity.
>
> Good luck, Jan

Jan,
One last thing, how do I create a [64^3x3] matrix? I was trying to create a [64x64x64] matrix which just consisted of strings representing the coordinates but that did not work?
Thanks