3
$\begingroup$

A square of given side length $S$ is to inscribe two circles and an ellipse as shown in the figure below.

enter image description here

If the radius of circle $(1)$ is given, determine the center and radius of circle $(2)$, then determine the inscribed ellipse $(3)$.

My attempt:

From tangency between circles $(1)$ and $(2)$, it is fairly easy to find the radius of circle $(2)$, and this also gives its center.

For the ellipse, the center has to lie halfway between the top and bottom sides of the square. What is unknown is the $x$ coordinate of this center ($C_x$). The points of tangency with the two circles are also unknown, and in addition the semi-major and semi-minor axes of the ellipse and the angle of rotation of the major axis from the standard orientation along the $x$ axis is also unknown. Using parametric equations for the two circles, we need two parameters $t_1$ and $t_2$ (unknown) to describe the two tangency points with the ellipse.

So the unknowns are: $t_1, t_2, a, b, \theta, C_x $.

Six equations can be written to describe the tangency with the top (and the bottom) side, and the right side of the square, and tangency with the two circles.

I leave it open to the reader to develop these equations, and run an example of this setup in order to determine the upper left circle (Circle $2$) and the ellipse on the right $(3)$.

$\endgroup$
5
  • 1
    $\begingroup$ The ellipse cannot exist if circle 1 is large enough. So large that the common tangent to both circles passes through B. $\endgroup$ Commented May 30 at 17:27
  • $\begingroup$ Yes. That's true. But the sake of finding the ellipse, assume that the radius of the lower circle (Circle 1) has been chosen appropriately to ensure that the ellipse on the right exists. $\endgroup$
    – Quadrics
    Commented May 30 at 20:29
  • $\begingroup$ May I suggest you remove the $e$ at the end of your user name ? $\endgroup$ Commented May 31 at 14:45
  • $\begingroup$ I'll change my user name completely when I am allowed. $\endgroup$
    – Quadrics
    Commented May 31 at 15:43
  • $\begingroup$ If Circle 1 is "too large", the ellipse may still exist but now it's reversed in orientation, overlapping with the circles. $\endgroup$ Commented Jun 2 at 21:33

3 Answers 3

3
+25
$\begingroup$

I'll walk through the derivation of equations capturing the problem. Symbolically, things get pretty ugly (with degree-$14$ polynomials in hundreds of terms), so numerical methods are crucial. But, to show that my approach works, here's a sample configuration:

enter image description here

I'm rearranging and relabeling things a bit.


For a square of side-length $2s$, coordinatize with $$A=(-s,-s) \qquad B = (s,-s) \qquad C = (s,s) \qquad D = (-s,s) \tag1$$ Let $A'$ and $B'$ be the centers of the circles (offset from $A$ and $B$ instead of OP's $A$ and $D$), with $$A' := A + (h+k)\,(1,1) \qquad B' := B + (h-k)\,(-1,1) \tag2$$ for some $h$ and $k$. Let $A''$ and $B''$ be the points of tangency of those circles with the ellipse; we'll write: $$A'' := A' + (h+k)\,(\cos\alpha, \sin\alpha) \qquad B'' := B' + (h-k)\, (-\cos\beta,\sin\beta) \tag3$$ (I've negated $\cos\beta$ in $B''$ for a kind of mirror symmetry with $A''$.)

Finally, let $C'$, $D'$, $T$ be the points of tangency of the square wth the ellipse; with $$C' := C + (u-v)\,(0,-1) \qquad D' := D + (u+v)\,(0,-1) \qquad T := (t,s) \tag4$$

Now to derive some equations relating the parameters $h$, $k$, $\alpha$, $\beta$, $u$, $v$, $t$ ...


The tangency of the circles requires $$|A'B'|^2 = (2h)^2 \quad\to\quad s^2+k^2-2hs=0 \quad\to\quad h = \frac{s^2+k^2}{2s} \tag5$$ That was easy! Continuing ...

To get the conic tangent to the square at $C'$, $D'$, $T$, I use a trick of nudging copies of two points to get a total of five, which determine an conic; then I collapse the copies back onto the originals. Algebraically, I define $$C'' := C' + (0,\varepsilon) \qquad D'' := D' + (0,\varepsilon) \tag6$$ and use this determinant formula shown in this answer for the conic through the five points $C'$, $D'$, $T$, $C''$, $D''$; the result has a factor of $\varepsilon^2$, which I conveniently cancel (because it's non-zero) before then substituting $\varepsilon\to 0$ everywhere else (because it's vanishingly-small), to get $$\begin{align} 0 &= x^2\,\left(s \left(u^2 + v^2\right) - 2 t u v\right) \;+\; (y - (s+u))^2 \; s \left(s^2 - t^2\right) \\ &\quad+ 2 x (y - (s+u))\; v \left(s^2 - t^2\right) \\ &\quad- s (s u - t v)^2 \end{align} \tag7$$ Let the tangent vector to the conic at $(x,y)$ be $(\dot{x},\dot{y})$. The differential form of $(7)$ relates these values: $$\begin{align} 0 &= \dot{x}x\,\left(s \left(u^2 + v^2\right) - 2 t u v\right) \;+\; \dot{y}(y - (s+u)) \; s \left(s^2 - t^2\right) \\ &\quad+ (\dot{y}x +\dot{x}(y - (s+u)))\; v \left(s^2 - t^2\right) \end{align} \tag{7'}$$ This must hold when $(x,y)=T$ and $(\dot{x},\dot{y})=(1,0)$, which tells us $$st \left(u^2 + v^2\right) = u v \left(s^2+t^2\right) \quad\to\quad t = \frac{su}{v},\frac{sv}{u}\tag{8}$$ The solution $t=su/v$ is extraneous (it reduces $(7)$ to a line through $C'$ and $D'$, so we take $t=sv/u$. With this, $(7)$ and $(7')$ become $$\begin{align} u^2 x^2 \;+\; s^2 (y - (s+u))^2 \;+\; 2 s v x (y - (s+u)) &\;=\; s^2 (u^2 - v^2) \tag{9} \\[4pt] \dot{x}\left(u^2 x + s v (y - (s+u))\right) \;+\; \dot{y}\,s (v x + s (y - (s+u))) &\;=\; 0 \tag{9'} \end{align}$$ We want these relations to be hold for points $A''$ and $B''$, with corresponding tangent vectors $(-\sin\alpha,\cos\alpha)$ and $(\sin\beta,\cos\beta)$. So, "all we have to do" is substitute (recalling $(5)$) and solve for some chosen four of $k$, $u$, $v$, $\alpha$, $\beta$ in terms of the fifth.

Any way of going about it seems to be a mess. From the first substitutions, we have four polynomials equations (two from $(9)$ and two from $(9')$) that are quartic in $k$, and quadratic in $u$ and $v$, with trigs of $\alpha$ and $\beta$ floating around. Eliminating variables makes things worse and worse.

As for the trigs ... In order that Mathematica can manipulate things as simple polynomials, I used the tangent half-angle substitution $$a := \tan\frac12\alpha \qquad b := \tan\frac12\beta \tag{10}$$ so that $$\cos \alpha = \frac{1-a^2}{1+a^2} \qquad \sin\alpha = \frac{2a}{1+a^2} \qquad \cos\beta = \frac{1-b^2}{1+b^2} \qquad \sin\beta = \frac{2b}{1+b^2} \tag{11}$$ Note that these made anything prettier.


At this point, I resort to numerical methods. The figure above shows a case $s=5$ and $u=-3$, with remaining values taken from the last row of this table of Mathematica's full set of real solutions (and $h$ and $t$ calculated from $(5)$ and $(8)$):

$$\begin{array}{cccc} k & v & a & b \\ \hline \phantom{-}44.9302 & \phantom{-}659.359 & -0.97540 & -2.45736 \\ -44.9302 & -659.359 & -2.45736 & -0.97540 \\ \hline -16.7662 & -120.821 & \phantom{-}0.43142 & -0.88397 \\ \hline -19.4486 & \phantom{-}49.6271 & -0.76768 & -2.48510 \\ \phantom{-}19.4486 & -49.6271 & -2.48510 & -0.76768 \\ \hline \phantom{-}25.3198 & \phantom{-}11.4631 & -1.07842 & -2.46041 \\ -25.3198 & -11.4631 & -2.46041 & -1.07842 \\ \hline -12.7342 & -3.69367 & \phantom{-}0.42058 & -1.33054 \\ \hline \phantom{-}12.2945 & \phantom{-}0.34276 & -2.35157 & \phantom{-}0.32602 \\ -12.2945 & -0.34276 & \phantom{-}0.32602 & -2.35157 \\ \hline \phantom{-}0.46032 & \phantom{-}2.46871 & \phantom{-}0.59875 & \phantom{-}1.20824 \\ -0.46032 & -2.46871 & \phantom{-}1.20824 & \phantom{-}0.59875 \\ \hline \end{array}$$

Clearly, many of the above cases have no chance of corresponding to the prescribed configuration of an "inscribed ellipse", as they put tangent points $C'$ and $D'$, and/or circle centers $A'$ and $B'$, well beyond the square. Generally, it's not even guaranteed that conic $(7)$ is an ellipse. (The condition for ellipse-ness is actually pretty simple. I'll leave that to the reader.) Moreover, when we do have an inscribed ellipse, as desired, the circles may turn out to be internally tangent to it. (I had to go through a few choices of $s$ and $u$ to generate a configuration that looked like OP's original.)

Nevertheless, it would seem that the solutions apply to a generalized form of the problem, where the circles and conic are tangent somewhere to the side-lines of the square.

Anyway ... That's about as far as I expect to take this analysis. I hope it's been helpful.

$\endgroup$
3
$\begingroup$

Giving $C_1$ we define $C_2$. Now we have

$$ \cases{ C_1(x,y,r)=(x-r)^2+(y-r)^2-r^2=0\\ C_2(x,y,r)=(x-r)^2+(y-L+r)^2-r^2=0\\ E(x,y,x_0,y_0,a,b,t) = a^2 (\sin (t) (x-x_0)+\cos (t) (y-y_0))^2+b^2 (\cos (t) (x-x_0)-\sin (t) (y-y_0))^2-a^2 b^2=0 } $$

We have five tangent points: $\{p_i, i = 1,\cdots,5\}$ with $p_i = \{x_i,y_i\}$. Now $p_3 = \{0,x_3\}, p_4=\{L,y_4\}, p_5 = \{x_5,L\}$. The conditions are:

$$ \cases{ E(p_i,p_0,a,b,t)=0,\ \ i = 1,\cdots,5\\ C_1(p_1,r_1) = 0\\ C_2(p_2,r_2) = 0\\ \nabla E(p_1,p_0,a,b,t)\times \nabla C_1(p_1,r_1) = 0\\ \nabla E(p_2,p_0,a,b,t)\times \nabla C_2(p_2,r_2) = 0\\ \nabla E(p_i,p_0,a,b,t)\times \nabla B_i,\ \ i = 3,\cdots,5 } $$

where $B_i$ are the border conditions. So we have $12$ unknowns $\{a,b,x_I,y_i,t\}$ and $12$ conditions. Follows the MATHEMATICA code to solve this system of equations.

Clear[c1, c2, ell]
parms = {r1 -> 10/9, r2 -> 0.8947408975536746` , L -> 4};
parms = {r1 -> 1.2, r2 -> 0.818219539958136` , L -> 4};
parms = {r1 -> 1.21, r2 -> 0.8099999999999725`, L -> 4};
c1[p_, r_] := (p[[1]] - r)^2 + (p[[2]] - r)^2 - r^2;
c2[p_, r_] := (p[[1]] - r)^2 + (p[[2]] - (L - r))^2 - r^2;
ell[p_, p0_, a_, b_, t_] := a^2 ((p[[2]] - p0[[2]]) Cos[t] + (p[[1]] - p0[[1]]) Sin[t])^2 + b^2 ((p[[1]] - p0[[1]]) Cos[t] - (p[[2]] - p0[[2]]) Sin[t])^2 - a^2 b^2
p0 = {x0, y0};
p = {x, y};
p1 = {x1, y1};
p2 = {x2, y2};
p3 = {x3, 0};
p4 = {L, y4};
p5 = {x5, L};
pts = {p1, p2, p3, p4, p5};
equs1 = Table[ell[pts[[k]], p0, a, b, t], {k, 1, 5}];
equs2 = {c1[p1, r1], c2[p2, r2]};
gradc1 = Grad[c1[p, r1], p];
gradc2 = Grad[c2[p, r2], p];
gradell = Grad[ell[p, p0, a, b, t], p];
gradab = {0, 1};
gradbc = {1, 0};
gradcd = {0, 1};
cross[u_, v_] := u[[2]] v[[1]] - u[[1]] v[[2]]
equs3 = {cross[gradc1, gradell] /. Thread[p -> p1],
   cross[gradc2, gradell] /. Thread[p -> p2],
   cross[gradab, gradell] /. Thread[p -> p3],
   cross[gradbc, gradell] /. Thread[p -> p4],
   cross[gradcd, gradell] /. Thread[p -> p5]};
equs = Join[Join[equs1, equs2], equs3] /. parms;
Length[equs]
vars = {a, b, x0, x1, x2, x3, x5, y0, y1, y2, y4, t};
inits = {{a, 2.2}, {b, 0.6}, {x0, 3}, {y0, 2}, {t, Pi/2.5}, {x1, 2}, {x2, 2}, {y1, 1}, {y2, 3}, {x3, 3.7}, {y4, 1}, {x5, 2}};
sol = FindRoot[equs == 0, inits]
gr3a = ContourPlot[(ell[p, p0, a, b, t] /. sol) == 0, {x, 0, L /. parms}, {y, 0, L /. parms}, ContourStyle -> Red];
square = {{0, 0}, {L, 0}, {L, L}, {0, L}, {0, 0}} /. parms;
gr0 = ListLinePlot[square];
gr1 = Graphics[Circle[{r1, r1} /. parms, r1 /. parms]];
gr2 = Graphics[Circle[{r2, L - r2} /. parms, r2 /. parms]];
gr3 = ContourPlot[(ell[p, p0, a, b, t] /. sol) == 0, {x, 0, L /. parms}, {y, 0, L /. parms}, ContourStyle -> Red];
Show[gr0, gr3, gr1, gr2, AspectRatio -> 1, Axes -> False]
Show[gr0, gr3a, gr1, gr2, AspectRatio -> 1, Axes -> False]

enter image description here

$\endgroup$
2
$\begingroup$

The square vertices are $A(0,0), B(S, 0), C(S,S), D(0, S)$ where $S$ is known. The first circle has a radius given in terms of the the side length $S$. Let's call this radius $r_1$, then we are given

$ r_1 = \alpha S $

For some known $\alpha$. The reason I introduced $\alpha$ is to keep track of the relative ratio between $r_1$ and $S$.

So $r_1$ is known. If $r_2$ is the radius of the upper left circle, then its center is $ (r_2, S - r_2) $. From tangency with the lower circle, we know that

$ (r_1 - r_2)^2 + (S - r_2 - r_1)^2 = (r_1 + r_2)^2 $

So that

$ - 2 r_1 r_2 + S^2 + r_2^2 + r_1^2 - 2 S r_1 - 2 S r_2 = 0 $

$ r_2^2 - 2 r_2 \left( S + r_1 \right) + \left( S - r_1 \right)^2 = 0 $

The discriminant is

$ 4 \left( S + r_1 \right)^2 - 4 \left( S - r_1 \right)^2 = 16 S r_1 $

Hence, the solution of this quadratic equation is

$ r_2 = \dfrac{1}{2} \left( 2 (S + r_1) \pm 4 \sqrt{ S r_1 } \right) $

which simplifies to,

$ r_2 = S + r_1 - 2 \sqrt{ S r_1 } = (\sqrt{S} - \sqrt{r_1})^2 $

Next, we we want to identify the ellipse that is tangent to the top, right, and bottom sides as well as the two circles on the left. Let the center of this ellipse be $G = (G_x, G_y)$, then necessarily $G_y = \dfrac{S}{2}$. The equation of this ellipse is

$ (r - G)^T Q (r - G) = 1 $

The gradient vector of the ellipse is given by

$ \nabla = 2 Q (r - G) $

At the right tangency point $P_1$, we have

$ Q (P_1 - G) = k \mathbf{i} $

where $k \gt 0 $ is some positive constant, and $\mathbf{i} = [1, 0]^T $.

Solving for $P_1 - G$ , we obtain

$ P_1 - G = k Q^{-1} \mathbf{i} $

Substituting this into the ellipse equation above, gives

$ k = \dfrac{1}{\sqrt{ \mathbf{i}^T Q^{-1} \mathbf{i} } } $

Pre-multiplying the above expression for $P_1 - G$ by $\mathbf{i}^T $ gives

$ \mathbf{i}^T {P_1} - \mathbf{i}^T G = k \ \mathbf{i}^T Q^{-1} \mathbf{i} = \sqrt{ \mathbf{i}^T Q^{-1} \mathbf{i} } $

Since $\mathbf{i}^T {P_1} = S $ and $\mathbf{i}^T G = G_x $ , then we now have

$ ( S - G_x )^2 = Q^{-1}_{11} \tag{1} $

Now considering the top the tangency point $P_2$, we have

$ Q (P_2 - G) = k' \ \mathbf{j} $

where $k' \gt 0 $. Similar to the above analysis, we end up with

$ \mathbf{j}^T P_2 - \mathbf{j}^T G = \sqrt{ \mathbf{j}^T Q^{-1} \mathbf{j} } $

But $ \mathbf{j}^T P_2 = S $ and $ \mathbf{j}^T G = G_y = \dfrac{S}{2} $; therefore,

$ \left( \dfrac{S}{2} \right)^2 = Q^{-1}_{22} \tag{2}$

Turning now to tangency with the two circles. Introduce the tangency point $T_1$ with the lower circle and $T_2$ with the top circle. Parametrically, we have

$T_1 = (r_1, r_1) + r_1 (\cos t_1, \sin t_1 ) $

$T_2 = (r_2, S - r_2) + r_2 (\cos t_2, \sin t_2) $

The first requirement for both $T_1$ and $T_2$ is that they lie on the ellipse, therefore, we immediately have two additional equations, namely,

$ (T_1 - G)^T Q (T_1 - G) = 1 \tag{3} $

$ (T_2 - G)^T Q (T_2 - G) = 1 \tag{4} $

Secondly, the gradients of the circle and the ellipse at $T_1, T_2$ have to be parallel, and this gives the final two equations

$ (T_1 - (r_1, r_1) ) \times Q (T_1 - G) = \mathbf{0} \tag{5} $

$ (T_2 - (S - r_2, r_2) \times Q (T_2 - G) = \mathbf{0} \tag{6} $

These are the $(6)$ equations that govern the six unknowns: $t_1, t_2, a, b, \theta, G_x $. Note that

$ Q = R D R^T $

where $D = \begin{bmatrix} \dfrac{1}{a^2} && 0 \\ 0 && \dfrac{1}{b^2} \end{bmatrix} $ and $ R = \begin{bmatrix} \cos \theta && - \sin \theta \\ \sin \theta && \cos \theta \end{bmatrix} $

These $6$ equations can be solved numerically using the Newton-Raphson multivariate method. The Newton-Raphson recurrence converged to a solution within few iterations. The number of iterations necessary for convergence depends on the initial guess of the unknowns. The figure attached to the question was obtained for $r_1 = 0.29 S $.

$\endgroup$
4
  • $\begingroup$ +1. Informative! I don't think I give enough attention to the matrix forms of conic equations. :) ... Did you have this solution in your pocket when you asked your question? If so, then you should have posted it right away, so that someone else wouldn't spend time and effort inadvertently duplicating your work. (I personally found the question interesting to play with, but I might not have bothered composing, formatting, illustrating, and tabulating a comprehensive answer if I'd known you already had one. (No harm done. I had fun.)) ... Cheers! $\endgroup$
    – Blue
    Commented Jun 2 at 10:49
  • $\begingroup$ Yes. Actually I did have the solution that I wrote already working. But was wondering if there are other methods/procedures to attack the problem that are unknown to me. Your answer (+1) provided such an alternative view. $\endgroup$
    – Quadrics
    Commented Jun 2 at 10:59
  • $\begingroup$ "[I] was wondering if there are other methods/procedures to attack the problem" ... That underscores my point about duplicated effort. It's no fun to put time into posting a comprehensive answer only to have the asker respond "That's how I did it; I wanted to see a different approach." Someone can't guess what counts as an "other" method/procedure unless they can see the one you know. Besides, it's always a good idea to post as much as you know about a problem, as it could provide a jumping-off point for alternative approaches, without everyone having to start from scratch. ... Cheers! $\endgroup$
    – Blue
    Commented Jun 2 at 12:02
  • $\begingroup$ I did put my thoughts about my attempt in the OP. $\endgroup$
    – Quadrics
    Commented Jun 2 at 13:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .