Search code examples
c++matrixpoint-cloudspoint-cloud-library

How to rotate point cloud about an axis?


I have a point cloud of a depth image that was taken with the camera 30 degrees above the horizontal (rotated 30 degrees in z-axis). I want to translate all of the points back to their position as if the camera was at 0 degrees, which I believe I can do with the following rotation matrix:

|cos(30) -sin(30) 0| 
|sin(30)  cos30   0| 
|0        0       1|

However, when looking at the pcl method to transform a point cloud I found this:

pcl::transformPointCloud (const PointCloud< PointT > &cloud_in, 
PointCloud< PointT > &cloud_out, const Eigen::Matrix< Scalar, 4, 4 > &transform)

But why is it a 4x4 matrix as opposed to the 3x3 rotation one above?


Solution

  • |x||1 0 0 a| =  |x+a|
    |y||0 1 0 b|    |y+b|
    |z||0 0 1 c|    |z+c|
    |1||0 0 0 1|    |1  |
    

    In this example we moved the point (x,y,z) to the point(x+a, y+b, z+c). This can only be done with a 4 x 4 matrix.


    |cos(30) -sin(30) 0 0| multiply The Matrix above. 
    |sin(30)  cos30   0 0| 
    |0        0       1 0|
    |0        0       0 1|
    

    This will give you a rotation and translation of a point.