I am doing some web design, and I need a way to dynamically figure out what to set a circle's diameter to so that it exactly covers a rectangle, as shown in the above image. In the first scenario (in the image), I calculated that the diameter of the circle was 12% greater than the width of the rectangle, and thought this would work for all rectangles, but it does not. The problem is that the width of the rectangle is dynamic, so I never know what it's value will be ahead of time, I have to size the circle based off of whatever dimensions the rectangle is at the time.
This is probably a fairly simple formula, but I am far from being a mathematician, clearly. If I can do anything to clarify my question, please ask! Thanks!