0
votes

I'm writing a code to plot the circular orbit of a satellite (created using comet3() function) around a 3d model of the Earth (created using surf() and set() functions). The problem is that I can't seem to find a way to get them together in the same plot. I have tried using hold on and hold off but that doesn't seem to work either. I'm pasting the MATLAB code below for reference.

Edit: All the other functions like sv_from_coe(), odeset, etc. are working perfectly, the only place I'm facing issue is combining the plots from comet3() and 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')
1
Welcome to SO! Can you add some more detail to your question? What does the figure that you obtain currently look like, and what would you like to see different? - rinkert
@rinkert - I'm currently getting a 3d sphere without the surface image of the earth and after 3 seconds the image of the earth appears. What I want to get is the 3d model of earth, with a satellite orbiting around it in a circular orbit. - SacredMechanic
The sv_from_coe() function here takes in the 'classical orbital elements' and outputs initial conditions s (position vector) and v(velocity vector) of the orbit. But all of that isn't a problem. The only place I'm facing an issue is combining the plots from comet3() and set(). - SacredMechanic

1 Answers

2
votes

You just have to reverse the order, first plot the earth and set the texture. Then use comet3 to animate the trajectory:

% 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)