how to animate two plots at the same time?

5 vues (au cours des 30 derniers jours)
Matthew Lee
Matthew Lee le 2 Mar 2021
Commenté : Matthew Lee le 2 Mar 2021
Hi everyone!
recently I've been making an orbit propagator where I plot an orbit around the Earth by plotting 2-body problem using ode45 and animate the orbit around the Earth.. but what happens is the rotation of Earth will be animated first and then the animation of the orbit begins after the Earth stops... is there any way I can make both happen at the same time?
the code:
Map = imread('earthmap.jpg');
Re = 6378; %km
[X, Y, Z]= sphere
Earth = surf(Re*X, Re*Y, -Re*Z)
set(Earth,'FaceColor','texturemap','Cdata',Map,'EdgeColor','none')
set(gcf,'Color','k')
set (gca,'Color','k')
axis equal
rotE = 360/24; %deg per hour
%Earth rotating around Z axis.
Ndays = Period/86400; %number of hours
tr = Ndays*24; %one day
for ir = 1:1:tr+1 %since time starts from 1 not 0
rotate(Earth,[0 0 1],rotE);
Anim = getframe(gca);
end
hold on
comet3(xv,yv,zv) %xv yv zv are the values I get from solving the 2-body problem which I didn't include here

Réponse acceptée

KSSV
KSSV le 2 Mar 2021
Put this line:
comet3(xv,yv,zv) %xv yv zv are the values I get from solving the 2-body problem which I didn't include here
into a loop as shown below:
n = length(xv) ;
for i = 1:n
plot3(xv(1:i),yv(1:i),zv(1:i)) ;
drawnow
end
If you are looking to inclide comet along with another animation.
  4 commentaires
Matthew Lee
Matthew Lee le 2 Mar 2021
Update: I tried to put both in the same loop by manipulating the variables such that the earth completes it's real time rotation... but another problem occurd is in one loop, Earth doesn't rotate around its axis in a fixed frame, while rotating itself the Earth will translate as the loop go on...... how to fix the rotation of Earth in this case?
%Earth rotation
lenx = length(xv)
revspeed = 360/86400; %rev per sec
EarthPhase = Period*revspeed; %phase of Earth in deg as the final time, Period is the timespan
tr=EarthPhase/lenx; %the rotational speed in terms of lenx
%oh=findobj(gca,'type','surface');
O = findobj('Type','surface')
for i = 1:1:lenx
rotate(O,[0 0 1],tr);
Anim = getframe(gca);
hold on
plot3(xv(1:i),yv(1:i),zv(1:i))
drawnow
hold off
end
Matthew Lee
Matthew Lee le 2 Mar 2021
I finally solved this by adding origin and now it works perfectly but a bit slow!
rotate(O,[0 0 1],tr,[0 0 0]);

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Animation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by