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");
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
can define the equation of a line
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)
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):
...do this also for the other direktions then:
now you can draw them: