我制作了一个脚本,用于绘制火星周围的火卫一,MEX和MAVEN航天器轨道的动画。我想要这个动画的视频。它几乎是完美的,但出于某种原因,创建的视频是Matlab中动画的缩放,我无法弄清楚原因。
这是我的代码(用cspice忽略所有内容,这是一个用于接收空间中对象位置的工具箱):
clear
%Load kernels
cspice_furnsh( 'de421.bsp' )
cspice_furnsh( 'MAR085.BSP' )
cspice_furnsh( 'maven_v03.tf' )
cspice_furnsh( 'MEX_130305_STEP.TSC' )
cspice_furnsh( 'MEX_V11.TF' )
cspice_furnsh( 'MVN_SCLKSCET.00000.tsc' )
cspice_furnsh( 'NAIF0010.TLS' )
cspice_furnsh( 'ORMF_______________00880.BSP' )
cspice_furnsh( 'PCK00010.TPC' )
cspice_furnsh( 'spk_m_141027-151027_110526.bsp')
cspice_furnsh( 'ORMM__150301000000_01138.BSP' )
% Flyby 09 APR 2015
ETbegin = cspice_str2et( '2015-04-09T06:30:00' );
ETend = cspice_str2et( '2015-04-09T14:10:00' );
% Generation of calculation input array
interval_ET=[ETbegin:1:ETend];
% Computation of positions of MAVEN, MEX and Phobos in reference to Mars
position_MAVEN_Mars = cspice_spkpos...
( 'maven', interval_ET, 'J2000', 'none', 'mars' );
position_MEX_Mars = cspice_spkpos...
( 'mex', interval_ET, 'J2000', 'none', 'mars' );
position_Phobos_Mars = cspice_spkpos...
( 'phobos', interval_ET, 'J2000', 'none', 'mars' );
MEX_x = position_MEX_Mars(1,:);
MEX_y = position_MEX_Mars(2,:);
MEX_z = position_MEX_Mars(3,:);
MAVEN_x = position_MAVEN_Mars(1,:);
MAVEN_y = position_MAVEN_Mars(2,:);
MAVEN_z = position_MAVEN_Mars(3,:);
PHOBOS_x = position_Phobos_Mars(1,:);
PHOBOS_y = position_Phobos_Mars(2,:);
PHOBOS_z = position_Phobos_Mars(3,:);
writerObj = VideoWriter('video_flyby.avi');
writerObj.FrameRate = 30;
writerObj.Quality = 100;
open(writerObj);
figure
plot3(0,0,0,'ro-',MEX_x,MEX_y,MEX_z,'b',...
MAVEN_x,MAVEN_y,MAVEN_z,'r',...
PHOBOS_x,PHOBOS_y,PHOBOS_z,'k');
legend('Mars','MEX','MAVEN','Phobos');
xlabel('X-axis (km)');
ylabel('Y-axis (km)');
zlabel('Z-axis (km)');
xlim([-20000 20000]);
view([47.5 32]);
grid on;
hold on;
m1 = plot3(MEX_x(1),MEX_y(1),MEX_z(1),'b*','MarkerSize',10);
m2 = plot3(MAVEN_x(1),MAVEN_y(1),MAVEN_z(1),'r*','MarkerSize',10);
m3 = plot3(PHOBOS_x(1),PHOBOS_y(1),PHOBOS_z(1),'k*','MarkerSize',10);
axis tight
set(gca,'nextplot','replacechildren');
set(gcf,'Renderer','zbuffer');
for n = 1:100:numel(PHOBOS_x)
set(m1, 'XData', MEX_x(n), 'YData', MEX_y(n), 'ZData', MEX_z(n));
set(m2, 'XData', MAVEN_x(n), 'YData', MAVEN_y(n), 'ZData', MAVEN_z(n));
set(m3, 'XData', PHOBOS_x(n), 'YData', PHOBOS_y(n), 'ZData', PHOBOS_z(n));
drawnow;
frame = getframe;
writeVideo(writerObj,frame);
end
close(writerObj);
% Unload kernels
cspice_kclear;
这就是Matlab中的结果。
这就是视频的完整框架。
答案 0 :(得分:2)
如果在没有参数的情况下使用getframe
,则只捕获当前轴。
创建图形的句柄并将其作为getframe
的参数。这样您就可以捕获实际图形的所有内容。
这两条线受影响,只是为了向您展示原则:
fh = figure;
frame = getframe(fh);