Removing Plot Points inside area

10 ビュー (過去 30 日間)
Jordan Coombs
Jordan Coombs 2021 年 3 月 11 日
コメント済み: Star Strider 2021 年 3 月 11 日
I am plotting a line graph figure with many different trajectories around moon, obviously the moon is a solid object so the lines cannot go through it however i cant find a way to remove the lines with pass through the area of the moon. I've tried inpolygon but i can't get it to work, either because it's not a polygon or i have coded it wrong. The moon is the dashed line.
theta = linspace(0,2*pi);
xc = r_moon*cos(theta);
yc = r_moon*sin(theta);
figure(); hold on
for i = 1:13
t = t_cell{i};
posvel = posvel_cell{i};
% the command below plots a 2-d plot of the trajectory of the
% probe in Cartesian coordinates x and y after using x2 and y2
% to plot the surface of the planet (assumed spherical)
q=(0:0.01:2)*pi;
x2=massrad(2)*cos(q);
y2=massrad(2)*sin(q);
% [in,on] = inpolygon(xc,yc,x2,y2);
% plot(posvel(:,1),posvel(:,2),x2(in),y2(in),'r+');
% plot(posvel(:,1),posvel(:,2),x2(~in),y2(~in),'bo');
plot(posvel(:,1),posvel(:,2),x2,y2);
top=length(t);
finenergy=0.5*(posvel(top,3).^2+ + posvel(top,4).^2)-...
G*massrad(1)/sqrt(posvel(top,1).^2+posvel(top,2).^2);
accuracy=((finenergy-inenergy)/inenergy);
end
plot(xc,yc,'--');
xlabel('x(m)')
ylabel('y(m)')
title('The Safest Place on the Moon?')
hold off

採用された回答

Star Strider
Star Strider 2021 年 3 月 11 日
There are too many missing values to run your code, so I can’t.
One option is to plot a filled circle after you’ve plotted everything else, for example:
r = 5;
xm = r*cos(theta);
ym = r*sin(theta);
fill(xm, ym, [1 1 1 ]*0.8)
Using:
axis('equal')
after all the plotting would also be advisable.
  2 件のコメント
Jordan Coombs
Jordan Coombs 2021 年 3 月 11 日
Thank you that helped a lot, a lot more simple than i was making it out to be
Star Strider
Star Strider 2021 年 3 月 11 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEarth and Planetary Science についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by