I need to find how distant the center of an orthogonal rectangle is from the center of a circle, given a specific angle.
The dimensions of the rectangle are proportional to the circle radius, so they use a 0-1 range, where 1 is the radius of the circle. The objective is to get the position of the center of that rectangle, knowing its size, so that when an angle is given one of its corner (or sides) is exactly on the circumference.
To clarify, here are three image examples.
Here is a rectangle that touches the circle on one of its sides:
The same rectangle, with a different angle, now touching the circle at one of its corners:
Another rectangle, with the same angle as the last, showing a different position for its center:
The above is just an example, the final purpose is to get an arbitrary function, no matter the angle: I'm actually trying to put a given text as close as possible to the circle. The bounding rectangle of the text is known (its size is proportional to the circle radius), and I need to know where that rectangle can be placed in order to make it as close as possible to the circle.
Note that I don't need the position in the circumference at a given angle (I know I can use sine/cosine for that). I specifically need the position of the rectangle with its center placed in the line that goes from the center of the circle, with the given angle.
What I cannot understand is how to find the geometry of the rectangle, getting its center is obviously a consequence (or, maybe, getting the geometry is, once the center is found?).
I have limited math knowledge, I've tried to use my basic trigonometry skills, but I failed.
My initial intuition was to just place the rectangle at one of its sides for orthogonal angles and then use the law of sines, along with the tangent of the circumcircle of the rectangle, for other cases, but then I realized that, depending on the ratio between the rectangle size (thus, its diagonals) and the radius, there are cases where the contact point is still on one side of the rectangle, not on its corners. Still, I wasn't able to get the logical link between any of them.
Expanding the first image example, I realize that I cannot rely on the circumcircle:
I'd still settle for a corner based solution, though, as this may suffice, even if not optimal like the following:
Due to the limited knowledge noted above, I'm also not well versed in math symbols, so while I'd appreciate any answer (and then try to find my way to understand standard syntax), I'd also be grateful for logical explanations of those answers.





$\mathrm{Fig.\space 1}$ shows vertex $A$ of the rectangle $ABCD$ having measurements $2\lambda r\times 2\mu r$ touching a circle of radius $r$, the center of which is located at the origin $O$ of $xy-$coordinate system. The center of the rectangle is at $M$. It is given that the line $OM$ joining the centers of the circle and the rectangle makes an angle $\phi$ with the $x-$axis. Our aim is to determine the length $OM$ in terms the known variables $r, \lambda, \mu$, and $\phi$. Although OP has stated the condition $0\lt \lambda ,\mu\le 0.5$ in his problem statement, we are going to ignore it because we found that the derived formulae are valid as long as $\lambda ,\mu\gt 0$.
To facilitate the derivation of the sought formula, we have drawn a line parallel to $OM$ thorough the vertex $A$ to intersect the $y-$axis and the vertical line $MN$, which passes through $M$, at $G$ and $F$ respectively. This makes $\measuredangle FAE = \phi$. We also drop a perpendicular to the line $GF$ from the origin $O$ and its foot is $H$. With that we have $\measuredangle HOG = \phi$. Finally, we draw the radius $OA$ and let $OG=c$.
By considering the right-angled triangle $AEF$, we obtain, $$FE=AE\tan\left(\phi\right)= \lambda r\tan\left(\phi\right)\quad\text{and}\tag{1}$$ $$AF=AE\sec\left(\phi\right)= \lambda r\sec\left(\phi\right).\qquad\quad\tag{2}$$
It follows from (1) that $$MF=ME-FE=\mu r-\lambda r\tan\left(\phi\right). \tag{3}$$
Since $OGFM$ is a parallelogram, using (3), we can write, $$c=OG=MF=\mu r-\lambda r\tan\left(\phi\right). \tag{4}$$
We also have, $$OM=GF=GH+HA+AF. \tag{5}$$
$\triangle GHO$ is a right-angled triangle. $${\large{\therefore}} \enspace GH=c\sin\left(\phi\right)\quad\text{and}\tag{6}.$$ $$OH= c\cos\left(\phi\right).\quad\tag{7}$$
$\triangle OHA$ is also a right-angled triangle. After applying Pythagoras’s theorem, we can substitute the value of $OH$ from (7) to obtain, $$HA=\sqrt{OA^2-OH^2}=\sqrt{r^2- c\cos\left(\phi\right)^2}.\tag{8}$$
Finally, substitution of values from (6), (7), and (2) in (5) gives the following formula. $$OM=GF=GH+HA+AF= c\sin\left(\phi\right)+ \sqrt{r^2- c\cos\left(\phi\right)^2}+\lambda r\sec\left(\phi\right)$$
Using (3), $c$ can be eliminated from this formula and further simplifications leads to, $$OM=r\left(\mu\sin\left(\phi\right)+\lambda\cos\left(\phi\right)+\sqrt{1-\Big(\mu\cos\left(\phi\right)-\lambda\sin\left(\phi\right)\Big)^2}\right).$$
When using this formula, OP should be careful to select the correct value for the angle $\phi$ depending on the orientation of the line that joins the two centers. As shown in $\mathrm{Fig.\space 2}$, $\phi$ is the angle between this line and the $x-$axis and must be always less than or equal to $90^o$.
Deriving the formula for the case, in which a side of the rectangle touches the circle, is very easy. So we are not going to describe it in detail. Instead, we leave you with the $\mathrm{Fig.\space 3}$, which, we hope, helps you to analyse this case.
$\underline{\text{Added at the request of OP}}$:
Unlike the case described in detail above, there are only four possible scenarios in this case. As shown in $\mathrm{Fig.\space 4}$, any given rectangle can touch a circle only at $P$, $Q$, $U$, or $V$. The distance between the two centers, when the point of touching is at either $P$ or $U$, is given by, $$OM=r\left(1+\lambda\right)\sec\left(\phi\right).$$
In a similar vein, when the point of touching is at either $Q$ or $V$, this distance is given by, $$OM=r\left(1+\mu\right)\csc\left(\phi\right).$$
Here too, the angle $\phi$ between $OM$ and the $x-$axis is always less than or equal to $90^o$.