https://www.algorithm-archive.org/contents/verlet_integration/verlet_integration.html
https://www.techbrood.com/zh/news/webgl/%E7%B2%92%E5%AD%90%E8%BF%90%E5%8A%A8%E6%A8%A1%E6%8B%9F—verlet%E7%A7%AF%E5%88%86%E7%AE%97%E6%B3%95%E7%AE%80%E4%BB%8B.html
http://datagenetics.com/blog/july22018/index.html
http://www.myliushu.com/4922.html 加速度公式
Verlet Integration
Verlet integration is essentially a solution to the kinematic equation for the motion of any object,
where x is the position, v is the velocity, a is the acceleration, b is the often forgotten jerk term, and t is time. This equation is a central equation to almost every Newtonian physics solver and brings up a class of algorithms known as force integrators. One of the first force integrators to work with is Verlet Integration.
So, let’s say we want to solve for the next timestep in x . To a close approximation (actually performing a Taylor Series Expansion about x(t±Δt) ) , that might look like this:
This means that if we need to find the next x , we need the current x , v , a , etc. However, because few people calculate the jerk term, our error is typically O(Δt3) .
that said, we can calculate x with less knowledge and higher accuracy if we play a trick!
let us say we want to calculate x of the previous timestep.
again, to a close approximation, that might look like this:
now, we have two equations to solve for two different timesteps in x, one of which we already have.
if we add the two equations together and solve for x(t+Δt) , we find that
so, this means we can find our next x simply by knowing our current x, the x before that, and the acceleration!
no velocity necessary!
in addition, this drops the error to O(Δt4) . which is great!
here is what it looks like in code:
function verlet(pos::Float64, acc::Float64, dt::Float64)
prev_pos = pos
time = 0.0
while (pos > 0)
time += dt
temp_pos = pos
pos = pos * 2 - prev_pos + acc * dt * dt
prev_pos = temp_pos
end
return time
end
now, obviously this poses a problem;
what if we want to calculate a term that requires velocity, like the kinetic energy, 0.5mv^2?动能?
in this case, we certainly can not get rid of the velocity!
well, we can find the velocity to O(Δt2) accuracy by using the Stormer-Verlet method, which is the same as before, but we calculate velocity like so
note that the 2 in the denominator appears because we are going over 2 timestep.
it is essentially solving v = Δx/Δt.
in addition, we can calculate the velocity of the next timestep like so:
However, the error for this is O(Δt) , which is quite poor, but it gets the job done in a pinch. Here’s what it looks like in code:
function stormer_verlet(pos::Float64, acc::Float64, dt::Float64)
prev_pos = pos
time = 0.0
vel = 0.0
while (pos > 0.0)
time += dt
temp_pos = pos
pos = pos * 2 - prev_pos + acc * dt * dt
prev_pos = temp_pos
# Because acceleration is constant, velocity is straightforward
vel += acc * dt
end
return time, vel
end