Viewer for orbital_model7, demonstrates animation of orbits USAGE: view1h(1,0,1000) view1h(animate,persistence,npts) Calls Orbital model for 4 different initial velocities and plots the results using ordinary cartesian plots. if animate=1 -- Animates planets if persistence=1 -- Leaves line behind planet motions npts number of data points USES: [time, radius, theta ]=orbital_model5(41800,0,0);
function view1h(animate,persistence,npts) %Viewer for orbital_model7, demonstrates animation of orbits %USAGE: view1h(1,0,1000) % view1h(animate,persistence,npts) %Calls Orbital model for 4 different initial velocities and %plots the results using ordinary cartesian plots. % % if animate=1 -- Animates planets % if persistence=1 -- Leaves line behind planet motions %npts number of data points %USES: [time, radius, theta ]=orbital_model5(41800,0,0); global NPTS NPTS=npts; scale=1E9; close all figure; v1=36000; v2=30000; v3=24000; %v4=40000; [time, x1,y1 ]=orbital_model7(v1,150E9,1.99E30,NPTS); x1=x1/scale; y1=y1/scale; leg1=sprintf('v_0 = %7.1f km/s',v1/1000); %22000 27000, 30000, 33000 38000 (highly eccentric) %40000 more eccentric are all interesting 41800 is almost parabolic %close all %Run simulation for 10 Earth years ... [time, x2,y2 ]=orbital_model7(v2,150E9,1.99E30,NPTS); x2=x2/scale; y2=y2/scale; leg2=sprintf('v_0 = %7.1f km/s',v2/1000); [time, x3,y3 ]=orbital_model7(v3,150E9,1.99E30,NPTS); x3=x3/scale; y3=y3/scale; leg3=sprintf('v_0 = %7.1f km/s',v3/1000); size=2000; mrk1='r.'; mrk2='k.'; mrk3='b.'; plot(0,0,mrk1,0,0,mrk2,0,0,mrk3); legend(leg1,leg2,leg3) ylabel('Distance -- millions of km') axis square xlim([-size/2 size/2]);ylim([-size/2 size/2]); restext=sprintf('\n Number of time-steps/year = %6i',NPTS); solvertext='Using RK4 method'; title(strcat('3 Possible orbits beginning at Earth''s orbit \newline',solvertext,restext)) if animate==0 hold on plot(x1,y1,mrk1,x2,y2,mrk2,x3,y3,mrk3); h=plot(0,0,'m+',0,0,'ro'); set(h,'MarkerSize',18); end if animate==1 h=anim_setup4(size,persistence) %I think need anim_setup4 % keyboard figure(1); len=length(x1); for i=1:len X1=x1(i); Y1=y1(i); X2=x2(i); Y2=y2(i); X3=x3(i); Y3=y3(i); % X4=x4(i); Y4=y4(i); pause(0.031); %This 0.03 second pause gives "30 frames/second". %Can shorten pause to get faster response. set(h(2),'XData',X1,'YData',Y1); set(h(3),'XData',X2,'YData',Y2); set(h(4),'XData',X3,'YData',Y3); % set(h(5),'XData',X4,'YData',Y4); drawnow end end end function plot_handle=anim_setup4(size,persistence) % Sets up a Figure for the any animation for four bodies. % Bodies are the sun and three planets % The figure is square, and size sets the total size % of the figure in arbitrary units. % If persistence=0, every time a new point is added to the % animation, the old one is erased. % If persistence=1, the old points remain (creating a trail of motion). % % USAGE: plot_handle=anim_setup4(size,persistence) % e.g.: h=anim_setup(1E6,0) % h = % 159.0089e+000 % 160.0079e+000 % 161.0079e+000 % 162.0079e+000 %size(h) %ans = 4 1 %Note that each handle points to a different object! %The above would create a window whose width and height was 1,000,000 units %It's up to you whether they represent meters, kilometers or inches. %Whatever numbers are in Xdata and Ydata, if they reach more than 500,000, %would be off the plot. Getting to select size helps put the animation in natural %units. Some animations would make more sense in a field only 1000 units %wide, or 100 units wide. Xdata and Ydata can be decimals, so size could be 1 with no loss of %resolution. %close all; %figure(1); fig_handle=gcf; Pos=[0 50 750 600]; P2=Pos(2); Pos(2)=0; Pos=Pos*1.3; Pos(2)=P2; set(fig_handle,'Position', Pos); %0=far left, 50=bottom, 500=xwidth, 400=yheight set(fig_handle,'Color',[0.25 0.64 0.60],'doublebuffer','off'); % Turquoise if persistence ==0 plot_handle = plot(0,0,'g*',size,size,'ko',size,size,'ko',size,size,'ko'); end if persistence ==1 plot_handle = plot(0,0,'g*',size,size,'r.',size,size,'k.',size,size,'b.'); end xmin=-size/2; xmax=size/10; ymin=-2*xmax; ymax=-xmin-xmax; axis([xmin xmax ymin ymax]) axis square grid off mkrsize0=18; mkrsize1=12; if persistence == 1 set(plot_handle,'EraseMode','none','MarkerSize',mkrsize1); end %Makes small markers if persistence == 0 set(plot_handle,'EraseMode','xor' ,'MarkerSize',mkrsize0,'LineWidth',2); end %Makes big markers figure(1) end