Defining a 3d XYZ vector aligned with Z axis and then rotating it along the XY plane by pi/4

조회 수: 3 (최근 30일)
x= zeros(1,101);
y= zeros(1,101);
z= 0:0.01:1;
figure(1)
plot3(x,y,z,'LineWidth',2, 'Color',[1 0 0])
grid on
axis square
rot = xrot(pi/4);
xr = rot(1,:);
yr = rot(2,:);
zr = rot(3,:);
xr = x.*xr';
yr = y.*yr';
zr = z.*zr';
figure(2)
plot3(xr,yr,zr,'LineWidth',2, 'Color',[1 0 0])
grid on
axis square
function Rx=xrot(phi)
Rx = [1 0 0; 0 cos(phi) -sin(phi);0 sin(phi) cos(phi)];
This is the code I have currently. I have not used plot3 or rotated graphs before. I was wondering if this is even the correct way to define a vector along the z axis in the first place and if so how do I rotate the vector if rotates at all.
  댓글 수: 1
Rajeev
Rajeev 2023년 1월 25일
By rotating the vector along the x-y plane, you mean the final position of the rotated vector would have an angle of with its projection on the x-y plane?

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

답변 (1개)

Nehemiae
Nehemiae 2023년 3월 10일
Hello,
The coordinates defined indeed are aligned with the z-axis. To rotate a matrix by some degree, the “rotx”, “roty” and “rotz” functions can be used to rotate a 3D matrix. These functions return a rotation matrix which need to be multiplied by matrix multiplication - i.e. * (not element-wise multiplication .*) - with the coordinate matrix.
rot = rotx(90); % Give angle in degrees
rotMat = rot * [x; y; z];
rot = rotz(45); % Give angle in degrees
rotMat = rot * rotMat;
plot3(rotMat(1, :), rotMat(2, :), rotMat(3, :),'LineWidth', 2, 'Color', [1 0 0])
The documentation on the “rotz” function (https://www.mathworks.com/help/releases/R2021b/phased/ref/rotz.html?s_tid=doc_ta) is helpful in this regard.

카테고리

Help CenterFile Exchange에서 Pulse and Transition Metrics에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by