Determining shortest vector between a ray and an axis-aligned 3D bounding box (correcting a near-miss) I have a situation where (due to floating point error) a ray that is known to hit a bounding box fails due to floating point error. (1e-8 or so)

Expanding the box is not an acceptable solution in my specific use case. However, if I could "snap" the ray to the box, that would work out well.

In order to do so, I need to find the shortest vector from a given ray to a bounding box. In 2 dimensions, that would look like this: 



If I can get that red vector, I can add it to the origin and the ray will be shifted to the bounding box.

In 2D this is apparently relatively easy, as you can get distance between two lines like here, then find the smallest of the 4 lines and use that. 

But in 3D I am not aware of how to do this. Does anyone know if there is a way?
If you know the rounding error, you could subtract the error from your vectors so that rays would overlap the bounding box. This could be done in your intersection tests.

In 3D, computing shortest distance between a vector and face of a bounding box would be another way to shift the vector to overlap the bounding box. But I doubt this approach would work well as it essentially tries to fix a rounding problem.