How can I give a rotational velocity to spheres?

4 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Matt J
Matt J il 8 Mag 2021
Modificato: Matt J il 8 Mag 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 Commenti
Matt J
Matt J il 8 Mag 2021
Modificato: Matt J il 8 Mag 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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Graphics Performance in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by