![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1462092/image.png)
How to customize setting the included angle of the XY axis to 120 degrees?
조회 수: 3 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
답변 (1개)
Ayush
2023년 8월 22일
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1462092/image.png)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!