How do I remove the tail on an animation?

조회 수: 3 (최근 30일)
Courtney Navarre
Courtney Navarre 2021년 11월 4일
댓글: Courtney Navarre 2021년 11월 4일
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