Calculate radius of circle required to completely overlap rectangle when centered within it

178 Views Asked by At

Consider a rectangle with known width ($w$), height ($h$) and center ($R$). You can assume $w\geqslant h$.

A random point ($C$) is selected within the rectangle which is a distance of $x$ (horizontally) and $y$ (vertically) from $R$:

Image 1

A circle is drawn centered at $C$ such that it completely overlaps the rectangle, but no more:

Image 2

Is there a way to calculate the circle's radius $r$, given the known inputs $w$, $h$, $R$, $C$, $x$ and $y$?

1

There are 1 best solutions below

4
On BEST ANSWER

Yes, there is. The radius of the circle is merely the length from $C$ to the vertex of the rectangle farthest away. Just draw a line from $C$ to this vertex and make that the hypotenuse of a right triangle. The legs of the triangle would be $|y|+\frac{h}2$, and $|x|+\frac{w}2$. Using the Pythagorean Theorem, this is $$\sqrt{({|y|+\frac{h}2})^2+({|x|+\frac{w}2})^2}$$.