Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用特征值过滤球体内部的点_C++_Eigen - Fatal编程技术网

C++ 使用特征值过滤球体内部的点

C++ 使用特征值过滤球体内部的点,c++,eigen,C++,Eigen,我有一组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

我有一组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);
矩阵点;//三维点集
矩阵p;
//填充“点”矩阵
...
//在矩阵中填入多份“p”以匹配大小
“点”的定义
矩阵pp(points.rows(),3);
pp=矩阵::一(点.行,1)*p;
矩阵sq_距离=(点-pp).rowwise.squaredNorm();
矩阵最近点=平方距离<(距离阈值*距离阈值);
然后我可以有一些方法来提取“点”中的点,以满足“最近的点”条件,如

Matrix<double, Dynamic, 3> nearest = points(nearest_points);
矩阵最近=点(最近的点);

对于最近的,我建议:

int i;
double sqdist = (points.rowwise()-p).rowwise().squaredNorm().minCoeff(&i);
nearest = points.row(i);
对于给定球中的球,您当前必须自己编写一个循环:

ArrayXd sqdists = (points.rowwise()-p).rowwise().squaredNorm();
Matrix<double,Dynamic,3> nearests( (sqdists<sqradius).count(), 3 );
int count = 0;
for(int i=0; i<points.rows(); ++i)
  if(sqdists(i)<sqradius)
    nearests.row(count++) = points.row(i);
ArrayXd sqdists=(points.rowwise()-p).rowwise().squardnorm();
矩阵最近((sqdists