Large amount of coordinates transformation in 3D

14 visualizaciones (últimos 30 días)
M Teaxdriv
M Teaxdriv el 13 de Jul. de 2022
Comentada: Paul el 4 de Dic. de 2025 a las 2:07
Hello,
I am trying to perform transformation of large amount of coordinates, but firstly I am doing it on this small example:
I would like to rotate by 10 degrees about y axis x y z coordinates ( size is 8 x 3). How to perform such rotation? I have found rotation matrices but they are 3x3 and if I want to mupliply matrices [3x3] * [8x3] it is not possible.
Therefore I would like to ask you for help.
theta = 10;
A = [0 0 0; 1 1 1; 0 0 1; 1 1 0; 1 0 1; 0 1 0; 0 1 1; 1 0 0];
x = A(:,1); y = A(:,2); z = A(:,3);
RY = [
cosd(theta) 0 sind(theta)
0 1 0;
-sind(theta) 0 cosd(theta)];
ARY = RY*A;
Best regards
Michal

Respuesta aceptada

Chunru
Chunru el 13 de Jul. de 2022
Transpose A:
theta = 10;
A = [0 0 0; 1 1 1; 0 0 1; 1 1 0; 1 0 1; 0 1 0; 0 1 1; 1 0 0]';
x = A(:,1); y = A(:,2); z = A(:,3);
RY = [
cosd(theta) 0 sind(theta)
0 1 0;
-sind(theta) 0 cosd(theta)];
ARY = RY*A
ARY = 3×8
0 1.1585 0.1736 0.9848 1.1585 0 0.1736 0.9848 0 1.0000 0 1.0000 0 1.0000 1.0000 0 0 0.8112 0.9848 -0.1736 0.8112 0 0.9848 -0.1736
A
A = 3×8
0 1 0 1 1 0 0 1 0 1 0 1 0 1 1 0 0 1 1 0 1 0 1 0

Más respuestas (2)

Walter Roberson
Walter Roberson el 13 de Jul. de 2022
theta = 10;
M = makehgtform('yrotate', deg2rad(theta))
M = 4×4
0.9848 0 0.1736 0 0 1.0000 0 0 -0.1736 0 0.9848 0 0 0 0 1.0000
A = [0 0 0; 1 1 1; 0 0 1; 1 1 0; 1 0 1; 0 1 0; 0 1 1; 1 0 0];
x = A(:,1); y = A(:,2); z = A(:,3);
c = zeros(size(x));
xyzc = [x, y, z, c];
newxyz = xyzc * M
ans = 8×4
0 0 0 0 0.8112 1.0000 1.1585 0 -0.1736 0 0.9848 0 0.9848 1.0000 0.1736 0 0.8112 0 1.1585 0 0 1.0000 0 0 -0.1736 1.0000 0.9848 0 0.9848 0 0.1736 0
newx = newxyz(:,1); newy = newxyz(:,2); newz = newxyz(:,3);

Remo Pillat
Remo Pillat el 3 de Dic. de 2025 a las 7:24
The other answers are good. One more possibility is to use the so3 object in MATLAB, which represents a 3D rotation matrix and has a lot of built-in functionality for converting between different rotation representations and for applying rotations to vectors. You also don't have to do any explicit transposes, since the transform function handles that internally.
For your example, the code would be fairly simple:
theta = 10;
A = [0 0 0; 1 1 1; 0 0 1; 1 1 0; 1 0 1; 0 1 0; 0 1 1; 1 0 0];
% Create 3D rotation object with rotation around y axis
RY = so3(deg2rad(theta), "roty")
RY = so3
0.9848 0 0.1736 0 1.0000 0 -0.1736 0 0.9848
% Apply rotation to original matrix of vectors
ARY = transform(RY, A)
ARY = 8×3
0 0 0 1.1585 1.0000 0.8112 0.1736 0 0.9848 0.9848 1.0000 -0.1736 1.1585 0 0.8112 0 1.0000 0 0.1736 1.0000 0.9848 0.9848 0 -0.1736
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
  1 comentario
Paul
Paul el 4 de Dic. de 2025 a las 2:07
Hi Remo,
The linked doc page for so3 is incorrect. Compare the the signs of the (2,3) and (3,2) terms for "rotx" to Rx(phi) in the Description.
phi = 45*pi/180;
so3(phi,"rotx")
ans = so3
1.0000 0 0 0 0.7071 -0.7071 0 0.7071 0.7071
Also, using psi for a rotation around y and theta for a rotation around z as on that doc page is nonstandard, is it not?

Iniciar sesión para comentar.

Categorías

Más información sobre Coordinate Transformations en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by