title: how to find principal components and orientation of a point cloud using point cloud library
body: <p>I have a point cloud of a wooden block. I have found the centroid of that  point cloud. Now I am trying to find the Principal components and orientation using point cloud library. Below is the code I have tried. Correct me if you havent understood something.</p>
  
  <pre><code>        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,centroid);
  
          // Compute the 3x3 covariance matrix
          pcl::computeCovarianceMatrix (*cloud_filtered, centroid, covariance_matrix);
          pcl::eigen33 (covariance_matrix, eigen_vectors, eigen_values);
          std::cout &lt;&lt; "centroid-x:"&lt;&lt;centroid[0]&lt;&lt;"centroid-y:"&lt;&lt;centroid[1]&lt;&lt;"centroid-z:"&lt;&lt;centroid[2]&lt;&lt;std::endl;
  </code></pre>