如何在MATLAB中组合3D冲浪图和Comet3图?

问题描述 投票:0回答:1

我正在编写代码以绘制围绕3d地球模型(使用surf()和set()函数创建)的卫星(使用comet3()函数创建)的圆形轨道。问题是我似乎找不到在同一个情节中将它们组合在一起的方法。我已经尝试过使用hold on and hold off,但这似乎也不起作用。我在下面粘贴MATLAB代码以供参考。

编辑:sv_from_coe(),odeset等所有其他功能均正常运行,我面临的唯一问题是将comet3()和set()的图组合在一起。

G = 6.67E-11;
Me = 5.976E24;

coe = [6776, 0.0005638, 2.0543, 0.9, 5.549, 0];
[r, v] = sv_from_coe(coe);
rv = [r v];

opt = odeset('RelTol', 1e-6, 'AbsTol', 1e-6);
[t,X] = ode45(@rate, [0 2*1.5*3600], rv, opt);

[x,y,z] = sphere;
r_earth = 6378*1000;

figure
hs1 = surf(x*r_earth,y*r_earth,-z*r_earth);
cdata = imread('1024px-Land_ocean_ice_2048.jpg');
alpha = 1;

hold on
axis equal
comet3(X(:,1), X(:,2), X(:,3))
set(hs1, 'FaceColor', 'texturemap', 'CData', cdata, 'FaceAlpha', alpha, 'EdgeColor', 'none')
matlab matlab-figure
1个回答
1
投票

您只需要颠倒顺序,首先绘制地球并设置纹理。然后使用comet3为轨迹设置动画:

% earth
[x,y,z] = sphere;
r_earth = 6378*1000;

% some simple trajectory
phi = 0:0.01:2*pi;
r_orbit = r_earth + 408*1e3; % ISS orbit height
xv = r_orbit * cos(phi);
yv = r_orbit * sin(phi);
zv = zeros(size(yv));

% draw figure
figure(1); clf;
ax = axes;

% first plot the earth and set texture
hs1 = surf(x*r_earth,y*r_earth,-z*r_earth);
alpha = 1;
cdata = imread("Land_ocean_ice_2048.jpg");
set(hs1, 'FaceColor', 'texturemap', 'CData', cdata, 'FaceAlpha', alpha, 'EdgeColor', 'none')
hold on
axis equal

% finally, animate using comet3
comet3(xv,yv,zv)
© www.soinside.com 2019 - 2024. All rights reserved.