Given a set of N points in three-dimensional space, I try to find the best suitable plane using SVD and Eigen.
My algorithm:
- The centered data points around (0,0,0).
- The shape of the 3xN matrix of point coordinates.
- Calculate SVD matrices.
- Set the smallest singular vector corresponding to the smallest singular value as the normal to the plane.
- Adjust the distance from the start to the plane, as usual, with the centroid.
I cannot figure out how to use the Eigen SVD Module to find the smallest singular vector corresponding to the smallest singular value of the point coordinate matrix.
So far I have this code (steps 1, 2 and 5 of the algorithm):
Eigen::Matrix<float, 3, 1> mean = points.rowwise().mean(); const Eigen::Matrix3Xf points_centered = points.colwise() - mean; int setting = Eigen::ComputeThinU | Eigen::ComputeThinV; Eigen::JacobiSVD<Eigen::Matrix3Xf> svd = points_centered.jacobiSvd(setting); Eigen::Vector3d normal = **???** double d = normal.dot(mean);
source share