# Why the coordinate doesn't make sense after rotation matrix (rotx)?

조회 수: 4(최근 30일)
Jiali 17 Jun 2020
Hello,
I got confused about the rotation matrix results. I want to rotate the structure around the z-axis with theta first, and then rotate around x-axis for phi.
theta=60;
phi=30;
R=rotx(phi)*rotz(theta);
R*[1; 0; 0];
% use rotation matrix to transform coordinate
% [X,Y,Z] is original coordinate
[X,Y,Z]=ndgrid(xa,ya,za);
[ie,je,ke]=size(X);
a=[X(:),Y(:),Z(:)];
% new coordinate
anew=R*(a.');
The result is [0.5; 0.75;0.433] for the vector of x-axis. But in my opinion, the new x-axis should be [0.5;-0.866;0]. I am not sure whether my understanding is wrong. Whether I can use rotation matrix to get the correct coordinate? #### 댓글 수: 1

Ameer Hamza 17 Jun 2020
Which rotx() function are you using? One from MATLAB's phsased Phased Array System Toolbox or some other source?

### 채택된 답변

David Goodmanson 18 Jun 2020
Hi Jiali,
from your results it looks like you are using the usual form of the rotation matrices,
function M = Rx(theta)
% angle is in DEGREES
c = cosd(theta); s = sind(theta);
M = [1 0 0
0 c -s
0 s c]
end
function M = Ry(theta)
% angle is in DEGREES
c = cosd(theta); s = sind(theta);
M = [ c 0 s
0 1 0
-s 0 c]
end
function M = Rz(theta)
% angle is in DEGREES
c = cosd(theta); s = sind(theta);
M = [c -s 0
s c 0
0 0 1]
end
which produce counterclockwise rotation of an object when looking down at the appropriate rotation axis coming up out of the page.
By 'rotating the structure' it sounds like you meant rotating the object, leaving the axes in place. In that case
Rx(30)*Rz(60)*[1;0 0]
ans =
0.5000
0.7500
0.4330
is correct. On the other hand, if you wish to rotate the coordinate axes and leave the object in place, then for the same physical rotation you change the signs of rotation and reverse the order of matrix mutiplication:
Rz(-60)*Rx(-30)*[1;0 0]
ans =
0.5000
-0.8660
0