5

In the context of determining pore volumes in adsorbing materials, I'm trying to find the pores that a gas molecule can go through. To do so, I have so solve a complex geometry/linear algebra problem. Here is a 2D representation of the problem, involving 4 circles instead of 5 spheres in 3D.

There are three circles with center coordinates u, v, and k with a radius r1, r2, r3, and I would like to know the radius of the circle, rg, that is inside and touching the three circles. The enclosed circle is located at a coordinate g. So you can imagine three atoms of a material, and I'd like to see the maximum size of an atom that can pass through the hole. Though I am describing this problem in 2D for simplicity, I ultimately want the solution in 3D with 5 spheres, where a sphere is inside and touching the 4 spheres. I'm trying to solve this for my research, but no luck so far.

myster
  • 73

1 Answers1

3

Given the four known spheres of centers $C_1, C_2, C_3, C_4 $ and radii $r_1, r_2, r_3, r_4 $, we want to determine $C$ and $R \gt 0$ such that

$ R + r_1 = \| C C_1 \| = \sqrt{ (C - C_1)^T (C - C_1) }$

$ R + r_2 = \| C C_2 \| =\sqrt{ (C - C_2)^T (C - C_2) }$

$ R + r_3 = \| C C_3 \| =\sqrt{ (C - C_3)^T (C - C_3) }$

$ R + r_4 = \| C C_4 \| = \sqrt{ (C - C_4)^T (C - C_4) }$

Square each of the above four equations and take the differences between the first and the second, the first and the third, the first and the fourth, we get the following three equations,

$ 2 R (r_1 - r_2) + r_1^2 - r_2^2 = - 2 C^T (C_1 - C_2) + C_1^T C_1 - C_2^T C_2 $

$ 2 R (r_1 - r_3) + r_1^2 - r_3^2 = - 2 C^T (C_1 - C_3) + C_1^T C_1 - C_3^T C_3 $

$ 2 R (r_1 - r_4) + r_1^2 - r_4^2 = - 2 C^T (C_1 - C_4) + C_1^T C_1 - C_4^T C_4 $

which are $3$ linear equations in $4$ unknowns. Feeding these to a linear equation solver, gives

$ X = V_0 + t V_1 $

where $X = [ C_x, C_y, C_z, R]^T$ and $V_0, V_1$ are known vectors, and $t \in \mathbb{R} $

To find $t$, substitute this expression into the equation

$ (R + r_1)^2 = (C - C_1)^T (C - C_1) $

and solve for $t$, this will give two values of $t$, take the one that gives a positive value for $R$.

EDIT:

A slightly different way to determine $R$ is as follows:

Let $C = C_1 + v $ where $v $ is a vector, $v \in \mathbb{R}^3$, the above equations become

$ (R + r_1)^2 = \| C C_1 \|^2 = (C - C_1)^T (C - C_1) = v^T v \hspace{30pt} (*) $

$\begin{equation} \begin{split} (R + r_2)^2 &= \| C C_2 \|^2 = (C - C_2)^T (C - C_2) \\ &= (C_1 - C_2 + v)^T (C_1 - C_2 + v) \\&= \| C1 - C_2 \|^2 + 2 (C_1 - C_2)^T v + v^T v \end{split}\end{equation}$

Similarly,

$ (R + r_3)^2 = \| C C_3 \|^2 =\| C1 - C_3 \|^2 + 2 (C_1 - C_3)^T v + v^T v $

$ (R + r_4)^2 = \| C C_4 \|^2 = \| C1 - C_4 \|^2 + 2 (C_1 - C_4)^T v + v^T v $

Substituting $(*)$ in the above three equations, and re-arranging,

$ 2 R (r_2 - r_1) + r_2^2 - r_1^2 = \| C1 - C_2 \|^2 + 2 (C_1 - C_2)^T v $

$ 2 R (r_3 - r_1) + r_3^2 - r_1^2 = \| C1 - C_3 \|^2 + 2 (C_1 - C_3)^T v $

$ 2 R (r_4 - r_1) + r_4^2 - r_1^2 = \| C1 - C_4 \|^2 + 2 (C_1 - C_4)^T v $

These three equations can be written in matrix-vector form as follows:

Let $A = \begin{bmatrix} (C_1 - C_2)^T \\ (C_1 - C_3)^T \\ (C_1 - C_4)^T \end{bmatrix} $

and let $ b = \begin{bmatrix} r_2 - r_1 \\ r_3 - r_1 \\ r_4 - r_1 \end{bmatrix} $

and let $ c = \dfrac{1}{2} \begin{bmatrix} r_2^2 - r_1^2 - \| C_1 - C_2 \|^2 \\ r_3^2 - r_1^2 - \| C_1 - C_3 \|^2\\ r_4^2 - r_1^2 - \| C_1 - C_4 \|^2 \end{bmatrix} $

Then

$ A v = R b + c $

Hence, by pre-multiplying by the inverse of $A$

$ v = R A^{-1} b + A^{-1} c $

Now substitute this into the very first equation,

$ R^2 + 2 R r_1 + r_1^2 = v^T v = R^2 \bigg(b^T A^{-T} A^{-1} b\bigg) + 2 R \bigg( b^T A^{-T} A^{-1} c \bigg) + \bigg(c^T A^{-T} A^{-1} c\bigg) $

And this is a single quadratic equation in $R$ which can be solve to produce two solutions, out of which we'll take the positive one.


Two-Dimensional Case:

Following the second method above, we have now three circles with centers $C_1, C_2 , C_3 \in \mathbb{R}^2 $ and radii $r_1, r_2, r_3 $.

The center of the circle we want is $C \in \mathbb{R}^2 $ and its radius is $R$.

Let $ C = C_1 + v $ where $v \in \mathbb{R}^2 $, then the equations governing the relations between the radii and the coordinates of the centers are:

$ \| C - C_1 \|^2 = v^T v = (r_1 + R)^2 $

$ \| C - C_2 \|^2 = \| C_1 - C_2 + v \|^2 = v^T v + 2 (C_1 - C_2)^T v + \| C_1 - C_2 \|^2 = (r_2 + R)^2$

Use the first equation to replace $v^T v$ with $ (r_1 + R)^2 $, then

$ (r_2 + R)^2 = (r_1 + R)^2 + 2 (C_1 - C_2)^T v + \| C_1 - C_2 \|^2$

Cancel $R^2$ on both sides of this equation. This gives us,

$ 2 R (r_2 - r_1) + r_2^2 - r_1^2 - \| C_1 - C_2 \|^2 = 2 (C_1 - C_2)^T v $

And similarly, we have

$ 2 R (r_3 - r_1) + r_3^2 - r_1^2 - \| C_1 - C_3 \|^2 = 2 (C_1 - C_3)^T v $

Now define the $2 \times 2$ matrix $A$ and vectors $b$ and $c$ as follows

$ A = \begin{bmatrix} (C_1 - C_2)^T \\ (C_1 - C_3)^T \end{bmatrix} $

$ b = \begin{bmatrix} r_2 - r_1 \\ r_3 - r_1 \end{bmatrix} $

$ c = \dfrac{1}{2} \begin{bmatrix} r_2^2 - r_1^2 - \| C_1 - C_2 \|^2 \\ r_3^2 - r_1^2 - \| C_1 - C_3 \|^2 \end{bmatrix} $

Then our two equations above becomes in matrix-vector form as follows

$ A v = R b + c $

From which

$ v = R A^{-1} b + A^{-1} c $

The first equation is

$ (R + r_1)^2 = v^T v $

Substitute $v$, this becomes

$ R^2 + 2 R r_1 + r_1^2 = R^2 \bigg( b^T A^{-T}A^{-1} b \bigg) + 2 R \bigg( b^T A^{-T} A^{-1} c \bigg) + \bigg( c^T A^{-T} A^{-1} c \bigg) $

which is a quadratic equation in $R$, and can be solved using the quadratic formula. As before, select the positive value of $R$. Once we have $R$, we can calculate $v$ and then $C$.

The figure below shows a example run of the above method.

enter image description here

Hosam Hajeer
  • 21,978
  • Thank you very much for the detailed response. How would I go about deriving a single equation to calculate R? I would like to calculate it over all sphere sets in many materials simultaneously so solving linear equation for each set could be time consuming. – myster Dec 10 '22 at 13:23
  • 1
    Yes. It is possible to get a single equation in $R$. Check my updated solution. – Hosam Hajeer Dec 10 '22 at 15:52
  • What a wizardry. I worked on this all day until the morning. Thank you for enlightening a chemist. I actually need to work on another similar case, where it's a circle enclosed in 3 circles (i.e. the simpler example discussed in the question) but in 3 dimensional coordinates. I tried to follow your derivation but with 3 equations instead, but I couldn't go further because A matrix is not square. What could I look into in this case? – myster Dec 10 '22 at 16:57
  • 1
    @myster I've added the two dimensional case. – Hosam Hajeer Dec 10 '22 at 18:19
  • Thank you very much, maybe I wasn't clear, but i meant that C_1, C_2 , C_3 consists of 3 real numbers, e.g. 2D circles in 3D space. – myster Dec 10 '22 at 18:33