# Shortest distance between two shapes

This is the scenario of my problem. I have an image of two objects ( of arbitrary shape, not convex, not touching or crossing each other, kept a few space apart).

And I am supposed to find the shortest distance between these two shapes.

First thing that came to my mind was to use bruteforce methods, ie find all the elements of shape A's perimeter (Let it be set X) and same for B's perimeter (Let it be Y ). Then find distance between all possible combinations ( excluding repetitions) of elements of X and Y and take the minimum value in it.

But I am sure it will take a lot of time.

Is there any other better way to do this ?

-