I'm writing a computer program that needs to display circles in a particular way, but can't seem to figure out how to arrange them given the information I have available. The problem is as follows: (jump to the bottom to see a diagram)
- There is one large "green" circle with radius $R_g$.
- There is one smaller "blue" circle with radius $0 \leq R_b \leq G$.
- There are $n \in \mathbb{Z}_{\geq 1}$ "red" circles, each with radius $0 \leq R_r \leq R_b$.
- The blue and red circles must be placed on the inside circumference of the green circle.
- The blue and red circles must touch each other in a specific way (see diagram).
The problem is, given the following:
- $R_g$, the radius of the green circle,
- $R_b$, the radius of the blue circle, and
- $n$, the number of red circles
Calculate:
- $R_r$, the radius of the red circles
- $d$, the distance of the center of each of the red circles from the center of the green circle
- $\theta_r$, the angle between each of the red circles, and
- $\theta_b$, the angle between the blue circle and the nearest red circle.
I solved this problem when $R_b=R_r$ (when the radius of the blue circle is exactly the size of the red circles). In that case,
\begin{align*}
R_r &= R_b && \text{(given)}\\
d &= \frac{R_g \cdot \sec(\frac{\pi}{2}-\frac{\pi}{n+1})}{\sec(\frac{\pi}{2}-\frac{\pi}{n+1})+1} && \text{solution in link} \\
&= \frac{R_g}{1+\sin(\frac{\pi}{1+n})} && \text{simplified solution} \\
\theta_b = \theta_r &= \frac{2\pi}{n+1}
\end{align*}
Best Answer
Let $R_g$ be the radius of the green circumcircle, $R_b$ be the radius of the single blue circle, and there be $n \ge 1$ red circles. We wish to solve $\theta_r$, the angle between centers of each pair of consecutive red circles, and $R_r$, the radius of each of the red circles.
The radius of the centers of the red circles must be $R_g - R_b$. If we use a coordinate system where the origin is at the center of the green circle, the center of the blue circle is at $(R_b-R_g, 0)$.
If $n = 1$, then the one red circle has radius $R_r = R_g - R_b$ and is centered at $(R_b, 0)$.
If $n = 2$, then the two red circles have radius $R_r$ centered at $(x, \pm y)$, $$\left\lbrace\begin{aligned} R_r &= \displaystyle \frac{4 R_g R_b (R_g - R_b)}{(R_g + R_b)^2 } \\ x &= \displaystyle \frac{R_g ( 3 R_b - R_g )}{R_g + R_b} \\ y &= R_r \\ \theta_r &= 2 \operatorname{atan2}(y, x) = 2 \arctan\left(\frac{4 R_b (R_g - R_b)}{(3 R_b - R_g)(R_b + R_g)}\right)\\ \end{aligned}\right.$$
For $n \ge 3$, we need to solve $$\cos\left((n-1)\frac{\theta_r}{2}\right) - \frac{2 R_b}{R_g - R_b}\sin\left(\frac{\theta_r}{2}\right) + 1 = 0$$ for $\theta_r$; then $$R_r = \displaystyle R_g \frac{\sin\left(\frac{\theta_r}{2}\right)}{1 + \sin\left(\frac{\theta_r}{2}\right)}$$
I recommend using a binary search in range $$0 \le \theta_r \le \frac{2 \pi}{n}$$as there is only one zero for $$f(\theta_r) = \cos\left((n-1)\frac{\theta_r}{2}\right) - \frac{2 R_b}{R_g - R_b}\sin\left(\frac{\theta_r}{2}\right) + 1$$ If $f(\theta_r) \lt 0$, $\theta_r$ is too large; if $f(\theta_r) \gt 0$, $\theta_r$ is too small.
(The upper limit applies if $R_b = 0$, as then the red circles form a closed ring of circles.)
For neighboring red circles to touch, $$R_r = (R_g - R_r) \sin\left(\frac{\theta_r}{2}\right) \quad \iff \quad R_r = R_g \frac{\sin(\theta_r/2)}{1 + \sin(\theta_r/2)}$$
Here is a verified Python implementation, that returns $R_r$ and $\theta_r$ as a tuple:
If you add the following code, you can run it via
python3 this.py rG rB N out.svg
, specifying the green circle radius, blue circle radius, and the number of red circles, and it'll create an SVG image,out.svg
, for illustration and verification; you can view those in any browser.How did I find the solution for $n \ge 3$?
Consider the following illustration: The green circle is centered at origin, with radius $R_g$: The blue circle has radius $R_b$ and is centered at $(R_b - R_g, 0)$. Note that its center $x$ coordinate is actually $c = -R_g + R_b$: blue radius in from the leftmost point on the green circle.
Angle $\theta$ forms an isosceles triangle, with sides $R_g - R_r$ and base $2 R_r$. If we split it into two right triangles, where the hypotenuse length is $R_g - R_r$, short side length is $R_r$, and the angle opposite the short side $\theta/2$. Thus, $$\sin\left(\frac{\theta}{2}\right) = \frac{R_r}{R_g - R_r} \tag{1a}\label{G1a}$$ Solving this for $R_r$ yields $$R_r = R_g \frac{\sin\left(\frac{\theta}{2}\right)}{1 + \sin\left(\frac{\theta}{2}\right)} \tag{1b}\label{G1b}$$ This means that the red circle radius $R_r$ is defined by $\theta$, and $\theta$ is our only free variable. And only positive $\theta$ make any sense.
If there was no blue circle at all, then the $n$ red circles would cover the full circle: $n \theta = 2 \pi$. This gives us the possible range for $\theta$, $$0 \lt \theta \lt \frac{2 \pi}{n} \tag{2}\label{G2}$$
The topmost red circle is always at angle $$\theta_T = \frac{(n - 1) \theta}{2}$$ counterclockwise from right. Its center is at $(x, y)$, $$\left\lbrace \begin{aligned} x = (R_g - R_r) \cos \theta_T &= (R_g - R_r) \cos\left(\frac{(n - 1) \theta}{2}\right) \\ y = (R_g - R_r) \sin \theta_T &= (R_g - R_r) \sin\left(\frac{(n - 1) \theta}{2}\right) \\ \end{aligned} \right. \tag{3a}\label{G3a}$$ For the topmost red circle and the blue circle to touch, we need the distance between their centers to match the sum of their radiuses. Squaring the distances, we have $$(x - b)^2 + y^2 = (R_b + R_r)^2 \tag{3b}\label{G3b}$$ Next, we subtract the right side from the left side (so we get a function of form $f(\theta)$ whose root we need to find), substitute $x$, $y$, $b$, and $R_r$.
At this point, the expression starts to sprawl, and I for one switch to a Computer Algebra System. I suggest wxMaxima or SageMath; both free and available for all operating systems. In Maxima:
and after applying rational and trigonometric simplifications (
trigsimp(ratsimp(EQ));
), we getThat divisor, $2\sin(\theta/2) - \cos(\theta/2)^2 + 2 \ge 1$ in this context, because we only do this for $n \ge 3$ and therefore $0 \lt \theta/2 \lt \pi/3$, per $\eqref{G2}$. So, we can just omit it, by multiplying the equation with it. There is also a common factor $R_g$, which we can divide out at the same time:
trigsimp(ratsimp(% * (2*sin(theta/2) - cos(theta/2)^2 + 2) / R_g));
and we getReplacing $\cos(\theta)^2$ with $1 - \sin(\theta)^2$, we have
and finally, if we ask Maxima to solve this for $\theta$,
solve(%, theta);
, it gives us two solutions:The first one is garbage, so we grab the second one,
cos((n-1)*theta/2) = -(2*R_b*sin(theta/2)-R_g+R_b)/(R_b-R_g);
, and subtract right hand side from left hand side to get a nice function form:ratsimp(lhs(%) - rhs(%)) = 0;
, so we geti.e. $$\frac{(R_g - R_b) \cos\left(\frac{(n-1) \theta}{2}\right) - 2 R_b \sin\left(\frac{\theta}{2}\right) + R_g - R_b }{R_g - R_b} = 0$$ or, equivalently $$\cos\left(\frac{(n-1)\theta}{2}\right) - \frac{2 R_b}{R_g - R_b} \sin\left(\frac{\theta}{2}\right) + 1 = 0$$