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.



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 $$

  • $\begingroup$ I was hoping you wouldn't say that... oh well iteration it is Thank you for your help! $\endgroup$ – DavidH Feb 16 '15 at 14:56

Let the original circle has radius $R$ and: $l=$ leght to the edge, $r=$ radius of the new circle. Now the arc in the box of the second circle has leght: $$ 2r\left[\pi-\arccos\left(\dfrac{l}{r}\right) \right] $$ Since you want that tis is the same as the circunference of the first circle $=2\pi R$ , you have to solve the equation: $$ \pi-\arccos\left(\dfrac{l}{r}\right)=\dfrac{\pi R}{r} $$ You can set $x=1/r$ and become: $$ \arccos(lx)=\pi(1-Rx) $$ That you can solve numerically.


Suppose we have only one boundary line, i.e. consider a circle in a half-plane.

The $\alpha$ angle at the circle's center, defined by the cut chord ends, satisfies $$\cos\frac\alpha 2 = \frac DR$$ where $D$ is a circle center's distance from the cutting line and $R$ is the cricle's radius. Then the removed arc length is $R\cdot\alpha$ and the remaining arc length is $$L=(2\pi - \alpha) R = 2\left(\pi - \arccos\frac DR\right)R\qquad (*)$$

Plug the known values for $L$ and $D$ and solve for $R$.
I'm afraid there is no simple algebraic solution and you'll have to do it numerically.

Once you do that, get back to the rectangle: test if the calculated $R$ causes a collision with another side and correct the (*) equation accordingly. EDIT If distances from the two closest edges are $D$ and $E$, the equation becomes $$L = \left(2\pi - \frac \pi 2 - \arccos\frac DR - \arccos\frac ER\right)R$$


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.