How to find the intersection of three spheres (full solutions)?

The three equations of spheres are given

$(x-x_{1})^2+(y-y_{1})^2+(z-z_{1})^2=a^2$

$(x-x_{2})^2+(y-y_{2})^2+(z-z_{2})^2=b^2$

$(x-x_{3})^2+(y-y_{3})^2+(z-z_{3})^2=c^2$

How do I find $(x,y,z)$ analytically?


This is probably not the simplest possible analytic answer.

First, I'm going to choose some easier variables to use. Let $V$ ($V$ is your x,y,z) be the axis variables and $C$ be the centers of 3 spheres:

$$(V_{1} - C_{1,1})^2 + (V_{2} - C_{1,2})^2 + (V_{3} - C_{1,3})^2 = r_1^2 \tag {Sphere1 of V}$$ $$(V_{1} - C_{2,1})^2 + (V_{2} - C_{2,2})^2 + (V_{3} - C_{2,3})^2 = r_2^2 \tag {Sphere2 of V}$$ $$(V_{1} - C_{3,1})^2 + (V_{2} - C_{3,2})^2 + (V_{3} - C_{3,3})^2 = r_3^2 \tag {Sphere3 of V}$$


To begin solving this, first find the intersection of 2 spheres.

First realize that the intersection of 2 spheres is a circle. It could be a circle with real, zero, or complex radius, but it is still a circle. So first we will solve the intersection of 2 spheres analytically.

Choose an affine change of basis $V \rightarrow W$ with new axises $E$ and origin $\Omega$ that will result in the spheres being placed such that:

1) Sphere 1 and 2's centers are on the new $W_1$ axis.
2) The circle that results from their intersection is on the $W_1 = 0$ plane (by choice of location of the new origin).
By only choosing the first basis vector and the origin, these 2 conditions are enough to solve the sphere-sphere problem, but for convenience later we also want:
3) Sphere 3's center is located on the new y axis.
The final condition defines where other 2 basis vectors will be.

The x-axis will pass through the center of the spheres: $$E_1 = norm(C_2 - C_1)$$ The origin is also on this axis: $$\Omega = (C_2 - C_1)\cdot n_1 + C_1$$ The new Y axis passes through sphere 3: $$E_2 = norm(C_3 - \Omega)$$ $$E_3 = E_1 \times E_2$$

This defines an affine change of basis : $$V = W \begin{bmatrix} E_1 \\ E_2 \\ E_3 \end{bmatrix} + \Omega \tag{Transform 1}$$

Let $n$ be the distance between $C_1$ and $C_2$, where $n_1$ is the distance from the relocated Sphere 1 from the new origin and $n_2$ is the distance of the new relocated Sphere 2 from the origin. Last thing before translating the spheres, solve for $n_1$ and $n_2$, (and remember $r_x$, the radius of the circle-of-intersection, because we will definitely need it later ) :

$$n = |C_2 - C_1|$$ $$n = n_1 + n_2$$ $$r_1^2 - n_1^2 = r_2^2 - n_2^2 = r_X^2$$

Solves to

$$n_1 = \frac {n^2 - r_2^2 + r_1^2} {2 n} $$ $$n_2 = \frac {n^2 + r_2^2 - r_1^2} {2 n} $$ $$r_x^2 = - \frac {\left(n^2 - (r_1 - r_2)^2\right)\left(n^2 - (r_1 + r_2)^2\right)} {4 n^2} $$

Now when we put Sphere 1, Sphere 2, and Sphere 3 through Transform 1 we get:

$$(W_{1} + n_1)^2 + W_2^2 + W_3^2 = r_1^2 \tag {Sphere1 of W}$$ $$(W_{1} - n_2)^2 + W_2^2 + W_3^2 = r_2^2 \tag {Sphere2 of W}$$ $$W_{1}^2 + (W_2 - n_3)^2 + W_3^2 = r_3^2 \tag {Sphere3 of W}$$

Note that we know $n_3 = |C_3 - \Omega|$ because of how $E_2$ was chosen to be defined. By choice of transform and values of $n$, Sphere 1 and Sphere 2 has the solution: $$W_1 = 0$$ $$W_2^2 + W_2^2 = r_x^2$$

Which solves the sphere-sphere intersection part. Note that $r_x^2$ can be negative, which is a complex circle.


Now we are left with solving a circle circle intersection. This is really a simpler case of the same technique from above.

$$W_2^2 + W_2^2 = r_x^2 \tag {Circle 1}$$ $$(W_2 - n_3)^2 + W_3^2 = r_3^2 \tag {Circle2 was Sphere3}$$

Chose transform $U = W - \begin{bmatrix} 0 & m_1 & 0\end{bmatrix}$.

$$(U_2 + m_1)^2 + U_3^2 = r_x^2 \tag {Circle 1 in U}$$ $$(U_2 - m_2)^2 + U_3^2 = r_3^2 \tag {Circle2 in U}$$

If we choose :

$$m_1 + m_2 = m = n_3$$ $$r_x^2 - m_1 = r_3^2 - m_2^2 = r_F^2$$

These conditions solve to :

$$m_1 = \frac {m^2 - r_X^2 + r_3^2} {2 m} $$ $$m_2 = \frac {m^2 + r_X^2 - r_3^2} {2 m} $$ $$r_F^2 = - \frac {\left(m^2 - (r_3 - r_X)^2\right)\left(m^2 - (r_3 + r_X)^2\right)} {4 m^2} $$

Then Circle 1 and Circle 2 solve to : $$U_2 = 0$$ $$U_3^2 = r_F^2$$

Note that $r_F^2$ can be complex in the case of a non-overlapping system.


Going from $U$ to $V$, just backsubstitute the expressions:

$$ U = \begin{bmatrix} 0 & 0 & \sqrt{r_F^2}\end{bmatrix} \tag {This has 2 complex values}$$ $$ W = U + \begin{bmatrix} 0 & m_1 & 0 \end{bmatrix}$$ $$V = W \begin{bmatrix} E_1 \\ E_2 \\ E_3 \end{bmatrix} + \Omega \tag{Transform 1}$$

Applying the formulas for intermediate variables along the way. It gets an analytical solution, but not a short or pretty one.


To get you started:

  1. $(x-x_{1})^2+(y-y_{1})^2+(z-z_{1})^2=a^2$
  2. $(x-x_{2})^2+(y-y_{2})^2+(z-z_{2})^2=b^2$
  3. $(x-x_{3})^2+(y-y_{3})^2+(z-z_{3})^2=c^2$

Use 1.+2.

  1. $x^2-2xx_1+x_1^2+y^2-2yy_1+y_1^1+z_1^2-2zz_1+z_1^2=a^2$
  2. $x^2-2xx_2+x_2^2+y^2-2yy_2+y_2^2+z_2^2-2zz_2+z_2^2=b^2$

Now 1. - 2.

$$ -2xx_1+2xx_2+x_1^2-x_2^2-2yy_1+2yy_2+2zz_1-2zz_2+y_1^2-y_2^2+z_1^2-z_2^2=a^2-b^2$$

Simplify

$$2x(x_2-x_1)+2y(y_2-y_1)+2z(z_2-z_1)+(x_1^2-x_2^2+y_1^2-y_2^2+z_1^2-z_2^2)=a^2-b^2$$

$$\Leftrightarrow x=\dfrac{a^2-b^2-2y(y_2-y_1)-2z(z_2-z_1)-(x_1^2-x_2^2+y_1^2-y_2^2+z_1^2-z_2^2)}{2(x_2-x_1)}$$

Now put $x$ into 1. or 2. and solve the quadratic for $y$. Use at last Ari's hint.