How do I rotate the 3D plot around one of the axis
조회 수: 17 (최근 30일)
이전 댓글 표시
Need Help Rotating 3D plot I was wondering if you guys can give me some guidances on how to create a plot rotation. I need to create a video of the plot rotate around any of the axis. The rotating command need to be within the code. So when I run the function it would create a plot then start to rotate without any other input from me.
Thanks Guys.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function spheremap
close all
clear all
r=1;
x1=zeros(81,81);
x2=zeros(81,81);
x3=zeros(81,81);
c=zeros(81,81);
x1new=zeros(81,81);
x2new=zeros(81,81);
x3new=zeros(81,81);
for i=1:1:81
theta=(i-1)*2*pi/80;
for j=1:1:81
phi=(j-1)*pi/80;
x1(i,j)=r*cos(theta)*sin(phi);
x2(i,j)=r*sin(theta)*sin(phi);
x3(i,j)=r*cos(phi);
hold on
end
end
surf(x1,x2,x3,'EdgeColor','c')
colormap winter
view (3)
% A = [2 2 2; 2 2 2;2 2 2]
A = [2 2 2; 2 2 2;2 2 1]
% A = [2.7 2 2; 2 2.7 2;2 2 1]
% A = [2.7 2 2; 2 2.7 .2;.2 .2 1]
lambda=eig(A)
[V,D]=eig(A)
for i=1:1:81
theta=(i-1)*2*pi/80;
for j=1:1:81
phi=(j-1)*pi/80;
x1=r*cos(theta)*sin(phi);
x2=r*sin(theta)*sin(phi);
x3=r*cos(phi);
B=[x1;x2;x3];
X=A*B;
x1new(i,j)=X(1);
x2new(i,j)=X(2);
x3new(i,j)=X(3);
hold on
end
end
surf(x1new,x2new,x3new,'EdgeColor','none')
camlight('headlight')
axis equal
grid on
grid minor
title('Stretch Transform')
set(gca,'fontsize',12)
xlabel('x')
ylabel('y')
zlabel('z')
axis([-4 4 -4 4 -4 4])
hold off;
end
댓글 수: 2
Jan
2017년 3월 12일
편집: Jan
2017년 3월 12일
Start with omitting the useless "close all; clear all". Especially the last is a waste of time only. Please read an apply https://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup#answer_18099.
Do you want to rotate the axes or the objects only?
답변 (1개)
Jan
2017년 3월 12일
Perhaps you want something like this at the end of your code:
for AZ = 0:5:360
view(AZ, 30);
pause(0.1);
end
for EL = -90:2:90
view(45, EL);
pause(0.1);
end
The detail "around any of the axis" is not clear.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!