我有一组 3D 点,我需要计算哪些点最接近给定点p。我想知道在 Eigen 中这可能是正确的方法。到目前为止,我有:
Matrix<double, Dynamic, 3> points; // The set of 3D points
Matrix<double, 1, 3> p;
// Populate the "points" matrix
...
// Fill a matrix with several copies of "p" in order to match the size
of "points"
Matrix<double, Dynamic, 3> pp(points.rows(), 3);
pp = Matrix<double, Dynamic, 1>::Ones(points.rows, 1) * p;
Matrix<double, Dynamic, 1> sq_distances = (points - pp).rowwise.squaredNorm();
Matrix<bool, Dynamic, 1> nearest_points = sq_distances < (dist_threshold * dist_threshold);
然后我可以有一些方法来提取满足“最近点”条件的“点”中的点,如
Matrix<double, Dynamic, 3> nearest = points(nearest_points);
?