兩點云坐標點的轉(zhuǎn)化
兩點云坐標點的轉(zhuǎn)化,就是把一個點云從自己的坐標系變換到另一個坐標系,配準,拼接都用得到。有點類似相機和激光外參的標定(將激光坐標系轉(zhuǎn)換到相機的坐標系。都是Rt變換)。
(1)基本知識
R為旋轉(zhuǎn)矩陣,X為原始點,t為平移量,X'為變換后的點(目標點)
R*X+t=X'? (Rt*X=X')
但是所求Rt矩陣用一個矩陣表示如下:
/* Reminder: how transformation matrices work :
|-------> This column is the translation
| 1 0 0 x |? \
| 0 1 0 y |?? }-> The identity 3x3 matrix (no rotation) on the left
| 0 0 1 z |? /
| 0 0 0 1 |??? -> We do not use this line (and it has to stay 0,0,0,1)
(2)舉例說明
將一個點(坐標系)繞自身z軸旋轉(zhuǎn)(正)M_PI/4,然后再沿著旋轉(zhuǎn)后得到的x軸方向(正)平移2.5。求Rt矩陣?
方法1:
直接數(shù)學(xué)方法得到并賦值:
METHOD #1: Using a Matrix4f
This is the "manual" method, perfect to understand but error prone !
*/
Eigen::Matrix4f transform_1 = Eigen::Matrix4f::Identity();
// Define a rotation matrix (see https://en.wikipedia.org/wiki/Rotation_matrix)
float theta = M_PI/4; // The angle of rotation in radians
transform_1 (0,0) = cos (theta); //第1行第1列個元素
transform_1 (0,1) = -sin(theta); //第1行第 2 列個元素
transform_1 (1,0) = sin (theta);
transform_1 (1,1) = cos (theta);
//??? (row, column)
// Define a translation of 2.5 meters on the x axis.
// transform_1 (0,3) = 2.5;
transform_1 (0,3) = 0;
// Print the transformation
printf ("Method #1: using a Matrix4f\n");
std::cout << transform_1 << std::endl;
方法2:
通過程序計算矩陣:
/*? METHOD #2: Using a Affine3f
This method is easier and less error prone
*/
Eigen::Affine3f transform_2 = Eigen::Affine3f::Identity();
// Define a translation of 2.5 meters on the x axis.
transform_2.translation() << 2.5, 0.0, 0.0;
// The same rotation matrix as before; theta radians arround Z axis
transform_2.rotate (Eigen::AngleAxisf (theta, Eigen::Vector3f::UnitZ()));
// Print the transformation
printf ("\nMethod #2: using an Affine3f\n");
std::cout << transform_2.matrix() << std::endl;
最后轉(zhuǎn)化:
pcl::transformPointCloud (*source_cloud, *transformed_cloud, transform_2);