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

21 views (last 30 days)
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 Comment
Angelo Yeo
Angelo Yeo on 11 Aug 2023
안녕하세요. 문의하신 내용을 정확하게 파악하지 못하였습니다. 한국어로 작성하시는게 편하시다면 댓글에 한국어로 문의사항을 좀 더 자세하게 작성해 보시겠어요? 다른 한국 사람들이 보고 더 적절한 도움을 드릴 수도 있습니다.

Sign in to comment.

Accepted Answer

Ruchika
Ruchika on 11 Aug 2023
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:

More Answers (1)

George Abrahams
George Abrahams on 14 Dec 2023
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

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!