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:
- final point of each trajectory is connected undesirably to the starting point of the next trajectory.
- 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
0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Earth and Planetary Science 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!