I want to plot3 x y z axis and how it moves as rotation matrix.

18 次查看(过去 30 天)
hi, i want to plot x y z axis at zero position [0 0 0] .
and plot how it changes as rotation matrix for example like [cos(theta) -sin(theta) 0; sin(theta) cos(theta) 0; 0 0 1]
but i when i rotate the dot [0 0 0], the x y z axis does not moves together.
please help me!!
  1 个评论
Angelo Yeo
Angelo Yeo 2023-8-11
안녕하세요. 문의하신 내용을 정확하게 파악하지 못하였습니다. 한국어로 작성하시는게 편하시다면 댓글에 한국어로 문의사항을 좀 더 자세하게 작성해 보시겠어요? 다른 한국 사람들이 보고 더 적절한 도움을 드릴 수도 있습니다.

请先登录,再进行评论。

采纳的回答

Ruchika
Ruchika 2023-8-11
Hi, to plot the x, y, and z axes at the zero position [0 0 0] and visualize their changes using a rotation matrix, you can follow these steps in MATLAB:
1. Define the initial axes.
2. Define the rotation matrix.
3. Apply the rotation to axes.
4. Plot the initial axes.
5. Plot the rotated axes.
6. Set plot properties.
Here's the code to plot the x, y, and z axes at the zero position [0 0 0] and visualize their changes using a rotation matrix:
% Define the initial axes
x_axis = [0 1 0];
y_axis = [0 0 1];
z_axis = [1 0 0];
% Define the rotation matrix
theta = pi/4; % Angle of rotation (45 degrees)
rotation_matrix = [cos(theta) -sin(theta) 0; sin(theta) cos(theta) 0; 0 0 1];
% Apply the rotation to axes
rotated_x_axis = x_axis * rotation_matrix;
rotated_y_axis = y_axis * rotation_matrix;
rotated_z_axis = z_axis * rotation_matrix;
% Plotting
plot3([0 x_axis(1)], [0 x_axis(2)], [0 x_axis(3)], 'r', 'LineWidth', 2);
hold on;
plot3([0 y_axis(1)], [0 y_axis(2)], [0 y_axis(3)], 'g', 'LineWidth', 2);
plot3([0 z_axis(1)], [0 z_axis(2)], [0 z_axis(3)], 'b', 'LineWidth', 2);
plot3([0 rotated_x_axis(1)], [0 rotated_x_axis(2)], [0 rotated_x_axis(3)], 'r--', 'LineWidth', 2);
plot3([0 rotated_y_axis(1)], [0 rotated_y_axis(2)], [0 rotated_y_axis(3)], 'g--', 'LineWidth', 2);
plot3([0 rotated_z_axis(1)], [0 rotated_z_axis(2)], [0 rotated_z_axis(3)], 'b--', 'LineWidth', 2);
% Set plot properties
axis equal;
xlabel('X');
ylabel('Y');
zlabel('Z');
legend('X-axis', 'Y-axis', 'Z-axis', 'Rotated X-axis', 'Rotated Y-axis', 'Rotated Z-axis');
To learn more about 3-D point or line plot, please check out the MathWorks documentation links below:

更多回答(1 个)

George Abrahams
George Abrahams 2023-12-14
Hi 동후, you can plot the axes (basis vectors) of the rotation matrix with my plotframe function on File Exchange. When you change the rotation matrix, you can update its position with the UpdateFrame name-value argument, so that it animates. For example:
f = figure;
ax = axes( f, 'DataAspectRatio', [1 1 1], 'View', [37.5 30], ...
'XLim', [-.5 1.1], 'YLim', [-.5 1.1], 'ZLim', [-.5 1.1], ...
'XGrid', 'on', 'YGrid', 'on', 'ZGrid', 'on' );
% Initialise the plot before beginning the animation.
hg = plotframe( Parent=ax );
rotation = 0;
while isgraphics( f )
% Calculate the new rotation matrix.
transformationMatrix = makehgtform( 'axisrotate',[1 1 1], rotation );
rotationMatrix = transformationMatrix(1:3,1:3);
% Update the plot.
plotframe( rotationMatrix, UpdateFrame=hg )
% drawnow is required to force MATLAB to render the updated figure on each loop.
drawnow
rotation = rem( rotation + 0.04, 2 * pi );
end

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by