Use Eigen to solve the rotation matrices of different coordinate systems

Rigid transformation between different coordinate systems and implementation:

The principle of coordinate system transformation is as follows. Affine transformation is used to realize rotation and translation:
[ r 11 r 12 txr 21 r 22 ty 0 0 ] ∗ [ xy 1 ] = [ x ′ ​​y ′ 1 ] \begin{bmatrix} r_{11 } & r_{12}& t_x\\ r_{21}& r_{22}& t_y\\ 0 & 0& \end{bmatrix}* \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}= \begin{bmatrix} x^{'} \\ y^{'} \\ 1 \end{bmatrix} r11r210r12r220txty xy1 = xy1
But find the equation A ∗ x = b A*x=b in eigenAx=b , so you can put[xyz] \begin{bmatrix} x \\ y \\ z \end{bmatrix} xyz As A, consider [ x ′ ​​y ′ z ′ ] \begin{bmatrix} x^{'} \\ y^{'} \\ z^{'} \end{bmatrix} xyz Think of it as bbb . However, this formula requires a certain amount of deformation to correspond to the previous one, and a transpose is made before and after, as shown below: [ [
r 11 r 12 txr 21 r 22 ty 0 0 ] ∗ [ xy 1 ] ] T = [ x ′ y ′ 1 ] T \left [ \begin{bmatrix} r_{11} & r_{12}& t_x\\ r_{21}& r_{22}& t_y\\ 0 & 0& \end{bmatrix}*\\ \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}\\ \right ] ^{T}= \begin{bmatrix} x^{'} \\ y^{'} \\ 1 \end{ bmatrix}^{T} r11r210r12r220txty xy1 T= xy1 T
will then be converted into the following:
[ xy 1 ] ∗ [ r 11 r 21 0 r 12 r 22 0 txty 1 ] = [ x ′ ​​y ′ 1 ] \begin{bmatrix} x &y &1 \end{bmatrix} *\begin{bmatrix} r_{11} & r_{21}& 0\\ r_{12}& r_{22}& 0\\ t_x & t_y&1 \end{bmatrix}=\begin{bmatrix} x^{' } & y^{'} & 1 \end{bmatrix}[xy1] r11r12txr21r22ty001 =[xy1]
So in the end the above formula is used in the program, andA.fullPivLu().solve(B)when the calculation is called, A corresponds to[ xy 1 ] \begin{bmatrix} x &y &1 \end{bmatrix}[xy1] , B corresponds to[ x ′ ​​y ′ 1 ] \begin{bmatrix} x^{'} & y^{'} & 1 \end{bmatrix}[xy1] . So the result is also[ r 11 r 21 0 r 12 r 22 0 txty 1 ] \begin{bmatrix} r_{11} & r_{21}& 0\\ r_{12}& r_{22}& 0\ \t_x & t_y&1 \end{bmatrix} r11r12txr21r22ty001 . See if you need to transpose it

A << -4.93374, -0.056378, 1, 0.397714, -0.126519, 1, 2.63284, -0.0925265, 1;
	B << 109995, 8318, 1, 110066, 13650, 1, 110032, 15885, 1;
Eigen::Matrix3d T = TransMatrix(A, B);
cout << "transform matrix is: " << "\n";
cout << T.transpose() << endl;//显示出A*T=B,但是实际计算的是(T的转置*A的转置)的转置=B的转置
cout << A*T << endl;

The transformation matrix results look like this:

Insert image description here

Guess you like

Origin blog.csdn.net/weixin_42295969/article/details/130619204