# Fit a plane in data set which passes through maximum number of points in this data set and disregards noise

I have a set of 3D points (cartesian coordinates). I want to find the best fit plane. As I understand, there are many algorithms to get a best fit plane. One of them is this by Dan Couture.

This fits a plane by calculating the least distances to each point. This is what I was using all the while.

Now, I want to fit this plane such that noise is ignored. I.e., if the normal distance from the point to this plane is beyond a certain value, I want to ignore it. This way all the noisy points in my data set are disregarded to fit plane. How can this be done?

When I say "plane fit", it means I want the equation of that plane.

Suppose than the equation of the plane be $$Ax+By+Cz+D=0$$ the distance of a point $(x_i,y_i,z_i)$ to the plane is given by $$d_i=\pm \frac{Ax_i+By_i+Cz_i+D}{\sqrt{A^2+B^2+C^2}}$$ So, to me, by analogy with least-square fit, the idea is to minimize $$\Phi(A,B,C,D)=\sum_{i=1}^n d_i^2$$ with respect to parameters $A,B,C,D$. I should say that this looks as a trivial minimization problem.
When the problem is solved, you know all the $d_i$'s. If you want to discard those for which $|d_i| \gt \Delta$, just remove the points from the data set and repeat the optimization.