Given N, 3D position vectors, I want to find the best-fit plane of those vectors.
I found a suggested answer here that said:
Calculate the average of the points (easy)
Calculate the Covariance matrix for points minus the average (thanks)
Find the two largest eigenvectors of that matrix (bwhuh?)
Calculate the Cross product of those and you get the normal of you plane (I can understand that)
So, AFAIK, this is what I think I should be doing:
average=sum(positions)/N
covariant=numpy.cov(positions-average)
eigenvectors,eigenvalues = numpy.linalg.eig(covariant)
sorted_evecs = eigenvectors[eigenvalues.argsort()]
#Take the last EV as per comment instead of crossing largest
normal = sorted_evecs[-1]
But it is plainly wrong, because the 'normal' vector that we get at the end is a 4-vector. Can anyone offer any directions / explanations please?
Sorry to mix SO and Math but thought it would be more appropriate here.