Least Squares Plane

Given set of 3D points, we often want to know whether these points lie on a certain plane in terms of a specified tolerance. If so, we may further need to know the definition of the plane such that we can project these points onto the plane.

A plane in 3D space may be defined by
Ax+By+Cz+D=0.
where A, B, and C furnish the components of the normal of the plane. In other words, the plane normal is given by N=(A,B,C). Assume the above plane is normalized (i.e., N is a unit vector). Then, the distance between a point pi=(xi,yi,zi) and the plane is given by
di = Axi+Byi+Czi-D.
For a given set of points pi (i=1,2,3... n), our task is to find a plane such that the distance between pi and the plane is minimized in some fashion. After having obtained the definition of the plane, we may compute the actual distance between pi and the plane with i=0,1,2,...,n and compare it with the given tolerance to determine whether all the points are on the plane.

Since di may be positive or negative, an appropriate minimization of di is the least squares approximation, which is equivalent to finding A, B, C, and D such that
f(A,B,C,D)= n
å
i=1 
di2= n
å
i=1 
(Axi+Byi+Czi-D)2
is minimized. Accordingly, we want to solve the following system of liner equations:

       [(df)/(dA)]=2åi=1n[Axi+Byi+Czi-D]xi=0

       [(df)/(dB)]=2åi=1n[Axi+Byi+Czi-D]yi=0

       [(df)/(dC)]=2åi=1n[Axi+Byi+Czi-D]zi=0

       [(df)/(dD)]=2åi=1n[Axi+Byi+Czi-D]=0

From df/dD=0, we have D=Axc+Byc+Czc where
xc=
n
å
i=0 
xi

n
,    yc=
n
å
i=0 
yi

n
,    zc=
n
å
i=0 
zi

n
.
The above relation shows that the least squares plane passes through the centroid (or the center of mass) of the points.

In order to simplify computation, we subtract the center of mass, (xc,yc,zc), from each point. In this case, the least squares plane will pass through the origin. Accordingly, D=0 and f = åi=1n[A(xi-xc)+B(yi-yc)+C(zi-zc)]. Therefore, we have

       [(df)/(dA)]=åi=1n[A(xi-xc)2+B(yi-yc)(xi-xc)+ C(zi-zc)(xi-xc)]=0

       [(df)/(dB)]=åi=1n[A(xi-xc)(yi-yc)+B(yi-yc)2+ C(zi-zc)(yi-yc)]=0

       [(df)/(dC)]=åi=1n[A(xi-xc)(zi-zc)+B(yi-yc)(zi-zc)+ C(zi-zc)2]=0

Let

       a00=åi=1n(xi-xc)2,

       a11=åi=1n(yi-yc)2,

       a22=åi=1n(zi-zc)2,

       a01=a10=åi=1n(xi-xc)(yi-yc),

       a02=a20=åi=1n(xi-xc)(zi-zc), and

       a12=a21=åi=1n(yi-yc)(zi-zc).

Then, the desired A, B, and C are obtained by solving
æ
ç
ç
ç
è
a00
a01
a02
a10
a11
a12
a20
a21
a22
ö
÷
÷
÷
ø
æ
ç
ç
ç
è
A
B
C
ö
÷
÷
÷
ø
=0.
The above system has a trivial solution A=B=C=0. For a non-trivial solution, we may require A2+B2+D2=1. With this constraint, it is readily seen that solution to the above equation is an eigenvalue problem (Computation of three eigenvalues and eignevectors is well documented in any linear algebra book and hence not discussed here). The three eignevectors are mutually orthogonal and define three sets of A, B, and C. These three sets represent the best, intermediate, and worst planes. In our case, we want to choose the eignevector associated with the smallest eignevalue (Note: The eignevalue is the sum of squared distances). If all three eignevalues are the same, then the given points are either degenerate or symmetric.

RETURN