Best Fit Line with 3d Points Okay, I need to develop an alorithm to take a collection of 3d points with x,y,and z components and find a line of best fit.  I found a commonly referenced item from Geometric Tools but there doesn't seem to be a lot of information to get someone not already familiar with the method going.  Does anyone know of an alorithm to accomplish this?  Or can someone help me work the Geometric Tools approach out through an example so that I can figure it out from there?  Any help would be greatly appreciated.

We start with a sequence of $m$ measurements $\left\{ x_{k}, y_{k}, z_{k}, f_{k} \right\}_{k=1}^{m}$, and the trial function
$$
 f(x,y,z) = a_{0} + a_{1} x + a_{2} y + a_{3} z.
$$
The linear system is
$$
\begin{align}
  \mathbf{A} a &= f \\
%
\left[ \begin{array}{cccc}
  1 & x_{1} & y_{1} & z_{1} \\
  1 & x_{2} & y_{2} & z_{2} \\
  \vdots & \vdots & \vdots & \vdots \\
  1 & x_{m} & y_{m} & z_{m} 
\end{array} \right]
%
\left[ \begin{array}{cccc}
  a_{0} \\
  a_{1} \\
  a_{2} \\
  a_{3} 
\end{array} \right]
%
&=
%
\left[ \begin{array}{cccc}
  f_{1} \\
  f_{2} \\
  \vdots \\
  f_{m} 
\end{array} \right].
%
\end{align}
$$
The normal equations are 
$$
\begin{align}
  \mathbf{A}^{*} \mathbf{A} a &= \mathbf{A}^{*} y \\
%
\left[ \begin{array}{cccc}
  \mathbf{1} \cdot \mathbf{1} & \mathbf{1} \cdot x & \mathbf{1} \cdot y & \mathbf{1} \cdot z \\
  x \cdot \mathbf{1} & x \cdot x & x \cdot y & x \cdot z \\
  y \cdot \mathbf{1} & y \cdot x & y \cdot y & y \cdot z \\
  z \cdot \mathbf{1} & z \cdot x & z \cdot y & z \cdot z \\
\end{array} \right]
%
\left[ \begin{array}{cccc}
  a_{0} \\
  a_{1} \\
  a_{2} \\
  a_{3} 
\end{array} \right]
%
&=
%
\left[ \begin{array}{cccc}
  \mathbf{1} \cdot f \\
  x \cdot f \\
  y \cdot f \\
  z \cdot f 
\end{array} \right]
%
\end{align}
$$
The solution is
$$
\begin{align}
  a_{LS} &= \left( \mathbf{A}^{*} \mathbf{A} \right)^{-1} \mathbf{A}^{*} y \\
%
\left[ \begin{array}{cccc}
  a_{0} \\
  a_{1} \\
  a_{2} \\
  a_{3} 
\end{array} \right]
%
&=
%
\left[ \begin{array}{cccc}
  \mathbf{1} \cdot \mathbf{1} & \mathbf{1} \cdot x & \mathbf{1} \cdot y & \mathbf{1} \cdot z \\
  x \cdot \mathbf{1} & x \cdot x & x \cdot y & x \cdot z \\
  y \cdot \mathbf{1} & y \cdot x & y \cdot y & y \cdot z \\
  z \cdot \mathbf{1} & z \cdot x & z \cdot y & z \cdot z \\
\end{array} \right]^{-1}
%
\left[ \begin{array}{cccc}
  \mathbf{1} \cdot f \\
  x \cdot f \\
  y \cdot f \\
  z \cdot f 
\end{array} \right]
%
\end{align}
$$
