# How can I calculate the acceleration of an object?

Is there some easy way to calculate the acceleration of an object at every point in time, between the two closest keyframe?

I'm thinking that the easiest way would be to calculate the velocity of the object and then calculate it's derivative. However, for that I need the time difference, which I don't know how to calculate.

Is this even possible (currently :D)?

## 2 Answers

However, for that I need the time difference, which I don't know how to calculate.

You can use the second order finite differencing to approximate the acceleration. And by using a central differencing scheme you can achieve second order accuracy.

In Blender, you can use FCurve.evaluate function to get the position of one object:

action = bpy.data.actions[0]
curve = action.fcurves[0]
# Evaluate object's position at time t
position = curve.evaluate(t)


And you can use central second order differencing to calculate the acceleration at time t:

def D(curve, t):
h = 1e-4
return (curve.evaluate(t + h) - curve.evaluate(t) * 2 + curve.evaluate(t - h)) / (h * h)


Note that you have to use backward or forward differencing scheme at boundary of an action curve since the value at t + h or t - h may not be defined there.

Also note that you will see an extraordinary large acceleration at jump point, which may be a problem when you build animations from the calculated acceleration.

Something I put together a few years back.

http://blenderartists.org/forum/showthread.php?244186-Trying-to-rig-a-vehicle-to-transform-linear-motion-into-rotational-motion-for-wheels&p=2042066&viewfull=1#post2042066

Rather than using fcurves (useless in this case as its animated via follow path ) running the script steps thru all the frames and calculates the speed (from the velocity vector) and acceleration based on obj.matrix_world.translation over a couple of frames and keyframes them to custom properties.

Looking at it now there should also be a displacement

disp += abs(v)

given we do use petrol in reverse.

IIRC this was pre the events handler system, & I've often wondered how it would go with a frame_change_pre and post handler and global variables.