Filter löschen
Filter löschen

Transform coordinates into pixel

4 Ansichten (letzte 30 Tage)
L
L am 25 Feb. 2024
Bearbeitet: Matt J am 25 Feb. 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

Akzeptierte Antwort

Matt J
Matt J am 25 Feb. 2024
Bearbeitet: Matt J am 25 Feb. 2024

Weitere Antworten (0)

Kategorien

Mehr zu Animation finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by