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

4 次查看(过去 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 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by