How to plot a "goal" into my plot?

2 vues (au cours des 30 derniers jours)
Noah Wilson
Noah Wilson le 13 Déc 2019
Commenté : Noah Wilson le 14 Déc 2019
This is only to do something cool in the plot but I am plotting the trajectory of a soccer ball and I thought it would be cool to plot a "goal" (a rectangle) into the figure since I have a green surface that looks like a field already.
My code is the following:
%% Constants
t = linspace(0, 10, 1000);
m = 0.4; %mass (kg)
g = 9.8; %gravitational accel. (m/s.^2)
b = 0.44; %drag coefficient
w_1 = 1.5; %Angular Velocity
w_2 = 1; %Angular Velocity
w_3 = 0.5; %Angular Velocity
%% w_1
x_t_1 = (2349.*m)./(100.*b) - (2349.*m.*exp(-(b.*t)./m))./(100.*b);
y_t_1 = (g.*m.*t.*w_1)./(b.^2 + w_1.^2) - (171.*b.^2.*m.*w_1)./(20.*(b.^4 + 2.*b.^2.*w_1.^2 + w_1.^4)) - (171.*m.*w_1.^3)./(20.*(b.^4 + 2.*b.^2.*w_1.^2 + w_1.^4)) - (2.*b.*g.*m.^2.*w_1)./(b.^4 + 2.*b.^2.*w_1.^2 + w_1.^4) + (171.*b.^3.*m.*exp(-(b.*t)./m).*sin((t.*w_1)./m))./(20.*(b.^4 + 2.*b.^2.*w_1.^2 + w_1.^4)) + (171.*m.*w_1.^3.*exp(-(b.*t)./m).*cos((t.*w_1)./m))./(20.*(b.^4 + 2.*b.^2.*w_1.^2 + w_1.^4)) + (171.*b.^2.*m.*w_1.*exp(-(b.*t)./m).*cos((t.*w_1)./m))./(20.*(b.^4 + 2.*b.^2.*w_1.^2 + w_1.^4)) + (171.*b.*m.*w_1.^2.*exp(-(b.*t)./m).*sin((t.*w_1)./m))./(20.*(b.^4 + 2.*b.^2.*w_1.^2 + w_1.^4)) + (b.^2.*g.*m.^2.*exp(-(b.*t)./m).*sin((t.*w_1)./m))./(b.^4 + 2.*b.^2.*w_1.^2 + w_1.^4) - (g.*m.^2.*w_1.^2.*exp(-(b.*t)./m).*sin((t.*w_1)./m))./(b.^4 + 2.*b.^2.*w_1.^2 + w_1.^4) + (2.*b.*g.*m.^2.*w_1.*exp(-(b.*t)./m).*cos((t.*w_1)./m))./(b.^4 + 2.*b.^2.*w_1.^2 + w_1.^4);
z_t_1 = (171.*b.^3.*m)./(20.*(b.^4 + 2.*b.^2.*w_1.^2 + w_1.^4)) + (171.*b.*m.*w_1.^2)./(20.*(b.^4 + 2.*b.^2.*w_1.^2 + w_1.^4)) + (b.^2.*g.*m.^2)./(b.^4 + 2.*b.^2.*w_1.^2 + w_1.^4) - (g.*m.^2.*w_1.^2)./(b.^4 + 2.*b.^2.*w_1.^2 + w_1.^4) - (b.*g.*m.*t)./(b.^2 + w_1.^2) - (171.*b.^3.*m.*exp(-(b.*t)./m).*cos((t.*w_1)./m))./(20.*(b.^4 + 2.*b.^2.*w_1.^2 + w_1.^4)) + (171.*m.*w_1.^3.*exp(-(b.*t)./m).*sin((t.*w_1)./m))./(20.*(b.^4 + 2.*b.^2.*w_1.^2 + w_1.^4)) - (171.*b.*m.*w_1.^2.*exp(-(b.*t)./m).*cos((t.*w_1)./m))./(20.*(b.^4 + 2.*b.^2.*w_1.^2 + w_1.^4)) + (171.*b.^2.*m.*w_1.*exp(-(b.*t)./m).*sin((t.*w_1)./m))./(20.*(b.^4 + 2.*b.^2.*w_1.^2 + w_1.^4)) - (b.^2.*g.*m.^2.*exp(-(b.*t)./m).*cos((t.*w_1)./m))./(b.^4 + 2.*b.^2.*w_1.^2 + w_1.^4) + (g.*m.^2.*w_1.^2.*exp(-(b.*t)./m).*cos((t.*w_1)./m))./(b.^4 + 2.*b.^2.*w_1.^2 + w_1.^4) + (2.*b.*g.*m.^2.*w_1.*exp(-(b.*t)./m).*sin((t.*w_1)./m))./(b.^4 + 2.*b.^2.*w_1.^2 + w_1.^4);
%% w_2
x_t_2 = (2349.*m)./(100.*b) - (2349.*m.*exp(-(b.*t)./m))./(100.*b);
y_t_2 = (g.*m.*t.*w_2)./(b.^2 + w_2.^2) - (171.*b.^2.*m.*w_2)./(20.*(b.^4 + 2.*b.^2.*w_2.^2 + w_2.^4)) - (171.*m.*w_2.^3)./(20.*(b.^4 + 2.*b.^2.*w_2.^2 + w_2.^4)) - (2.*b.*g.*m.^2.*w_2)./(b.^4 + 2.*b.^2.*w_2.^2 + w_2.^4) + (171.*b.^3.*m.*exp(-(b.*t)./m).*sin((t.*w_2)./m))./(20.*(b.^4 + 2.*b.^2.*w_2.^2 + w_2.^4)) + (171.*m.*w_2.^3.*exp(-(b.*t)./m).*cos((t.*w_2)./m))./(20.*(b.^4 + 2.*b.^2.*w_2.^2 + w_2.^4)) + (171.*b.^2.*m.*w_2.*exp(-(b.*t)./m).*cos((t.*w_2)./m))./(20.*(b.^4 + 2.*b.^2.*w_2.^2 + w_2.^4)) + (171.*b.*m.*w_2.^2.*exp(-(b.*t)./m).*sin((t.*w_2)./m))./(20.*(b.^4 + 2.*b.^2.*w_2.^2 + w_2.^4)) + (b.^2.*g.*m.^2.*exp(-(b.*t)./m).*sin((t.*w_2)./m))./(b.^4 + 2.*b.^2.*w_2.^2 + w_2.^4) - (g.*m.^2.*w_2.^2.*exp(-(b.*t)./m).*sin((t.*w_2)./m))./(b.^4 + 2.*b.^2.*w_2.^2 + w_2.^4) + (2.*b.*g.*m.^2.*w_2.*exp(-(b.*t)./m).*cos((t.*w_2)./m))./(b.^4 + 2.*b.^2.*w_2.^2 + w_2.^4);
z_t_2 = (171.*b.^3.*m)./(20.*(b.^4 + 2.*b.^2.*w_2.^2 + w_2.^4)) + (171.*b.*m.*w_2.^2)./(20.*(b.^4 + 2.*b.^2.*w_2.^2 + w_2.^4)) + (b.^2.*g.*m.^2)./(b.^4 + 2.*b.^2.*w_2.^2 + w_2.^4) - (g.*m.^2.*w_2.^2)./(b.^4 + 2.*b.^2.*w_2.^2 + w_2.^4) - (b.*g.*m.*t)./(b.^2 + w_2.^2) - (171.*b.^3.*m.*exp(-(b.*t)./m).*cos((t.*w_2)./m))./(20.*(b.^4 + 2.*b.^2.*w_2.^2 + w_2.^4)) + (171.*m.*w_2.^3.*exp(-(b.*t)./m).*sin((t.*w_2)./m))./(20.*(b.^4 + 2.*b.^2.*w_2.^2 + w_2.^4)) - (171.*b.*m.*w_2.^2.*exp(-(b.*t)./m).*cos((t.*w_2)./m))./(20.*(b.^4 + 2.*b.^2.*w_2.^2 + w_2.^4)) + (171.*b.^2.*m.*w_2.*exp(-(b.*t)./m).*sin((t.*w_2)./m))./(20.*(b.^4 + 2.*b.^2.*w_2.^2 + w_2.^4)) - (b.^2.*g.*m.^2.*exp(-(b.*t)./m).*cos((t.*w_2)./m))./(b.^4 + 2.*b.^2.*w_2.^2 + w_2.^4) + (g.*m.^2.*w_2.^2.*exp(-(b.*t)./m).*cos((t.*w_2)./m))./(b.^4 + 2.*b.^2.*w_2.^2 + w_2.^4) + (2.*b.*g.*m.^2.*w_2.*exp(-(b.*t)./m).*sin((t.*w_2)./m))./(b.^4 + 2.*b.^2.*w_2.^2 + w_2.^4);
%% w_3
x_t_3 = (2349.*m)./(100.*b) - (2349.*m.*exp(-(b.*t)./m))./(100.*b);
y_t_3 = (g.*m.*t.*w_3)./(b.^2 + w_3.^2) - (171.*b.^2.*m.*w_3)./(20.*(b.^4 + 2.*b.^2.*w_3.^2 + w_3.^4)) - (171.*m.*w_3.^3)./(20.*(b.^4 + 2.*b.^2.*w_3.^2 + w_3.^4)) - (2.*b.*g.*m.^2.*w_3)./(b.^4 + 2.*b.^2.*w_3.^2 + w_3.^4) + (171.*b.^3.*m.*exp(-(b.*t)./m).*sin((t.*w_3)./m))./(20.*(b.^4 + 2.*b.^2.*w_3.^2 + w_3.^4)) + (171.*m.*w_3.^3.*exp(-(b.*t)./m).*cos((t.*w_3)./m))./(20.*(b.^4 + 2.*b.^2.*w_3.^2 + w_3.^4)) + (171.*b.^2.*m.*w_3.*exp(-(b.*t)./m).*cos((t.*w_3)./m))./(20.*(b.^4 + 2.*b.^2.*w_3.^2 + w_3.^4)) + (171.*b.*m.*w_3.^2.*exp(-(b.*t)./m).*sin((t.*w_3)./m))./(20.*(b.^4 + 2.*b.^2.*w_3.^2 + w_3.^4)) + (b.^2.*g.*m.^2.*exp(-(b.*t)./m).*sin((t.*w_3)./m))./(b.^4 + 2.*b.^2.*w_3.^2 + w_3.^4) - (g.*m.^2.*w_3.^2.*exp(-(b.*t)./m).*sin((t.*w_3)./m))./(b.^4 + 2.*b.^2.*w_3.^2 + w_3.^4) + (2.*b.*g.*m.^2.*w_3.*exp(-(b.*t)./m).*cos((t.*w_3)./m))./(b.^4 + 2.*b.^2.*w_3.^2 + w_3.^4);
z_t_3 = (171.*b.^3.*m)./(20.*(b.^4 + 2.*b.^2.*w_3.^2 + w_3.^4)) + (171.*b.*m.*w_3.^2)./(20.*(b.^4 + 2.*b.^2.*w_3.^2 + w_3.^4)) + (b.^2.*g.*m.^2)./(b.^4 + 2.*b.^2.*w_3.^2 + w_3.^4) - (g.*m.^2.*w_3.^2)./(b.^4 + 2.*b.^2.*w_3.^2 + w_3.^4) - (b.*g.*m.*t)./(b.^2 + w_3.^2) - (171.*b.^3.*m.*exp(-(b.*t)./m).*cos((t.*w_3)./m))./(20.*(b.^4 + 2.*b.^2.*w_3.^2 + w_3.^4)) + (171.*m.*w_3.^3.*exp(-(b.*t)./m).*sin((t.*w_3)./m))./(20.*(b.^4 + 2.*b.^2.*w_3.^2 + w_3.^4)) - (171.*b.*m.*w_3.^2.*exp(-(b.*t)./m).*cos((t.*w_3)./m))./(20.*(b.^4 + 2.*b.^2.*w_3.^2 + w_3.^4)) + (171.*b.^2.*m.*w_3.*exp(-(b.*t)./m).*sin((t.*w_3)./m))./(20.*(b.^4 + 2.*b.^2.*w_3.^2 + w_3.^4)) - (b.^2.*g.*m.^2.*exp(-(b.*t)./m).*cos((t.*w_3)./m))./(b.^4 + 2.*b.^2.*w_3.^2 + w_3.^4) + (g.*m.^2.*w_3.^2.*exp(-(b.*t)./m).*cos((t.*w_3)./m))./(b.^4 + 2.*b.^2.*w_3.^2 + w_3.^4) + (2.*b.*g.*m.^2.*w_3.*exp(-(b.*t)./m).*sin((t.*w_3)./m))./(b.^4 + 2.*b.^2.*w_3.^2 + w_3.^4);
%% Drag Only
xt = (23.49.*m./b) - (23.49.*m.*exp(-b.*t./m)./b);
yt = 0.*t;
zt = (m.*(171.*b + 20.*g.*m)./(20.*b.^2)) - (m.*(g.*t + (exp(-b.*t./m).*(171.*b + 20.*g.*m)./(20.*b)))./b);
%% Plot
figure(1)
plot3(x_t_1, y_t_1, z_t_1)
hold on
plot3(x_t_2, y_t_2, z_t_2)
plot3(x_t_3, y_t_3, z_t_3)
plot3(xt, yt, zt)
xlabel('X (m)')
ylabel('Y (m)')
zlabel('Z (m)')
% xlim([0 15])
ylim([-5 5])
zlim([0 inf])
hs = surf(xlim, ylim, zeros(2));
hs.FaceColor = [0.3 0.5 0.1];
grid on
legend('\omega = 1.5 rad/s', '\omega = 1.0 rad/s', '\omega = 0.5 rad/s', 'Drag Only')
hold off
I'm not sure if a piecewise plot might be the way to go to get a rectangle at z=0, y=[-2 2], x=20 ?
Thanks for the help in advanced!

Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 13 Déc 2019
help rectangle
  1 commentaire
Noah Wilson
Noah Wilson le 14 Déc 2019
From what I read that is for a 2D plot. I'm hoping to put it in my 3D plot. Thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by