# How can I find the intersection of four spheres?

I need to program a GPS system.

So, I get: (The distances are the distance between the target and the points) \begin{align} d_1 &= 8.246211, \\ d_2 &= 7.483315, \\ d_3 &= 3.3166249, \\ d_4 &= 9.110434. \end{align} and I know the coordinates of each point: \begin{align} p_1 &= (-2580 ,61 ,-2290), \\ p_2 &= (-2574 ,61 ,-2290), \\ p_3 &= (-2577 ,59 ,-2287), \\ p_4 &= (-2577 ,58 ,-2293). \end{align} How can I get the target coordinates?

• I guess that this gonometric problem is documented on Wikipedia. – Yves Daoust Jul 18 '17 at 20:43
• Computing the intersections of these spheres is a good starting point for your code, but I suspect that in practice you’ll almost never find an exact solution for the system of equations because of truncation and other errors in the data. Instead, you’re likely to need to find an approximate solution that minimizes some error measure instead. – amd Jul 18 '17 at 20:56
• math.stackexchange.com/questions/2332673/… – Aretino Jul 18 '17 at 21:27

Two spheres intersecate (if they do) in a circle that lies on a plane that is normal to the line joining the centers, and that crosses that line at a distance $d_{1,2}$ from point $C1$, that can be found by solving the triangle with the given sides, as shown

that is $$d_{\,1,2} = {{r_{\,1} ^{\,2} - r_{\,2} ^{\,2} + \left| {{\bf v}_{\,12} } \right|^{\,2} } \over {2\left| {{\bf v}_{\,12} } \right|}}$$ which can be either positive or negative.

The equation of the plane will then be: $$\left( {{\bf x} - {\bf c}_{\,1} } \right) \cdot {{{\bf v}_{\,12} } \over {\left| {{\bf v}_{\,12} } \right|}} = d_{\,1,2}$$ which is the same as to write \eqalign{ & \left( {x - C_{\,1,\,x} } \right) \cdot \left( {C_{\,2,\,x} - C_{\,1,\,x} } \right) + \left( {y - C_{\,1,\,y} } \right) \cdot \left( {C_{\,2,\,y} - C_{\,1,\,y} } \right) + \left( {z - C_{\,1,\,z} } \right) \cdot \left( {C_{\,2,\,z} - C_{\,1,\,z} } \right) = \cr & = {{r_{\,1} ^{\,2} - r_{\,2} ^{\,2} + \left| {{\bf v}_{\,12} } \right|^{\,2} } \over 2} \cr}

Do the same for other two couples of points, choosen in such a way that the three vectors ${{\bf v}_{\,jk} }$ be oriented as much differently as possible.

Then find the point where the three planes cross, i.e. the solution to the system of the three linear equations they define.
If the 4 spheres define a unique point, then it must be that, apart of course from measurement errors/approximations. Check the distances of the cross point from the four references.

In case of big discrepances, find some other planes and find a common solution by the method of least squares, again checking vs. the known distances.

Note

If you are writing a "real applicable" program, the error checking and handling is fundamental. Then you need to know probability theory, statistics etc. (and GPS engineering, of course) to decide which method strategy to adopt.

If you have the centers of each sphere, as well as their radii, then you are able to plug those values into the equation of a sphere: $(x-x_{coord})^2 + (y-y_{coord})^2 + (z-z_{coord})^2 = r^2$

A program will be able to assist you with solving the rather messy algebraic equation that is the result

Just as José commented on your question, people who answer aren't here to do the math for you. So if you understand what I'm saying then you'll know how to solve it.

• That is not possible for me because i need the full equation to be able to program it :S – Ruben Ferreira Jul 18 '17 at 20:24

This is a spheres intersection problem. The distances are the radii. When the intersection of four spheres is not empty, the general case is so that the intersection is not reduced to an unique point. The enumeration of the topological situations and the equations are given in my book chapter published by Springer in 2013 (doi:10.1007/978-1-4614-5128-0_4 ; a free preprint is available at https://hal.archives-ouvertes.fr/hal-01955983). You may have up to four points delimiting the domain of the intersection. It must be checked if these four points coincide or not. Using the freeware ASV (http://petitjeanmichel.free.fr/itoweb.petitjean.freeware.html), I computed the volume and the surface of the intersection of your 4 spheres: the volume is larger than 147 units and the surface is larger than 135 units. Compared to the individual spheres surfaces and volumes, these values show that the domain of the intersection is significant: it cannot be neglected. So, by far, the domain does not reduce to an unique point.