How to customize setting the included angle of the XY axis to 120 degrees?

2 vues (au cours des 30 derniers jours)
Shuwen
Shuwen le 14 Août 2023
Réponse apportée : Ayush le 22 Août 2023
Hi, i am a PHD of chemistry. Considering that I need to build a structural model of the hexagonal crystal system, I need to set the angle between the XY axis to 120 degrees in the 3D drawing, while the Z axis remains perpendicular to the XY plane. What should I do? I would appreciate any advice you can provide!

Réponses (1)

Ayush
Ayush le 22 Août 2023
I understand that you want to set the angle between XY as 120 degree while keeping Z-axis perpendicular to XY plane. This can be achieved by performing coordinate transformation as given bellow:
% Generate a 3D coordinate system
figure;
quiver3(0, 0, 0, 1, 0, 0, 'r', 'LineWidth', 2); % X axis (red)
hold on;
quiver3(0, 0, 0, 0, 1, 0, 'g', 'LineWidth', 2); % Y axis (green)
quiver3(0, 0, 0, 0, 0, 1, 'b', 'LineWidth', 2); % Z axis (blue)
axis equal;
% Apply rotation transformation
angle = 120; % Angle in degrees
rotationMatrix = [cosd(angle) -sind(angle) 0; sind(angle) cosd(angle) 0; 0 0 1];
% Apply the rotation to the coordinate system
newXAxis = rotationMatrix * [1; 0; 0];
newYAxis = rotationMatrix * [0; 1; 0];
newZAxis = rotationMatrix * [0; 0; 1];
% Plot the rotated coordinate system
quiver3(0, 0, 0, newXAxis(1), newXAxis(2), newXAxis(3), 'r--', 'LineWidth', 2); % Rotated X axis (dashed red)
quiver3(0, 0, 0, newYAxis(1), newYAxis(2), newYAxis(3), 'g--', 'LineWidth', 2); % Rotated Y axis (dashed green)
quiver3(0, 0, 0, newZAxis(1), newZAxis(2), newZAxis(3), 'b--', 'LineWidth', 2); % Z axis (blue)
The rotated coordinate system is plotted using dashed lines. You can adjust the angle variable to set the desired angle between XY axis. You may read further on ‘quiver3’ here: https://in.mathworks.com/help/matlab/ref/quiver3.html

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by