[Numpy-discussion] 3d plane to point cloud fitting using SVD

Peter Schmidtke pschmidtke at mmb.pcb.ub.es
Wed May 5 04:02:38 EDT 2010


Dear Numpy Users,

I want to fit a 3d plane into a 3d point cloud and I saw that one could use
svd for this purpose. So as I am very fond of numpy I saw that svd was
implementented in the linalg module. 

Currently I have a numpy array called xyz with n lines (number of points)
and 3 columns (x,y,z).
I calculated the centroid as :
   xyz0=npy.mean(xyz, axis=0)  #calculate the centroid
Next I shift the centroid of the point cloud to the origin with.
    M=xyz-xyz0

next I saw by matlab analogy
(http://www.mathworks.co.jp/matlabcentral/newsreader/view_thread/262996)
that I can write this :

u,s,vh=numpy.linalg.linalg.svd(M)

Then in the matlab analog they use the last column of vh to get the a,b,c
coefficients for the equation
a,b,c=vh[:, -1] in numpy

The problem is that the equation ax+by+cz=0 does not represent the plan
through my point cloud at all. 
What am I doing wrong, how can I get the a,b and c coefficients?

Thanks in advance.

-- 

Peter Schmidtke

----------------------
PhD Student at the Molecular Modeling and Bioinformatics Group
Dep. Physical Chemistry
Faculty of Pharmacy
University of Barcelona




More information about the NumPy-Discussion mailing list