Removing Plot Points inside area

11 vues (au cours des 30 derniers jours)
Jordan Coombs
Jordan Coombs le 11 Mar 2021
Commenté : Star Strider le 11 Mar 2021
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

Réponse acceptée

Star Strider
Star Strider le 11 Mar 2021
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 commentaires
Jordan Coombs
Jordan Coombs le 11 Mar 2021
Thank you that helped a lot, a lot more simple than i was making it out to be
Star Strider
Star Strider le 11 Mar 2021
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Earth and Planetary Science dans Help Center et File Exchange

Tags

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by