Hi guys
Assume we have a 2D matrix A1 which includes x and y locations. I have calculated the values related to each (x,y) of matrix A1 and then put them in another matrix of B1, with the same dimension as A1. In other words, I have a 3D matrix that I have defined it like this.
Now, I need to rotate this 3D matrix around z axis and add it to the previous one, not rotated one, I am confused how to do this. The problem is that this rotation, changes, of course, x and y locations, so I cannot simply add two matrices because the new matrix has different x and y locations. But B1 stays the same. Can you please help me figure this out?
Thanks

3 comentarios

Rik
Rik el 26 de Abr. de 2018
You should use explicit coordinates instead of matrix positions (e.g. every row should contain the coordinates to a single point). Then rotating the matrix will not change the positional information.
Hossein
Hossein el 26 de Abr. de 2018
That is a very interesting answer. How can I use explicit coordinates? I have not tried this before.
Hossein
Hossein el 26 de Abr. de 2018
The only way I know to define a coordinate is meshgrid. And if I do so, I need to rotate it and then how to add relevent new (x,y)s to the previous ones?

Iniciar sesión para comentar.

 Respuesta aceptada

Rik
Rik el 26 de Abr. de 2018

0 votos

You need to apply a conversion to the values inside the matrix, not the matrix itself. Using meshgrid is indeed helpful for generating explicit coordinates.
You could even use arrayfun and use a normal rotation matrix (untested code):
[X,Y]=meshgrid(x_coordinates,y_coordinates);
Z=some_function(X,Y);
[new_X,new_Y,new_Z]=arrayfun(@apply_transform,X,Y,Z);
function [new_x,new_y,new_z]=apply_transform(x,y,z)
R=eye(4);%replace by actual transform matrix
v=[x;y;z;1];
new_v=R*v;
new_x=new_v(1);
new_y=new_v(2);
new_z=new_v(3);
end

3 comentarios

Hossein
Hossein el 27 de Abr. de 2018
Hi Rik
Thanks for your answer. I have a few questions about your code:
1. What are these new_x, new_y as we decided to fix x and y coordinates? as we decided to fix the coordinate.
2. The transformation matrix is Rz(γ)=[cosγ,sinγ,0; sinγ, cosγ, 0; 0, 0, 1]; which is a 3*3 matrix. How we can apply these to the two matrices I have, A1 which includes X and Y coordinates, and B1 which includes the values corresponds to each location in A1.
3. why did you define you your "v" vector a 4 element one? we only have three dimensions. I know it is related to eye(4), but for the rotation does it make sense? Also, x, y, and z are not numbers, they are 2D matrices.
Thanks for your help
Rik
Rik el 27 de Abr. de 2018
Each position in the matrices X,Y,Z is a single point, where each matrix contains one coordinate element. You can choose to overwrite the old matrices with the new coordinates, but that is your choice. I chose to write it this way to clarify where the change happens.
I don't really understand what you mean with how A1 is structured, but this point is connected to your third question. To facilitate not only rotation and translation, but also scaling, the transformation matrices are sometimes written as a (dimension+1)-by-(dimensions+1) matrix. The (end,end) position is 1 if no scaling should be applied. The rest of the last col/row contain only zeros. If you choose to use this structure, your vector to be transformed is [x;y;z;1].
As for the last thing you mention: read the documentation for arrayfun. X,Y,Z are array inputs, and the function is applied on each position separately, so inside the function x,y,z are scalar. That is the reason for my choice in upper/lower case variable names.
Rik
Rik el 30 de Abr. de 2018
Did my answer solve your problem? If so, please mark it as accepted answer, if not, feel free to comment with your remaining questions.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 26 de Abr. de 2018

Comentada:

Rik
el 30 de Abr. de 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by