Eigen and SVD to find the best plane to set given a set of points

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); 
+5
source share
2 answers

U = svd.matrixU() designating U = svd.matrixU() , the vectors U.col(0) and U.col(1) define the base of your plane and U.col(2) is normal for your plane.

U.col(0) also determines the direction with the largest standard deviation.

You should use the ComputeFullU flag instead of ComputeThinU to have the correct dimensions, even if your points are coplanar.

+3
source

Your problem mainly lies in how to perform least square framing using the Eigen JacobiSVD module. Here is a link with a more useful example. The main idea of ​​least square fitting is that you first take the vector difference of all N-1 points from one of N points, and then try to approximate all such N-1 vectors as a linear combination of two basis vectors that define a two-dimensional plane.

+1
source

All Articles