Removing Plot Points inside area
10 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
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 件のコメント
その他の回答 (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!