# Prove with MATLAB whether a set of n points is coplanar

I need to find a way to prove if a set of n points are coplanar. I found this elegant way on one of the MATLAB forums but I don't understand the proof. Can someone help me understand the proof please?

" The most insightful method of solving your problem is to find the mean square orthogonal distance from the set of points to the best-fitting plane in the least squares sense. If that distance is zero, then the points are necessarily coplanar, and otherwise not.

Let x, y , and z be n x 1 column vectors of the three coordinates of the point set. Subtract from each, their respective mean values to get V, and form from it the positive definite matrix A,

V = [x-mean(x),y-mean(y),z-mean(z)];

A = (1/n)*V'*V;

Then from

[U,D] = eig(A);

select the smallest eigenvalue in the diagonal matrix D. This is the mean square orthogonal distance of the points from the best fitting plane and the corresponding eigenvector of U gives the coefficients in the equation of that plane, along with the fact that it must contain the mean point (mean(x),mean(y),mean(z))."

Here is the link from where I obtained this information.

-
anybody?? I need this urgently. I have a test tonight. –  John Smith Sep 8 '12 at 15:10

If you put all the points as columns in a matrix, the resulting matrix will have rank equal to 2 if the points are coplanar. If such a matrix is denoted as $\mathbf A$ then $\mathbf{AA}^T$ will have one eigenvalue equal to or close to 0.