2021-01-09利用eigen矩阵基本操作

头文件

#include <eigen3/Eigen/core>

#include <eigen3/Eigen/dense>

#include <eigen3/Eigen/Geometry>

//如果想要省略eigen3,需要在CMakeLists.txt文件当中添加:

include_directories("/usr/include/eigen3")

矩阵定义

Eigen::Matrix matrix_name = Eigen::Matrix <double, 3, 4> //知道矩阵的大小3*4大小的矩阵

Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> matrix_notknow_size;//不知道矩阵的大小 ,这样定义

Eigen::MatrixXd matrix_nSize; //更简单地定义矩阵,不知道矩阵的大小。

矩阵数据格式的变换

matrix_nSize.cast<double>()  //把矩阵数据格式转换成double格式,因为矩阵只能相同格式地相乘。

基本的矩阵操作:转置、求逆、求迹、求和、数乘、行列式

matrix_nSize.transpose() //转置

matrix_nSize.sum() //矩阵各元素求和

matrix_nSize.trace() //求迹

matrix_nSize.inverse() //求逆

10 * matrix_nSize //矩阵数乘,数乘是可以不同类型来做的.

matrix_nSize.determinant() //求行列式

矩阵特征值求解

matrix_real = Eigen::Matrix3d::Random();

matrix_realSymentry = matrix_real.transpose() * matrix_real;//这是一个实对称矩阵

Eigen::SelfAdjointEigenSolver<Eigen::Matrix3d> eigen_solver (matrix_realSymentry) //特征求解器

cout << "Eigen values = " << eigen_solver.eigenvalues() <<endl; //输出特征值

cout << "Eigen vectors = " << eigen_solver.eigenvectors() << endl; //输出特征向量

矩阵QR分解求方程的解

x = matrix_NN.colPivHouseholderQr().solve(v_Nd);

/********************************************************

旋转矩阵、旋转向量、四元数的使用

********************************************************/

旋转向量的定义

Eigen::AngleaAxisd rotation_vector (M_PI/4, Eigen::Matrix3d::Identity())

rotation_matrix = rotation_vector.toRoationMatrix();//把旋转向量转换成旋转矩阵

rotation_matrix = rotation_vector.Matrix();// 另外一种旋转矩阵的表达形式

欧拉角

Eigen::vector3d euler_angles = rotation_matrix.eulerAngles(2, 1, 0);// z y x 顺序, yaw, pitch, row;

变换矩阵

Eigen::Isometry3d T = Eigen::Isometry3d::Identity();

T.rotate(rotation_vector);

T.pretranslate(Eigen::Vector3d(1, 3, 4));

cout <<"Transform matrix is \n" << T.matrix() << endl;

cout <<"Rotation vector is \n" << rotation_vector.axis() << endl;

四元数

Eigen::Quaterniond q = Eigen::quaterniond (rotation _vector);

cout << " quaterniond = \n" << q.coeffs() << endl;

v_rotated = q *  v;

参考书目《视觉SLAM十四讲:从理论到实践》

  • 1鏃ュ埌31鏃ョ殑鑻辨枃鍏ㄧО鍜岃嫳鏂囩缉鍐欐槸浠涔?
    绛旓細1鏃 first 1st 2鏃 second 2nd 3鏃 third 3rd 4鏃 fourth 4th 5鏃 fifth 5th 6鏃 sixth 6th 7鏃 seventh 7th 8鏃 eighth 8th 9鏃 ninth 9th 10鏃 tenth 10th 11鏃 eleventh 11th 12鏃 twelfth 12th 13鏃 thirteenth 13th 14鏃 fourteenth 14th 15鏃 fi...
  • 鑻辨枃鏃ユ湡鎬庝箞璇?
    绛旓細1鏃ワ細 first 锛1 2鏃ワ細 second 锛2nd锛3鏃ワ細 third 锛3rd锛4鏃ワ細 fourth 锛4th锛5鏃ワ細 fifth 锛5th锛6鏃ワ細 sixth 锛6th锛7鏃ワ細 seventh 锛7th锛8鏃ワ細 eighth 锛8th锛9鏃ワ細 ninth 锛9th锛10鏃ワ細 tenth 锛10th锛11鏃ワ細 eleventh 锛11th锛12鏃ワ細 twelfth 锛12th锛13鏃ワ細 thirteenth 锛13th...
  • 涓鍒31鏃ョ敤鑻辫鎬庝箞璇
    绛旓細1鏃ワ細 first 锛1 2鏃ワ細 second 锛2nd锛3鏃ワ細 third 锛3rd锛4鏃ワ細 fourth 锛4th锛5鏃ワ細 fifth 锛5th锛6鏃ワ細 sixth 锛6th锛7鏃ワ細 seventh 锛7th锛8鏃ワ細 eighth 锛8th锛9鏃ワ細 ninth 锛9th锛10鏃ワ細 tenth 锛10th锛11鏃ワ細 eleventh 锛11th锛12鏃ワ細 twelfth 锛12th锛13鏃ワ細 thirteenth 锛13th...
  • n1鍒31鐨勮嫳鏂囩缉鍐欐槸浠涔
    绛旓細1鏃ワ細 first 锛1 2鏃ワ細 second 锛2nd锛3鏃ワ細 third 锛3rd锛4鏃ワ細 fourth 锛4th锛5鏃ワ細 fifth 锛5th锛6鏃ワ細 sixth 锛6th锛7鏃ワ細 seventh 锛7th锛8鏃ワ細 eighth 锛8th锛9鏃ワ細 ninth 锛9th锛10鏃ワ細 tenth 锛10th锛11鏃ワ細 eleventh 锛11th锛12鏃ワ細 twelfth 锛12th锛13鏃ワ細 thirteenth 锛13th...
  • n1鏃ュ埌31鏃ョ殑鑻辨枃鍏ㄧО鍜岃嫳鏂囩缉鍐欐槸浠涔?
    绛旓細1鏃ワ細 first 锛1 2鏃ワ細 second 锛2nd锛3鏃ワ細 third 锛3rd锛4鏃ワ細 fourth 锛4th锛5鏃ワ細 fifth 锛5th锛6鏃ワ細 sixth 锛6th锛7鏃ワ細 seventh 锛7th锛8鏃ワ細 eighth 锛8th锛9鏃ワ細 ninth 锛9th锛10鏃ワ細 tenth 锛10th锛11鏃ワ細 eleventh 锛11th锛12鏃ワ細 twelfth 锛12th锛13鏃ワ細 thirteenth 锛13th...
  • 鏃ュ埌鏈堣嫳璇庝箞璇
    绛旓細1鏃ワ細 first 锛1 2鏃ワ細 second 锛2nd锛3鏃ワ細 third 锛3rd锛4鏃ワ細 fourth 锛4th锛5鏃ワ細 fifth 锛5th锛6鏃ワ細 sixth 锛6th锛7鏃ワ細 seventh 锛7th锛8鏃ワ細 eighth 锛8th锛9鏃ワ細 ninth 锛9th锛10鏃ワ細 tenth 锛10th锛11鏃ワ細 eleventh 锛11th锛12鏃ワ細 twelfth 锛12th锛13鏃ワ細 thirteenth 锛13th...
  • 扩展阅读:20200101改成2020-01-01 ... 日期格式变为2021-09-01 ... 佳能打印机e301-0001 ... 2021-01-01格式怎么设置 ... 荣威ei6报价及图片 ... 荣威ei5纯电动汽车出租版 ... 表格2020-03-01怎么设置 ... www.exam100.net ... 2020.01.01转换日期格式 ...

    本站交流只代表网友个人观点,与本站立场无关
    欢迎反馈与建议,请联系电邮
    2024© 车视网