How can I give a rotational velocity to spheres?

4 Ansichten (letzte 30 Tage)
ka
ka am 8 Mai 2021
Kommentiert: ka am 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 Kommentar
ka
ka am 8 Mai 2021
Bearbeitet: ka am 8 Mai 2021
@Matt JSorry I forgot to write hold on
check now!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Matt J
Matt J am 8 Mai 2021
Bearbeitet: Matt J am 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 Kommentare
Matt J
Matt J am 8 Mai 2021
Bearbeitet: Matt J am 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by