필터 지우기
필터 지우기

How to plot a second coordinate frame using plot3?

조회 수: 26 (최근 30일)
Jimmy Neutron
Jimmy Neutron 2022년 10월 1일
댓글: George Abrahams 2023년 12월 14일
So I am trying to fully understand the intermediate steps of what i did and to do so I would like to plot everything. What I am doing is I have a point rotated by 45 degrees in the z axis of the reference frame, and then rotated by 90 degrees around the new y-axis. The point after the two rotations is at [1; 0;1 ]. I have found what the point looks in the reference frame:
alb = deg2rad(45);
Rz = [ cos(alb) sin(alb) 0;
-sin(alb) cos(alb) 0
0 0 1];
beta = deg2rad(90);
Ry = [ cos(beta) 0 sin(beta);
0 1 0;
-sin(beta) 0 cos(beta)];
p_body = [1 0 1];
p_ref = Rz*Ry*p'
How can I plot the new coordinate axes after the 45 degrees rotation, and then after the 90 degree rotation? How shoudl I use the following?
Around X-axis:
X = x;
Y = y*cos(theta) - z*sin(theta);
Z = y*sin(theta) + z*cos(theta);
Around Y-axis:
X = x*cos(theta) + z*sin(theta);
Y = y;
Z = z*cos(theta) - x*sin(theta);
Around Z-axis:
X = x*cos(theta) - y*sin(theta);
Y = x*sin(theta) + y*cos(theta);
Z = z;

답변 (1개)

Jeffrey Clark
Jeffrey Clark 2022년 10월 2일
편집: Jeffrey Clark 2022년 10월 2일
@Jimmy Neutron, your Z rotation matrix doesn't agree with your Z rotation formula. Either could be correct depending if you want clockwise or counter rotation. I'd go with only matrices in right-hand rule (see wiki page) and skip the fomulas.
To draw the axis after rotation choose points on each of the axis in the original frame, rotate them, plot their lines on a figure using plot3 (or quiver3 if you want arrows) and use the figure's rotation control or using view to view them from some perspective. So:
Rx = @(t) [ 1 0 0 ...
; 0 cos(t) -sin(t) ...
; 0 sin(t) cos(t) ];
Ry = @(t) [ cos(t) 0 sin(t) ...
; 0 1 0 ...
; -sin(t) 0 cos(t) ];
Rz = @(t) [ cos(t) -sin(t) 0 ...
; sin(t) cos(t) 0 ...
; 0 0 1 ];
Xold = [1 0 0]; % point [0 0 0] will not move in these rotations
Yold = [0 1 0]; % but would be needed if you also had translatons
Zold = [0 0 1]; % in your matrices
Rxy = Rx(deg2rad(0));
Ryb = Ry(deg2rad(90));
Rza = Rz(deg2rad(45));
Xnew = Rza*Ryb*Rxy*Xold';
Ynew = Rza*Ryb*Rxy*Yold';
Znew = Rza*Ryb*Rxy*Zold';
tiledlayout(2,1,'TileSpacing','compact','Padding','compact')
nexttile
hold on
displayAxis(Xnew,Ynew,Znew)
xlabel('Xnew')
ylabel('Ynew')
zlabel('Znew')
axis([-1.5 1.5 -1.5 1.5 -1.5 1.5])
axis square
axis equal
view(25,45)
nexttile
hold on
displayAxis(Xnew,Ynew,Znew)
xlabel('Xnew')
ylabel('Ynew')
zlabel('Znew')
axis([-1.5 1.5 -1.5 1.5 -1.5 1.5])
axis square
axis equal
camup(Znew)
campos(2*mean([Xnew';-Ynew';Znew']))
function displayAxis(Xnew,Ynew,Znew)
quiver3(0,0,0,Xnew(1),Xnew(2),Xnew(3))
quiver3(0,0,0,Ynew(1),Ynew(2),Ynew(3))
quiver3(0,0,0,Znew(1),Znew(2),Znew(3))
text(Xnew(1),Xnew(2),Xnew(3),'Xold')
text(Ynew(1),Ynew(2),Ynew(3),'Yold')
text(Znew(1),Znew(2),Znew(3),'Zold')
end
  댓글 수: 1
George Abrahams
George Abrahams 2023년 12월 14일
Just to note, instead of your displayAxis function, you could use my plotframe function on File Exchange, if you want something more powerful. Hope it helps.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by