"is there a method to define it automatically ? "
Well, nothing that would be a reasonable amount of effort, I fear.
I think the question here is: how accurate do you need this to be? What you could try is: use multiple expanding sphere collisions at the objects’ surface points. Once one of the spheres overlaps, it’s radius is your distance.