Draw a vector from the centroid in point cloud

本秂侑毒 提交于 2019-12-23 03:37:12

问题


I have found the centroid and the eigenvectors of a cluster. How can I draw the vector from the centroid in pcl visualizer.

    Eigen::Vector4f centroid;
    Eigen::Matrix3f covariance_matrix;

    // Extract the eigenvalues and eigenvectors
    Eigen::Vector3f eigen_values;
    Eigen::Matrix3f eigen_vectors;

    pcl::compute3DCentroid(*cloud_filtered,cluster_indices[i],centroid);

    // Compute the 3x3 covariance matrix
    pcl::computeCovarianceMatrix (*cloud_filtered, centroid, covariance_matrix);
    pcl::eigen33 (covariance_matrix, eigen_vectors, eigen_values);
    _viewer->addLine<pcl::PointXYZRGB> (centroid, eigen_vectors, "line");

回答1:


An equation of a line in 3D can be defined by a point and a vector. Just plug in your centroid as the point (x,y,z) and the eigenvector as its vector (i, j, k) .... For example

point1 at (3, 2, -5)  # your centroid

vectorA of (7i, -6j, 2k)  #  your eigenvector

can define the equation of a line

r = (3i, 2j, -5k) + S(+7i, -6j, 2)

where variable S freely varies continuously (sample value of S = -4.9, or S = 0.03) to determine various points along your line. For example S of 0 gives you your centroid point, whereas S = 1 gives you another point on the same line of (10i, -4j, -3k)




回答2:


You can draw a arrow from the centroid orgin to the endpoint of the eigen_vectors. But first you need to map your eigen_vectors and the centroid into a PointXYZ dependent of the orgin (centroid):

Eigen::vector < PointXYZ > centroidXYZ_value, Point1_value,....;

PointXYZ centroidXYZ;
centroidXYZ.getVector4fMap() = centroid;

PointXYZ Point1 = PointXYZ((centroid(0) + eigen_vectors.col(0)(0)), (centroid(1) + eigen_vectors.col(0)(1)), (centroid(2) + eigen_vectors.col(0)(2)));

...do this also for the other direktions then:

centroidXYZ_value.push_back(centroidXYZ);
Point1_value.push_back(Point1);

now you can draw them:

_viewer->addArrow(Point1_value.at(i), centroidXYZ_value.at(i), 0.5, 0.5, 0.5, false, "Arrow1");
_viewer->addArrow(Point2_value.at(i), centroidXYZ_value.at(i), 0.5, 0.5, 0.5, false, "Arrow2");


来源:https://stackoverflow.com/questions/28844865/draw-a-vector-from-the-centroid-in-point-cloud

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!