How do I remove the tail on an animation?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Courtney Navarre
el 4 de Nov. de 2021
Comentada: Courtney Navarre
el 4 de Nov. de 2021
I'm working on a project where we need to create an animation using loops. I came up with the idea of doing similar to earth orbiting the sun. So I have two spheres. One larger one that stays put, but rotates about the Z-axis, and then a smaller one that travels around the larger one in a circular path. I'm having an issue with the smaller sphere leaving images as it moves around the circular path. I'd like to get this cleaned up and failed to find something with set that worked for me. This is the last bit I have at the moment and any help would be appreciated.
clc
clear all
close all
r = 2;
[a b c] = sphere;
figure(1)
s1 = surf (a,b,c,'facecolor','yellow');
ax = gca; set(ax,'Color','k');
title('Space... The Final Frontier');
xlabel('x-axis');
ylabel('y-axis');
zlabel('z-axis');
s1.FaceLighting = 'gouraud';
h = light;
h.Color = 'w';
h.Style = 'local';
h.Position = [-5 -5 0];
xlim ([-4 4])
ylim ([-4 4])
zlim ([-3 3])
hold on
theta = 0:10:360;
for i = 1:length(theta)
th = theta(i);
ang = th*pi/180;
x = (a/2) + r*cos(ang);
y = (b/2) + r*sin(ang);
z = c/2;
d = rand(1,37,'single');
e = ones(size(z))*d(i);
s2 = surf(x,y,z,e);
direction1 = [0 0 1];
rotate(s1,direction1,th)
direction2 = [0 0 1];
rotate(s2,direction2,2*th)
drawnow
pause(0.5)
end
hold off
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/789350/image.png)
0 comentarios
Respuesta aceptada
Geoff Hayes
el 4 de Nov. de 2021
@Courtney Navarre - since you have the handle s2 to the surf object that you replace on each iteration of the loop, then jusst delete this object after the timer expires. Something like
for i = 1:length(theta)
th = theta(i);
ang = th*pi/180;
x = (a/2) + r*cos(ang);
y = (b/2) + r*sin(ang);
z = c/2;
d = rand(1,37,'single');
e = ones(size(z))*d(i);
s2 = surf(x,y,z,e);
direction1 = [0 0 1];
rotate(s1,direction1,th)
direction2 = [0 0 1];
rotate(s2,direction2,2*th)
drawnow
pause(0.5)
delete(s2); % <---- delete the object here
end
3 comentarios
Geoff Hayes
el 4 de Nov. de 2021
@Courtney Navarre Are the star positions just random? If so, you could can generate random numbers within a certain range for your x, y, and z axes, then just plot with scatter3.
Más respuestas (0)
Ver también
Categorías
Más información sobre Graphics Performance en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!