How do I rotate the 3D plot around one of the axis
11 ビュー (過去 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 件のコメント
Rik
2017 年 3 月 12 日
I think the easiest way is to write your figure for each angle to an animated GIF.
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 で Colormaps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!