# Unwanted line connecting last point of current plot to the starting one of the next plot

17 views (last 30 days)
Sam on 1 Nov 2019
Commented: Sam on 1 Nov 2019
Dear friends
I want to plot trajectories of different orbits in one plot. The starting point (Earth) of each orbit is the same while orbital parameters varry. Using the program below I am almost able to plot trajectories, but there are two main problems:
1. final point of each trajectory is connected undesirably to the starting point of the next trajectory.
2. Initial points which should be located on the same point differ in location.
Any improvement is appreciated.
% input datas (these datas are just for instance)
a = [100e6,120e6,130e6]; %semi major axes of different orbits
e = [0.7,0.8,0.9]; %eccentricity of different orbits
dtheta = [90*pi/180,150*pi/180,180*pi/180]; % difference between true anomalies of radius-vectors at final point
dtheta1 = 20*pi/180; % difference between true anomalies of radius-vectors at initial point
[x,y] = OrbitPlotter(a,e,dtheta,dtheta1);
return
function [x,y] = OrbitPlotter(a,e,dtheta,dtheta1)
ElNum = numel(a);
u = 1;
v = 1;
while v <= ElNum
dt = dtheta1; % I reset delta theta to initial value for each trajectory
while dt <= dtheta(v)
x = a(v)*cos(dt);
y = (a(v)*sqrt(1-e(v)^2))*sin(dt);
w(u) = x;
z(u) = y;
dt = dt + pi/180;
u = u + 1;
end
plot(w,z)
hold on
% [w,z] = sort(w); I tried sorting but didn't help much.
v = v + 1;
end
end

ME on 1 Nov 2019
Edited: ME on 1 Nov 2019
a = [100e6,120e6,130e6]; %semi major axes of different orbits
e = [0.7,0.8,0.9]; %eccentricity of different orbits
dtheta = [90*pi/180,150*pi/180,180*pi/180]; % difference between true anomalies of radius-vectors at final point
dtheta1 = 20*pi/180; % difference between true anomalies of radius-vectors at initial point
figure;
[x,y] = OrbitPlotter(a,e,dtheta,dtheta1);
return
function [x,y] = OrbitPlotter(a,e,dtheta,dtheta1)
u = 1;
v = 1;
for v = 1:numel(a)
dt = dtheta1; % I reset delta theta to initial value for each trajectory
while dt <= dtheta(v)
x = a(v)*cos(dt);
y = (a(v)*sqrt(1-e(v)^2))*sin(dt);
w(u,v) = x;
z(u,v) = y;
dt = dt + pi/180;
u = u + 1;
end
w(w==0)=nan;
v(v==0)=nan;
plot(w(:,v),z(:,v))
hold on
end
end
Here the w(w==0)=nan; and v(v==0)=nan; are to account for the fact that the different orbits produce different length arrays. This prevents the plots going to the origin at the end of the orbit.
##### 2 CommentsShowHide 1 older comment
Sam on 1 Nov 2019
Came up with the following which looks logical to me but doesn't work anyway
plot(w(:,v) - w(1,v) + w(1,1),z(:,v) - z(1,v) + z(1,1))

### Categories

Find more on Gravitation, Cosmology & Astrophysics in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by