Transforming sphere equation to least squares

60 Views Asked by At

The equation of a sphere is:

$$(x-a)^2 + (y-b)^2 + (z-c)^2 = r2$$

I would like to solve a system of these equations, with $n$ spheres and $3$ unknowns $(x, y, z)$.

For least squares, generally people use the formula

$Ax = b$

However, with the equation of a sphere, i think it looks more like

$A-x = b$

Could someone help me rewrite the sphere equations into

$Ax = b$

if this is possible, and if not explain to me why its not possible? I'm new to linear algebra.

1

There are 1 best solutions below

6
On BEST ANSWER

In a least square sense, the problem is a bit more difficult than it looks since the distance from a point to the sphere is $$d=\sqrt{(x-a)^2 + (y-b)^2 + (z-c)^2}- r$$ So, what you need is to minimize $$\Phi(x,y,z)=\sum_{i=1}^n \left(\sqrt{(x-a_i)^2 + (y-b_i)^2 + (z-c_i)^2}- r_i\right)^2$$ which is not very simple (hightly nonlinear) and you need good initial estimates.

You considered to minimize $$\Psi(x,y,z)=\sum_{i=1}^n \left((x-a_i)^2 + (y-b_i)^2 + (z-c_i)^2- r_i^2\right)^2$$ which, again, is not so easy.

So, consider each equation $$f_i=(x-a_i)^2 + (y-b_i)^2 + (z-c_i)^2- r_i^2$$ and build the $\color{red}{\frac{n(n-1)}2}$ equations $(f_i-f_j)$, $i$ going from $1$ to $(n-1)$ and $j$ from $i$ to $n$.

Expanding, each of these equations will write $$2(a_j-a_i)x+2(b_j-b_i)y+2(c_j-c_i)z=(a_j^2+b_j^2+c_j^2-r_j^2)-(a_i^2+b_i^2+c_i^2-r_i^2)$$ which is now a linear system (easy to solve).

This gives you the guesses $(x_0,y_0,z_0)$ to start with for the minimization of $\Phi(x,y,z)$. If there is not too much noise in the data, you could even use Newton-Raphson method with numerical derivatives.

$$\frac {\partial \Phi(x,y,z)}{\partial x}=2\sum_{i=1}^n\frac{(x-a_i)\left(\sqrt{(x-a_i)^2 + (y-b_i)^2 + (z-c_i)^2}- r_i\right) }{\sqrt{(x-a_i)^2 + (y-b_i)^2 + (z-c_i)^2}}$$ $$\frac {\partial \Phi(x,y,z)}{\partial y}=2\sum_{i=1}^n\frac{(y-b_i)\left(\sqrt{(x-a_i)^2 + (y-b_i)^2 + (z-c_i)^2}- r_i\right) }{\sqrt{(x-a_i)^2 + (y-b_i)^2 + (z-c_i)^2}}$$ $$\frac {\partial \Phi(x,y,z)}{\partial z}=2\sum_{i=1}^n\frac{(z-c_i)\left(\sqrt{(x-a_i)^2 + (y-b_i)^2 + (z-c_i)^2}- r_i\right) }{\sqrt{(x-a_i)^2 + (y-b_i)^2 + (z-c_i)^2}}$$