I am busy working on a point cloud simplification algorithm.
Below is the code to calculate the normal to a neighbourhood of points . I have used principal component analysis.
I would like to know if i have computed the normals and curvature of point correctly?
I am aware the normals are unorientated and my next step is to create a graph using network x (with edges from each point to its nearest neighbours), weighting each edge with 1-|ni*ni+1| . Then create a minimum spanning tree and then initiate depth searching by starting at the highest z value point and flip orientation of ni+1 if ni*ni+1=-1 . I will be using networkx , so that i can achieve a global consistent orientation. Is this the best way to go about it?
Thanks
import numpy as np
#NEIGHBOURING POINTS
XYZ = np.array([[-0.0369122 , 0.12751199 , 0.00276757],
[-0.0398624 , 0.128204 , 0.00299348],
[-0.0328896 , 0.12613 , 0.00300653],
[-0.0396095 , 0.12667701 ,-0.00334699],
[-0.0331765, 0.12681 , 0.00839958],
[-0.0400911 ,0.128618 , 0.00909496],
[-0.0328901 , 0.124518 , -0.00282055]])
#GET THE COVARIANCE MATRIX
average=sum(XYZ)/XYZ.shape[0]
b = np.transpose(XYZ - average)
cov=np.cov(b)
#GET EIGEN VALUES AND EIGEN VEECTORS
e_val,e_vect = np.linalg.eigh(cov)
print e_val
print 'eigenvectors'
print e_vect
#DIAGONLIZE EIGENVALUES
print 'eigenvalues'
e_val_d = np.diag(e_val)
print e_val_d
#FIND MIN EIGEN VALUE
h = np.rank(min(e_val))
#FIND NORMAL
norm = e_vect[:,h]
print 'normal'
print norm
#CALCULATE CURVATURE
curvature = e_val[0]/(e_val[0]+e_val[1]+e_val[2])
print 'curvature'
print curvature