帮助文档
前言
三维空间中点在直线上的投影,推导方式参考这篇博客:https://blog.csdn.net/weixin_44329757/article/details/120047845
具体实现
//点云到某个直线上的投影
void PointToLineProjection(pcl::PointXYZ point, Eigen::VectorXf coefficients, pcl::PointXYZ& point_out)
{
Eigen::Vector3f p(point.x, point.y, point.z);
Eigen::Vector3f m(coefficients(0), coefficients(1), coefficients(2));
Eigen::Vector3f mp(p(0) - m(0), p(1) - m(1), p(2) - m(2));
Eigen::Vector3f s(coefficients(3), coefficients(4), coefficients(5));
float t;
t = (s.transpose() * mp / s.squaredNorm())(0);
point_out.x = coefficients(3) * t + coefficients(0);
point_out.y = coefficients(4) * t + coefficients(1);
point_out.z = coefficients(5) * t + coefficients(2);
}