ball_traj_anim.m 512 B

123456789101112131415161718192021222324
  1. clear all;
  2. v_0 = 50;
  3. theta_0 = 45;
  4. h_0 = 0;
  5. g = 9.8;
  6. x = @(t) cosd(theta_0) .* v_0 .* t;
  7. y = @(t) h_0 + v_0 * sind(theta_0) .* t - (1/2) * g * t .^ 2;
  8. t = linspace(0, 10, 100); % Time vector from 0 to 10 seconds
  9. x_min = min(x(t)); y_min = min(y(t));
  10. x_max = max(x(t)); y_max = max(y(t));
  11. for t_current = t
  12. plot(x(1:t_current), y(1:t_current));
  13. hold on;
  14. plot(x(t_current), y(t_current), 'ro', 'MarkerSize',25);
  15. xlim([x_min x_max]);
  16. ylim([y_min y_max]);
  17. pause(0.05);
  18. hold off;
  19. end