Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //include math.h to get the sqrt command
- #include <math.h>
- ...
- //ax and ay should be stored from the previous loop.
- vx+=ax*dt/2.0;
- vy+=ay*dt/2.0;
- //Calculate the vector acceleration. First find 1/distance cubed
- double dist=sqrt(x*x+y*y);
- dist=1.0/(dist*dist*dist);
- ax=-x*mg*dist;
- ay=-y*mg*dist;
- //Do another half timestep like in leapint.c
- vx+=ax*dt/2.0;
- vy+=ay*dt/2.0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement