I need to implement the algorithm described below. Everything is fine until the eigenvalues computation. I'm completely new to them and I found a lot of very complicated paper on the net. Is it possible that this 'best-fitting plane' case requires such a complex approach? Where can I find straightforward implementation of a suitable eigenvalue solver for this?
I am also interested in different approaches to the 'best-fitting plane' problem.
Thanks.
xm = mean(x); ym = mean(y); zm = mean(z); u = x - xm; v = y - ym; w = z - zm; M = [sum(u.^2),sum(u.*v),sum(u.*w); ... sum(v.*u),sum(v.^2),sum(v.*w); ... sum(w.*u),sum(w.*v),sum(w.^2)]; [V,D] = eig(M);
Now choose the smallest eigenvalue in D. The corresponding eigenvector in V gives the coefficients, v1, v2, v3, in the best-fitting plane:
v1*(X-xm) + v2*(Y-ym) + v3*(Z-zm) = 0
By the way, if that smallest eigenvalue should turn out to be zero, that is your indication that the four points are coplanar and your plane is an exact fit.