SHARE
TWEET

Untitled

a guest Jan 14th, 2020 118 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top