How can I give a rotational velocity to spheres?

4 vues (au cours des 30 derniers jours)
ka
ka le 8 Mai 2021
Commenté : ka le 8 Mai 2021
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?
  1 commentaire
ka
ka le 8 Mai 2021
Modifié(e) : ka le 8 Mai 2021
@Matt JSorry I forgot to write hold on
check now!

Connectez-vous pour commenter.

Réponse acceptée

Matt J
Matt J le 8 Mai 2021
Modifié(e) : Matt J le 8 Mai 2021
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 commentaires
Matt J
Matt J le 8 Mai 2021
Modifié(e) : Matt J le 8 Mai 2021
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
ka
ka le 8 Mai 2021
THANKS @Matt J!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Performance dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by