Smallest perpendicular distance between 2 breps

A similar goal was implemented here using IVRay (IsoVist Ray) to find the vertical distance between the area centroid of each building and the terrain mesh.

That’s not quite what you are asking for though because parts of the buildings may go below the terrain. To avoid that, you would have to project a 2D outline of each buildings perimeter unto the mesh, then find the highest discontinuity point of the projected curves.