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일

0 개 추천

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개)

카테고리

도움말 센터File Exchange에서 Polar Plots에 대해 자세히 알아보기

제품

릴리스

R2020b

태그

질문:

2021년 3월 11일

댓글:

2021년 3월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by