How to calculate velocity and momentum of a rigid body

Hello everyone,

I have a simple animation in which there are two planes and balls on the planes. There’s one ball on an inclined plane, and a couple of balls sitting on a horizontal plane below that ball. When the animation starts, the ball on the top rolls down the slope and collides with other balls. I need to calculate the velocity and momentum of the balls.

Here’s my code so far:

import bpy
from mathutils import Vector

def distance_line(point1: Vector, point2: Vector) → float:
return (point2 - point1).length

object =[“Sphere”]

prev_location = object.location.copy()

for frame in range(10, 151, 10):

new_location = object.location

distance = distance_line(new_location, prev_location)
distance_vec = new_location - prev_location

time = frame / 24
velocity = distance_vec / time
speed = distance / time
print("frame", frame, "speed = ", speed, "velocity = ", velocity)
prev_location = new_location.copy()

I have baked the animation otherwise the finding the location of the object in specific keyframes doesn’t work. So the problem with the above code is that if I let the for loop calculate the location for every key frame, it will show the exact same location value for consecutive frames. If I make the loop run for 10 steps I can see the change in location, but it’s still not a gradual change, so I can’t really calculate the exact velocity at a certain point in time. I even get inconsistent values for the velocity with this method. Is there any other way to do it in Blender?