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
0 个评论
采纳的回答
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
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!