![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/253653/image.png)
How do I shade the xy plane at z=0 of my plot and how to stop the plot after it passes z=0?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Noah Wilson
am 9 Dez. 2019
Bearbeitet: Adam Danz
am 9 Dez. 2019
I have the following code:
t = 0:0.0001:20; %time
m = 0.4; %mass (kg)
g = 9.8; %gravitational accel. (m/s^2)
b = 0.44; %drag coefficient
w_1 = 10; %Angular Velocity
w_2 = 8; %Angular Velocity
w_3 = 5; %Angular Velocity
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);
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);
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);
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)
xlabel('X')
ylabel('Y')
zlabel('Z')
legend('\omega = 10 rad/s', '\omega = 8 rad/s', '\omega = 5 rad/s')
hold off
I would like to shade the xy plane at z=0 to make the plot more visually appealing but I am not sure how to do this. I also only need the portion of each individual plot that appears before it goes below z=0 again. This plot is the trajectory of a soccer ball and at z=0 is the ground so mathematically the plots continue below z=0 but realistically this is not the case and I am not sure how to set this limit. Thank you in advanced for your help!
0 Kommentare
Akzeptierte Antwort
Adam Danz
am 9 Dez. 2019
Bearbeitet: Adam Danz
am 9 Dez. 2019
The easiest solution is simply
zlim([0,inf])
I also added grid on so we can see the 3D coordinates better. However, the data below z=0 still exist; you just can't see it.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/253653/image.png)
Another approach would be to simply replace unwanted data with NaN.
idx = z_t_1 > 0;
x_t_1(~idx) = NaN;
x_t_1(~idx) = NaN;
z_t_1(~idx) = NaN;
plot3(x_t_1, y_t_1, z_t_1)
And another approach is to split the data up into groups that 'bounce' above the z=0 axis. There's more than one way to do that. This appoach requires the image processing toolbox due to the use of bwlabel().
bwidx = bwlabel(z_t_1 > 0); % group the sections above z=0
splitGroups = @(data)splitapply(@(x){x},data(bwidx>0).',findgroups(bwidx(bwidx>0)).'); % Function that splits the data
axes();
hold on
cellfun(@plot3, splitGroups(x_t_1), splitGroups(y_t_1), splitGroups(z_t_1))
view(3)
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!