Matrix multiplication between an operation matrix, such as the rotation matrix, and a coordinate list.
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi
I would like to apply a 3D rotation operation, by matrix multiplication, on each of a element (rows) of coordinate list represented by a N x 3 vector.
For now I use a for-loop over all coordinates, see below, but I would prefer to do this in one operation.
BR
Thomas
y_rotation_matrix=@(theta) [cos(-theta) 0 sin(-theta);0 1 0;-sin(-theta) 0 cos(-theta)];
coordinate_list=rand(10,3)
hold on
xlabel('x')
ylabel('y')
zlabel('z')
plot3(coordinate_list(:,1),coordinate_list(:,2),coordinate_list(:,3));
rotated_coordinate_list=nan(size(coordinate_list));
theta0=.3
for q=1:size(coordinate_list,1)
rotated_coordinate_list(q,:)=y_rotation_matrix(theta0)*coordinate_list(q,:)';
end
plot3(rotated_coordinate_list(:,1),rotated_coordinate_list(:,2),rotated_coordinate_list(:,3));
0 comentarios
Respuesta aceptada
Paul
el 12 de Feb. de 2025
y_rotation_matrix=@(theta) [cos(-theta) 0 sin(-theta);0 1 0;-sin(-theta) 0 cos(-theta)];
rng(100)
coordinate_list=rand(10,3);
rotated_coordinate_list=nan(size(coordinate_list));
theta0 = .3;
for q=1:size(coordinate_list,1)
rotated_coordinate_list(q,:)=y_rotation_matrix(theta0)*coordinate_list(q,:)';
end
Here is one option
r1 = (y_rotation_matrix(theta0)*coordinate_list.').';
Suprised that it's not exactly the same as result from the loop. Maybe some operations are done in a different order when multiplying two matrices like that?
r1 - rotated_coordinate_list
Here's another option.
r2 = coordinate_list*y_rotation_matrix(theta0).';
Also slightly different than original result
r2 - rotated_coordinate_list
But am slightly surprised that it's identical to the first method
r2 - r1
1 comentario
Matt J
el 13 de Feb. de 2025
Editada: Matt J
el 13 de Feb. de 2025
Suprised that it's not exactly the same as result from the loop. Maybe some operations are done in a different order when multiplying two matrices like that?
The way matrix operations are multithreaded depends on the size of the operands.
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!