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.
更多回答(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!