Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #include <math.h>
  4.  
  5. #define DT 0.001
  6. #define G 9.81
  7. #define VELOCIDAD_INICIAL 20
  8. #define ANGULO_INICIAL 50
  9. #define PI 3.14159265358979
  10.  
  11.  
  12. double computar_velocidad(double vi,double a,double dt){
  13. return vi + a*dt;
  14. }
  15.  
  16. double computar_posicion(double pi,double vi,double dt){
  17. return pi + vi*dt;
  18. }
  19.  
  20. double grados_a_radianes(double g){
  21. return (g/180)*PI;
  22. }
  23.  
  24. void tiro_oblicuo(void){
  25.  
  26. double t=0,vx,vy,px=0,py=0,rad=grados_a_radianes(ANGULO_INICIAL);
  27.  
  28. vx = VELOCIDAD_INICIAL*cos(rad);
  29. vy = VELOCIDAD_INICIAL*sin(rad);
  30.  
  31. while (py >= 0){
  32.  
  33. printf("%f,%f,%f\n",px,py,t);
  34. t+=DT;
  35.  
  36. vy = computar_velocidad(vy,-G,DT);
  37. px = computar_posicion(px,vx,DT);
  38. py = computar_posicion(py,vy,DT);
  39. }
  40. }
  41.  
  42. int main(void){
  43.  
  44. tiro_oblicuo();
  45.  
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement