How can I give a rotational velocity to spheres?
조회 수: 4 (최근 30일)
이전 댓글 표시
t = linspace(0,6,250);
x1 = 0;
x2=2.01;
y = 0;
z = 0.234778*t;
figh = figure;
for k=1:length(t)
clf
t_k = t(k);
z_k = z(k);
[X,Y,Z] = sphere;
X2 = X ;
Y2 = Y ;
Z2 = Z ;
s=surf(X2,Y2,Z2+z_k);
hold on
[X,Y,Z] = sphere;
X2 = X;
Y2 = Y;
Z2 = Z;
sg=surf(X2+2.01,Y2,Z2+z_k);
grid on
xlabel('x')
ylabel('y')
zlabel('z')
xlim([-2.7 3.2])
ylim([-2.8 2.5])
zlim([0 3.9])
title(['t = ',num2str(t_k)])
view([30 35])
movieVector(k) = getframe;
end
so, this is my code for two sphere located in xy plane translating in z direction, now i want the spheres to rotate about y axis with some constant speed, how can I do that? what lines of code I should add?
채택된 답변
Matt J
2021년 5월 8일
편집: Matt J
2021년 5월 8일
figh = figure;
%%Axes
ax = axes('XLim',[-4 4],'YLim',[-4 4],'ZLim',[-4 4]);
view(3)
grid on
xlabel('x')
ylabel('y')
zlabel('z')
axis vis3d
%Initial Spheres
[X,Y,Z] = sphere;
s(1)=surface(X,Y,Z);
s(2)=surface(X+2.01,Y,Z);
%%Transformers
T1=hgtransform('Parent',ax);
T2=hgtransform('Parent',ax);
s(1).Parent=T1;
s(2).Parent=T2;
%Movie parameters
theta = linspace(0,360,250);
K=numel(theta);
movieVector(K)=struct('cdata',[],'colormap',[]); %pre-allocate
%%Draw
for k=1:K
T1.Matrix=AxelRot( theta(k), [0,1,0]);
T2.Matrix=AxelRot( theta(k), [0,1,0], [2.01,0,0]);
drawnow
movieVector(k) = getframe;
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!