Getting the closest distance between two parts surfaces

Imagine two parts of arbitrary size, orientation, and position. My goal is to find the distance between the closest points of each parts surface.

The closest thing I have to an idea on how to go about this is raycasting:
Say we have 1 vector3 position, and one part with random size, position, and orientation. To get the “closest” point on that parts surface, we can raycast from the point, to the parts origin, and the position of the raycast result will be the “closest” point to the raycast origin on the surface of the part. I say closest in partenthesis because of the part is really long, and is rotated properly, one end of it may be a lot closer to the point then the result this method will give you. I now need to figure out how to take this concept, and manipulate it so it will work with 2 parts, instead of 1 part and 1 position.

This concept is similar to this post, Get Distance from surfaces - Help and Feedback / Scripting Support - DevForum | Roblox, however there aren’t any resources linked to the topic, and the person who made it didn’t actually share how he solved his problem.

Any help is appreciated.

Raycast from part1 to part2 and then raycast from part2 to part1 and then get the magnitude between the 2 raycast results’ positions

this was my original idea, however if you have two long parts at random rotations, the ends of each part could be really close and this solution does not account for that.