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
Matt J 2021-5-8
编辑:Matt J 2021-5-8
This uses AxelRot from the File Exchange (Download):
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
  5 个评论
Matt J
Matt J 2021-5-8
编辑:Matt J 2021-5-8
Something like this,
z = linspace(0,6,K);
for k=1:K
Mz=makehgtform('translate',[0,0,z(k)]);
T1.Matrix=Mz*AxelRot( theta(k), [0,1,0]);
T2.Matrix=Mz*AxelRot( theta(k), [0,1,0], [2.01,0,0]);
drawnow
movieVector(k) = getframe;
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by