# 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?

• $(x-x_{3})^2+(y-y_{3})^2+(z-z_{3})^2=a^2$ or $c^2$? Nov 11, 2013 at 9:46
• @ulead86 yes. Thanks Nov 11, 2013 at 9:47
• $S_1 \bigcap S_2 \bigcap S_3 = (S_1 \bigcap \ S_2) \bigcap (S_2 \bigcap S_3) \bigcap (S_3 \bigcap S_1)$. This is essentially intersection of three circles of (possibly) different radii in $\mathbb R^3$. This can be a circle, two distinct points, one point and null set.
– ARi
Nov 11, 2013 at 9:55
• @ulead86 in your solution when you simplified, $z$ term is missing Nov 11, 2013 at 10:15
• To state ARi's point in a different way, the intersection of 2 spheres with distinct centers is a circle with complex radius. The intersection of a circle and sphere with 2 distinct centers is 2 (not necessarily distinct) complex points. Nov 12, 2013 at 10:04

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.

• I think this system of equations probably has 3 (not necessarily independent) discriminates, and that the $r_x^2 =$ equation is one of them, and that the other 2 are the cyclic versions of that. There is probably a better solution than this which treats the variables fairly, and uses the 3 discriminates to find a better analytic solution. I'd <i>really</i> be interested if someone could present a solution that treats the variables fairly, rather than picking a few to solve for first. Nov 12, 2013 at 10:17
• Thanks.It was nicely done. But can you solve this for step by step if we have values for the constants. as an example $S_{1}=(x-3)^2+(y-5)^2+(z-9)^2=119$, $S_{2}=(x+8)^2+(y+11)^2+(z-5)^2=49$, $S_{3}=(x-1)^2+(y+2)^2+(z+3)^2=78$ Nov 13, 2013 at 6:40

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.

• when 1.+2 what has happened to $z$ terms? Nov 11, 2013 at 9:59
• how do i find $z$? Nov 11, 2013 at 10:02
• Oh sorry, I mixed sphere + circle. Give me a second. Nov 11, 2013 at 10:21
• when we put $x$ into 1. or 2 and quadratic for $y$ comes with $z$? Nov 11, 2013 at 10:35
• I think this isn't correct. I believe that subtracting (1) and (2) is not a solution preserving operation. Note how you get only 1 value for $x$, but you should get 2 possible complex values for $x$ except in the case where the centers are shared. If this approach was sound then you could also get a single value for $y$ and $z$ the same way you did for $x$, and express the solution as the sum, product, and difference of centers and radii without using square root. Nov 12, 2013 at 10:10