Can anyone suggest a relatively simple way of finding the shortest dimension between two rectangles or a rectangle and circle?

Rectangle1
Centre = R1x,R1y
Width = W1
Height = H1

Rectangle2
Centre = R2x,R2y
Width = W2
Height = H2

Circle
origin =CX, CY
Radius =R

I'd be able to find it out myself but there'd be a page of ifs and buts. Hoping a mathematical mind might be able to rationalize it to a sensible formulae.