Finding smallest distance between two surfaces

Hello,

I am trying to implement a funtion of finding the closest distance between two surfaces(objects).
For example to measure a gap by selecting 2 objects and finding closest distance between them, or, ideally selecting 2 points on 2 objects and on this vector find the closest distance between objects.

I am not asking for a complete solution(although that would be really nice, hehe). But rather in which way should i look, or how would you implement such a function?

Any feedback appreciated!

Kind regards,

Alex.