Transform coordinates into pixel
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi ..
I am generating an animation of two eliptical trajectories. The animation have 100 timesteps and for each timestep, I point the x, y coordinates for both objects.
I need to save this animation as frames of a movie. So, I need to get this x, y positions and transform it to a 3D array (r,c,t),. In any given time t, I can acess the grid of pixels made of r x c pixels.
Is there any easy way of doint that? Any ideas?
Thanks
Ps: Here is the animation code:
%%
clear; close all
start_angle = -120;
%
%1 turn as the same trajectory% 5 turns diverging
turns_same = 1;
turns_diverge = 5 ;
frames = 100;
t_same = 50;
t = linspace(start_angle,start_angle+(turns_same + turns_diverge )*( start_angle + 360 ), frames) ;
xh(1:t_same) = 20.*cosd( t (1:t_same) ) ; xg = xh ;
yh(1:t_same) = 10.*sind( t (1:t_same) ) ; yg = yh ;
rgx = linspace(20,30,length(t)-t_same) ; rgy = linspace(10,20,length(t)-t_same) ;
xh = [xh 20.*cosd( t(t_same+1:end ))] ; xg = [xg rgx.*cosd(t(t_same+1:end )) ] ;
yh = [yh 10.*sind( t(t_same+1:end) ) ]; yg = [yg rgy.*sind(t(t_same+1:end )) ];
figure;
g = plot(xg(1),yg(1),'g-',xg(1),yg(1),'go', 'MarkerFaceColor', 'g', 'MarkerSize',12) ;
hold on;
h = plot(xh(1),yh(1),'r-',xh(1),yh(1),'ro', 'MarkerFaceColor', 'r', 'MarkerSize', 12) ;
axis([-30 30 -30 30 ]) ;
pause(0.5) ;
for ii=1:numel(xh)
% update plots
set(h(1),'xdata',xh(1: ii),'ydata',yh(1:ii)) ;
set(h(2),'xdata',xh(ii),'ydata',yh(ii)) ;
set(g(1),'xdata',xg(1: ii),'ydata',yg(1:ii)) ;
set(g(2),'xdata',xg(ii),'ydata',yg(ii)) ;
pause(0.1) ; drawnow ; % visibility
end
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Animation dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!