Search code examples
pythonscikit-learnpca

using PCA to find the major axis of a 3d pointcloud of a mesh


Hi am trying to calculate a vector of the major axis through a 3d mesh in python (using open3d library to interact with the mesh). I have turned the mesh into a pointcloud using a poisson distribution (1000 points in a numpy array) and have thought about using scikit learn and its PCA functionality to try and get the value of this vector.

From googling around I think I'm on the right tract but have little idea about how to use the PCA function to get what I want.

I think I need to extract the largest eigenvalue from the pointcloud and its accompanying eigenvector - which should hopefully be what I'm looking for.

Have little idea how to do this as I am completely unfamiliar with scikit learn. Any help please?


Solution

  • Have found a solution using trimesh library:

    used the principal_inertia_vectors function to find the 3 largest eigenvalues and corresponding eigenvectors. The eigen vectors correspond to the 3 axes of the mesh.

    This functions runs straight off the mesh therefore not requiring conversion to a point cloud.