How do I remove the tail on an animation?

3 次查看(过去 30 天)
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

采纳的回答

Geoff Hayes
Geoff Hayes 2021-11-4
@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 个评论
Geoff Hayes
Geoff Hayes 2021-11-4
@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.
Courtney Navarre
Courtney Navarre 2021-11-4
@Geoff Hayes Yes. Just random fixed positions during the run. Thanks again for the help.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by