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

12 次查看(过去 30 天)
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.
Thanks for your sincere help in advance
% 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
ME 2019-11-1
编辑:ME 2019-11-1
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 个评论
Sam
Sam 2019-11-1
much appreciated.
now the only problem which remains is the fact that initial points differ though they are not supposed to be different.
will think on it.
Thanks a lot
Sam
Sam 2019-11-1
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))

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Earth and Planetary Science 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by