animating a plane(keyframe or may be path), ideally want ship to display its speed just like it can display its name (if checked true from object display settings) or at screen bottom(view3d) where selected object and frame number displays. started writing a simple function to get speed first. even this isn't working correctly, may be because view doesn't get refreshed as i run and it doesn't actually go to previous frame and capture location.
import bpy
def calcSpeed():
ship = bpy.context.object
cf = bpy.context.scene.frame_current
pf = bpy.context.scene.frame_current - 1
bpy.context.scene.frame_set(pf)
pl = ship.location
bpy.context.scene.frame_set(cf)
cl = ship.location
speedVector = pl - cl
print (pf,cf)
print (pl,cl)
any ideas or pseudo code will really help, huge thanks for time and support.