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

Consider that V*U = 0 yields the equation of the plane. Then consider that V'*V*U = V'*0 = 0 can be interpreted as A*U = 0*U which by definition makes U the eigenvector associated with the eigenvalue 0 of A.

-
Although it may take some work to explain to OP how this answer relates to the quote from the other forum. –  Gerry Myerson Sep 8 '12 at 6:33
It still doesn't answer my basic question that why does the eigenvector corresponding to least eigenvalue of matrix A gives the coefficient of the least squared plane and why is there the needs to obtain the parameter D, in the equation of the plane, using the mean points at the end. –  John Smith Sep 8 '12 at 15:05
See above edit. –  Tpofofn Sep 8 '12 at 18:43
Thanks Tpofofn.. I think I am almost there but I need two more clarifications.. 1. How can you say V*U=0 is the equation of the least squared plane? and 2. Why is there a need to evaluate coefficient D in the equation of plane at the end? Any thoughts? –  John Smith Sep 8 '12 at 19:42
@JohnSmith, 1. Since the mean has been removed the plane passes through the origin. Then the equation of the plane is given by ax + by + c*z = 0. Let U = [a b c]' and v = [x y z]'. Then the equation of the plane becomes v'*U = 0. Note that v is any point in the plane and U is perpendicular to the plane (by definition). 2. in the above decomposition D represents the eigenvalues of the matrix A. IF the points are not perfectly co-planar, then generally v_i'*U != 0 for all v_i. In other words there are small porions of v_i that project onto U. –  Tpofofn Sep 8 '12 at 20:14