[Math] Find radius of fixed length arc of a circle in a bounding box when the circle intersects the edge of the bounding box

circlesgeometry

I have a bounding box that is represented as a Cartesian starting point $(0,0)$ with a width and a height.

I have a circle with centre point that can be anywhere within the bounding box. The circumference of the circle is fixed.

When the circle intersects the edge of the bounding box an arc is formed. This new arc has to have a length equal to the circumference of the original circle.

The location of the centre of the circle is known, therefore the distance from the centre to the edge of the bounding box is known.

As you move closer to the edge of the bounding box, the radius of the circle must increase to keep the arc length the same.

The start and stop points of the arc are unknown as the radius is unknown.

This is where I'm stuck. Knowing only the distance from the bounding box and the fixed length of the arc how can I find the radius of the circle?

I have drawn an image to represent the question but I'm unable to post due to lack of reputation.
Image of issue

Any help on this will be greatly appreciated as I have spent many days trying to figure this out.

What I am trying to achieve is a radial menu with a fixed number of items (of a fixed size) that can be displayed around a centre point. The fixed length is a calculated length that all menu items can fit around.

I am implementing this in .net, but for the sake of this query it's purely a math question.

This has been moved from stack overflow.

Best Answer

Illustration

So you know the distance $d=CD$ between center and boundary. Then you can write

$$\cos\angle ECD = \tfrac dr \qquad \angle ECF = 2\angle ECD = 2\arccos\tfrac dr$$

Now the length of an arc is $r$ times its angle, so the outside arc is $r\angle ECF$ and the inside arc is

$$s = r(2\pi-\angle ECF)=2r(\pi-\arccos\tfrac dr)$$

You want that number to be equal to some given value, so you want to solve the above equation for $r$. Unfortunately, that equation is transcendental, so you can't expect a closed form solution to your problem. Your best bet is some form of iterative numeric approximation.

Plot of function

As you can see from that plot, you can expect that for many possible ratios of $\frac sd$, you get two distinct solutions for $r$.

The apex (with the vertical tangent) appears to be at

$$ s/d\approx 5.94338774142760424162091392488776998544210982523814509283191138267355981 \\ r/d\approx 1.06193134974748196175464922830803488867448733227482933642882008697882597 $$