How do you rotate an ellispoid?

8 vues (au cours des 30 derniers jours)
Ali Almakhmari le 19 Juil 2022
Modifié(e) : Ali Almakhmari le 19 Juil 2022
So I have an ellispoid plotted in MATLAB. And I want to make an animation of this ellipsoid being rotated around its center with a certain speed. And possibly even save this animation as a gif or something. Is this possible? And how can I do it?
0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

Réponse acceptée

KSSV le 19 Juil 2022
Proceed something like this:
xc=50; %xCenter
yc=50; %yCenter
m = 1000;
theta = linspace(0,2*pi,m)';
x = a * cos(theta);
y = b * sin(theta);
alpha = linspace(0,2*pi) ;
figure(1)
filename = 'test.gif';
for i = 1:100
R = [cos(alpha(i)) -sin(alpha(i)); ...
sin(alpha(i)) cos(alpha(i))];
rCoords = R*[x' ; y'];
xr = rCoords(1,:)';
yr = rCoords(2,:)';
plot(xc+xr,yc+yr,'b');
drawnow
frame = getframe(1);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
if i == 1
imwrite(imind,cm,filename,'gif', 'Loopcount',inf);
else
imwrite(imind,cm,filename,'gif','WriteMode','append');
end
end
1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Ali Almakhmari le 19 Juil 2022
Modifié(e) : Ali Almakhmari le 19 Juil 2022
This is really good! However, this rotates an ellipse and not elliposid (an ellipsoid is an ellipse in 3D). Can you somehow make it work for an ellispoid?
Edit: Nevermind. I easily replaced few lines in the loop with the rotate command and it worked. Thanks!

Connectez-vous pour commenter.

Plus de réponses (1)

Matt J le 19 Juil 2022
Use rotate.
0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

Catégories

En savoir plus sur Animation dans Help Center et File Exchange

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by