animate_ball.m 644 B

12345678910111213141516171819
  1. function animate_ball(p)
  2. time = linspace(0, p.t_max, 100);
  3. [x_path, y_path] = projectile_motion(p, time);
  4. for cur_time = 1:length(time)
  5. hold on;
  6. xlim([p.x_min-1 p.x_max+1]);
  7. ylim([p.y_min p.y_max+1]);
  8. plot([0,0], [0, p.height_initial], 'LineWidth',2, 'Color','blue');
  9. plot(p.displacement, p.height_final, 'gs', 'MarkerSize',20);
  10. plot([p.displacement, p.x_max], [p.height_final, p.height_final], 'LineWidth', 2, 'Color', 'green', 'LineStyle', '-');
  11. plot(x_path(1:cur_time), y_path(1:cur_time), 'Color', "red");
  12. pause(0.05);
  13. hold off;
  14. end
  15. end