Transform coordinates into pixel

1 visualización (últimos 30 días)
L
L el 25 de Feb. de 2024
Editada: Matt J el 25 de Feb. de 2024
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

Respuesta aceptada

Matt J
Matt J el 25 de Feb. de 2024
Editada: Matt J el 25 de Feb. de 2024

Más respuestas (0)

Categorías

Más información sobre Animation en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by