Advertisement
Guest User

Untitled

a guest
Jan 14th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.39 KB | None | 0 0
  1. //include math.h to get the sqrt command
  2. #include <math.h>
  3.  
  4. ...
  5.  
  6. //ax and ay should be stored from the previous loop.
  7. vx+=ax*dt/2.0;
  8. vy+=ay*dt/2.0;
  9.  
  10. //Calculate the vector acceleration. First find 1/distance cubed
  11. double dist=sqrt(x*x+y*y);
  12. dist=1.0/(dist*dist*dist);
  13. ax=-x*mg*dist;
  14. ay=-y*mg*dist;
  15.  
  16. //Do another half timestep like in leapint.c
  17. vx+=ax*dt/2.0;
  18. vy+=ay*dt/2.0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement