As part of a vector class/ "physics engine" I am making, I am trying to implement a velocity verlet algorithm to solve Newton's equations of motion. However, the algorithm that I have implemented is producing massive values, as you can see below. i have tried what I believe to be every option on my own, and was wondering if someone could help. Thanks.
Xpos = 0 OldPos = 1 dt = 0.02 Xaccel = 9.81 def doVerletX(currentPos, oldPos, accel, dt): newPos = (currentPos + (currentPos-oldPos) + (accel*dt*dt)) return newPos for a in range (1,10,1): newPos = doVerletX(Xpos,OldPos,dt,Xaccel) print(newPos) OldPos = Xpos dt+=dt The output to the above code was:
0.9247220000000003 3.8494440000000005 7.698888000000001 15.397776000000002 30.795552000000004 61.59110400000001 123.18220800000002 246.36441600000003 492.72883200000007 I know that this is obviously wrong and was wondering what to do to fix it?
dtis delta t? why are you doingdt+=dt? Also I think your parameter are in wrong order when calling the funciton. In function definitiondtis 4th argument, during call you are passingdtas 3rd argument.