我有一个已知的点云来包含发言权。这是朝向某个未知方向的,并且在原点(0,0,0)处不。我必须
floor_plane
移动到XY平面,以便floor_plane
位于XY平面上floor_plane
的质心移动到原点(0,0,0)
。我对上述方法的看法是:
floor_plane
的平面系数。前三个系数对应floor_plane
的法线。 theta=acos(C/sqrt(A^2+B^2+C^2)
,其中A,B,C是floor_plane
的前三个系数。 floor_plane
的质心。否定它们以生成翻译使用PointCloud Library的代码如下所示。它无法执行所需的转换,我不知道为什么。有线索吗?
// Find the planar coefficients for floor plane
pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients);
pcl::PointIndices::Ptr floor_inliers (new pcl::PointIndices);
pcl::SACSegmentation<pcl::PointXYZRGB> seg;
seg.setOptimizeCoefficients (true);
seg.setModelType (pcl::SACMODEL_PLANE);
seg.setMethodType (pcl::SAC_RANSAC);
seg.setDistanceThreshold (0.01);
seg.setInputCloud (floor_plane);
seg.segment (*floor_inliers, *coefficients);
std::cerr << "Floor Plane Model coefficients: " << coefficients->values[0] << " "
<< coefficients->values[1] << " "
<< coefficients->values[2] << " "
<< coefficients->values[3] << std::endl;
Eigen::Matrix<float, 1, 3> floor_plane_normal_vector, xy_plane_normal_vector, rotation_vector;
floor_plane_normal_vector[0] = coefficients->values[0];
floor_plane_normal_vector[1] = coefficients->values[1];
floor_plane_normal_vector[2] = coefficients->values[2];
std::cout << floor_plane_normal_vector << std::endl;
xy_plane_normal_vector[0] = 0.0;
xy_plane_normal_vector[1] = 0.0;
xy_plane_normal_vector[2] = 1.0;
std::cout << xy_plane_normal_vector << std::endl;
rotation_vector = xy_plane_normal_vector.cross (floor_plane_normal_vector);
std::cout << "Rotation Vector: "<< rotation_vector << std::endl;
float theta = acos(floor_plane_normal_vector.dot(xy_plane_normal_vector)/sqrt( pow(coefficients->values[0],2)+ pow(coefficients->values[1],2) + pow(coefficients->values[2],2)));
Eigen::Affine3f transform_2 = Eigen::Affine3f::Identity();
transform_2.translation() << 0, 0, 30;
transform_2.rotate (Eigen::AngleAxisf (theta, rotation_vector));
std::cout << "Transformation matrix: " << std::endl << transform_2.matrix() << std::endl;
pcl::transformPointCloud (*cloud, *centeredCloud, transform_2);
答案 0 :(得分:3)
如果有人有兴趣
代码中有2个问题
感谢您发布代码,它帮助我快速完成。
答案 1 :(得分:2)
首先进行翻译,然后进行轮换。
检查theta的标志
Eigen::Vector3f rotation_vector = xy_plane_normal_vector.cross(floor_plane_normal_vector);
float theta = -atan2(rotation_vector.norm(), xy_plane_normal_vector.dot(floor_plane_normal_vector));