It looks like you are thinking of the distance between the centers of rectangles. If a rectangle has opposite corners $(a,b)$ and $(c,d)$ the center is $(\frac{a+c}{2},\frac{b+d}{2})$. As Weltschmerz says, you can just use the Pythagorean formula between these centers. It is easy to compute. An alternative is the Hausdorff distance. Between your green rectangle and the largest red one, it would give the distance from the upper right corner of the red one to the closest corner of the green one. It is harder to compute, but might be more what you want.
Added after the comment: you can calculate the orange lengths if you want, but they will not meet the usual requirements for a distance. The distance between two squares sharing an edge will be zero, but they are not the same rectangle. The triangle inequality will also fail. If the green rectangle is A and the upper right is B, there is a certain distance between them. If I now put a rectangle C in between which touches the top of A and the bottom of B, the distance from A to C is zero, the distance from C to B is zero, but the distance from A to B is greater than zero.
To calculate the orange distances, you can find the equation of the line going through the centers using the two point form. The line through $(a,b)$ and $(c,d)$ has equation $y-b=\frac{d-b}{c-a}(x-a)$, find the points where it hits the edge of the rectangles, and use Pythagoras.