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!