Inertia around axis

Hello folks!

I’m in a bit of a pickle trying to implement a stable spring-damper system for a physics game. Essentially, what I’m trying to do is to implement a semi stiff rotational relationship between two rigid bodies (I can’t use joints for this). I came across an implementation I’d like to try at

but it requires the inertia for the objects in question. The problem is that I can’t seem to find a way to get that value. I am aware that rigidbodies have a inertia tensor (not something I fully understand but I think I get the picture) but I can’t seem to figure out how to use this to get the value that I need.

So in summary, I’m trying to figure out the inertia of any rigidbody around a given axis. Also I’d like to understand what happens if the axis does not go through the center of mass of the of the rigidbody.

Thanks for the help and sorry if I butchered the explanation :slight_smile:

public static float MomentOfInertiaAlongAxis(this Rigidbody rb, Vector3 axis) {
axis = Quaternion.Inverse(rb.inertiaTensorRotation) * axis.normalized; //rotating the torque because it’s equivalent and more efficient
Vector3 angularAcceleration = new Vector3(Vector3.Dot(Vector3.right, axis) / rb.inertiaTensor.x, Vector3.Dot(Vector3.up, axis) / rb.inertiaTensor.y, Vector3.Dot(Vector3.forward, axis) / rb.inertiaTensor.z); //calculating the angular acceleration that would result from a torque of 1 Nm (the same way that unity does it)
return 1 / angularAcceleration.magnitude; //moment of inertia = Torque / angular acceleration