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

8 Ansichten (letzte 30 Tage)
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 Kommentar
Rajeev
Rajeev am 25 Jan. 2023
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?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Nehemiae
Nehemiae am 10 Mär. 2023
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.

Kategorien

Mehr zu 3-D Scene Control finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by