有人知道我应该如何使用动画线来立即为我绘制轨道吗? [英] Does anybody know how should I use animatedline in order to draw me an orbit immediately?

查看:29
本文介绍了有人知道我应该如何使用动画线来立即为我绘制轨道吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是主要代码

%%%%%%%%%%%% Valori pentru Rcsc%%%%Pozitiile si vitezele pe cele 3 axy0(1,1)= 743322.3616 ;y0(2,1)= -6346021.219 ;y0(3,1)= -3394131.349 ;y0(4,1)= 5142.38067;y0(5,1)= 4487.44895 ;y0(6,1)= -7264.00872;%%%% 提琴tspan=[0:864];%%%% Masa(kg) si aria suprafetei satelitului (m^2)米 = 217 ;%320;A = 1.2;%8;%%%% Metoda Runge-Kutta de Ordin 4h=1;y = zeros(6, tspan(end)/h);y(:,1) = y0;对于 i=1:(tspan(end)/h)H=sqrt(y(1,i)^2+y(2,i)^2+y(3,i)^2);k_1 = proiectia(tspan(i), y(:,i), H, m, A, y(4:6, i));k1=double(k_1);k_2 = proiectia(tspan(i)+0.5*h, y(:,i)+0.5*h*k_1, H, m, A, y(4:6, i));k2=double(k_2);k_3 = proiectia((tspan(i)+0.5*h), (y(:,i)+0.5*h*k_2), H, m, A, y(4:6, i));k3=double(k_3);k_4 = proiectia((tspan(i)+h),(y(:,i)+k_3*h), H, m, A, y(4:6, i));k4=double(k_4);y(:,i+1) = double(y(:,i) + (1/6)*(k1+2*k2+2*k3+k4)*h);结尾%%% 遥远的卫星Rcsc = ((y(1,:).^2 + y(2,:).^2 + y(3,:).^2).^0.5);n=50;%plot(tspan,Rcsc)%% 带纹理的 3D 地球示例%% 瑞恩·格雷% 2004 年 9 月 8 日% 2006 年 3 月 9 日、2006 年 1 月 31 日、2013 年 10 月 16 日修订%% 选项空间颜色 = 'k';npanels = 180;% 赤道周围的地球面板数量 deg/panel = 360/npanels阿尔法= 1;% 地球透明度级别,1 = 不透明,通过 0 = 不可见GMST0 = [];% 不要设置可旋转地球仪 (ECEF)%GMST0 = 4.89496121282306;% 在 J2000.0 设置一个可旋转的地球仪% 地球纹理图像% imread() 将处理的任何内容,但需要是 2:1 未投影的地球仪% 图片.image_file = 'https://upload.wikimedia.org/wikipedia/commons/thumb/c/cd/Land_ocean_ice_2048.jpg/1024px-Land_ocean_ice_2048.jpg';% 平均球形地球埃拉德 = 6371008.7714;% 赤道半径(米)普拉德 = 6371008.7714;% 极半径(米)爱罗 = 7.2921158553e-5;% 地球自转速率(弧度/秒)%% 创建图图('颜色',space_color);坚持,稍等;轨道=动画线;addpoints(orbit,y(1,:),y(2,:),y(3,:));拉杜% 关闭法线轴set(gca, 'NextPlot','add', 'Visible','off');轴相等;轴自动;% 设置初始视图视图(0,30);轴 vis3d;%% 创建线框地球% 使用椭球函数创建球体点的 3D 网格[x, y, z] = 椭圆体(0, 0, 0, erad, erad, prad, npanels);global = surf(x, y, -z, 'FaceColor', 'none', 'EdgeColor', 0.5*[1 1 1]);%% 地球纹理贴图% 为纹理贴图加载地球图像cdata = imread(image_file);% 将图像设置为颜色数据(cdata)属性,并设置人脸颜色来表示% 一个纹理贴图,Matlab 希望它在 cdata 中.关闭网格边缘.set(globe, 'FaceColor', 'texturemap', 'CData', cdata, 'FaceAlpha', alpha, 'EdgeColor', 'none');

我想要做的是,当我运行脚本时,应该会出现一个带有地球的图形,并且在通过 runge kutta 算法计算位置时,它应该实时上传轨道.但是现在这个图只有在 Rk 算法计算到 tspan 结束后才会出现,并且图中的轨道已经上传,没有中间点.我该怎么办?我在github上看到其他人使用animatedline和drawow.我在考虑

 轨道=动画线;addpoints(orbit,y(1,:),y(2,:),y(3,:));拉杜结尾

但是我应该把这条线确切地放在哪里?如果我把它放在 rk 循环中,它就不起作用,如果我把它放在

% 创建图图('颜色',space_color);%%轨道=动画线;addpoints(orbit,y(1,:),y(2,:),y(3,:));拉杜

它首先显示一个带有轨道的图形而不是中间点,然后显示一个与地球不同的图形,而轨道和地球应该在同一个图形中.

解决方案

您正在使用

This is the main code

%%%%%%%%%%%% Valori pentru Rcsc


%%%%Pozitiile si vitezele pe cele 3 axe

y0(1,1)=   743322.3616  ;                                     
y0(2,1)=   -6346021.219 ;                               
y0(3,1)=     -3394131.349 ;                                   
y0(4,1)=     5142.38067;        
y0(5,1)=   4487.44895   ;                    
y0(6,1)=     -7264.00872;                     
%%%% Timpul

tspan=[0 :864]; 

%%%% Masa(kg) si aria suprafetei satelitului (m^2)

m =    217 ;         %320;
A =   1.2;             %8;

%%%% Metoda Runge-Kutta de ordin 4

h=1;                                                                             
y = zeros(6, tspan(end)/h); 
y(:,1) = y0;

for i=1:(tspan(end)/h)    
    H=sqrt(y(1,i)^2+y(2,i)^2+y(3,i)^2);
    k_1 = proiectia(tspan(i), y(:,i), H, m, A, y(4:6, i));
    k1=double(k_1);
    k_2 = proiectia(tspan(i)+0.5*h, y(:,i)+0.5*h*k_1, H, m, A, y(4:6, i));
    k2=double(k_2);
    k_3 = proiectia((tspan(i)+0.5*h), (y(:,i)+0.5*h*k_2), H, m, A, y(4:6, i));
    k3=double(k_3);
    k_4 = proiectia((tspan(i)+h),(y(:,i)+k_3*h), H, m, A, y(4:6, i));
    k4=double(k_4);

    y(:,i+1) = double(y(:,i) + (1/6)*(k1+2*k2+2*k3+k4)*h);  

end


%%% Distanta satelitului
Rcsc = ((y(1,:).^2 + y(2,:).^2 + y(3,:).^2).^0.5);
n=50;
%plot(tspan,Rcsc)
 %% Textured 3D Earth example
%
% Ryan Gray
% 8 Sep 2004
% Revised 9 March 2006, 31 Jan 2006, 16 Oct 2013

%% Options

space_color = 'k';
npanels = 180;   % Number of globe panels around the equator deg/panel = 360/npanels
alpha   = 1; % globe transparency level, 1 = opaque, through 0 = invisible
GMST0 = []; % Don't set up rotatable globe (ECEF)
%GMST0 = 4.89496121282306; % Set up a rotatable globe at J2000.0

% Earth texture image
% Anything imread() will handle, but needs to be a 2:1 unprojected globe
% image.

image_file = 'https://upload.wikimedia.org/wikipedia/commons/thumb/c/cd/Land_ocean_ice_2048.jpg/1024px-Land_ocean_ice_2048.jpg';

% Mean spherical earth

erad    = 6371008.7714; % equatorial radius (meters)
prad    = 6371008.7714; % polar radius (meters)
erot    = 7.2921158553e-5; % earth rotation rate (radians/sec)

%% Create figure

figure('Color', space_color);


hold on;
 orbit=animatedline;
addpoints(orbit,y(1,:),y(2,:),y(3,:));
drawnow

% Turn off the normal axes

set(gca, 'NextPlot','add', 'Visible','off');

axis equal;
axis auto;

% Set initial view

view(0,30);

axis vis3d;

%% Create wireframe globe

% Create a 3D meshgrid of the sphere points using the ellipsoid function

[x, y, z] = ellipsoid(0, 0, 0, erad, erad, prad, npanels);

globe = surf(x, y, -z, 'FaceColor', 'none', 'EdgeColor', 0.5*[1 1 1]);



%% Texturemap the globe

% Load Earth image for texture map

cdata = imread(image_file);

% Set image as color data (cdata) property, and set face color to indicate
% a texturemap, which Matlab expects to be in cdata. Turn off the mesh edges.

set(globe, 'FaceColor', 'texturemap', 'CData', cdata, 'FaceAlpha', alpha, 'EdgeColor', 'none');

What I wanna do is that when I run the script a figure with the Earth should appear, and while the positions are being caluclated by the runge kutta algorithm it should upload the orbit in real time. But now the figure appears only after the Rk algorithm is being calculated till the end of tspan and the orbit from the figure is already uploaded without intermediate points. What should I do? I've seen on github that others use animatedline and drawnow. I was thinking about

 orbit=animatedline;

    addpoints(orbit,y(1,:),y(2,:),y(3,:));
    drawnow
    end

But where should I put this line exactly? if I put it in the rk loop it doesn't work and if I put it

% Create figure
figure('Color', space_color);
%%
orbit=animatedline;
addpoints(orbit,y(1,:),y(2,:),y(3,:));
drawnow

it first displays a figure with the orbit but not by intermediate points and then a different figure with the Earth ,while the orbit and the Earth should be in the same figure.

解决方案

You are using animatedline in a wrong way.

The line:

orbit = animatedline;

should be placed before the loop that calculates the points, and the lines:

addpoints(orbit,y(1,i),y(2,i),y(3,i));
drawnow

should be placed within it, to add one (or several) points to the line on each iteration. But, a better approach, would be to first calculate all the orbit and then use a loop for the animation. This way you have more control over the rate of the animation. Here is a small example using your case:

orbit = animatedline;
for k = 1:size(y,2)
    addpoints(orbit,y(1,k),y(2,k),y(3,k));
    drawnow
end

Alternative option

Don't use animated line just keep updating the data in the plot. Here is a simple workout for this:

% create a sphere with earth map on it:
set(gcf,'Color','k')
earth = imread('earth.jpg');
[X,Y,Z] = sphere(50); 
warp(-X,Y,-Z,earth)
axis off
view(-46,17)

% set an animation of a simple orbit:
Nframes = 100; % number of steps in the orbit
% calculation of the orbit:
orb = linspace(-pi,pi,Nframes); 
x = cos(orb).*1.5;
y = sin(orb);
hold on
% plot the whole orbit invisible, just for setting the axes limits:
tmp = plot(x,y,'Color','none');
p = plot(x(1),y(1),'LineWidth',3,'Color','m'); % plot the first step
hold off
for k = 1:numel(orb)
    p.XData = x(1:k); % update the data of the plot
    p.YData = y(1:k);
    pause(0.05) % delay
end

The result:

这篇关于有人知道我应该如何使用动画线来立即为我绘制轨道吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆