玩命加载中 . . .

Eigen_运算符


向量内积

Vector2d m(1, 2);
Vector2d n(4, 5);
cout << m.dot(n) << endl;    // 向量内积:14
cout << m.adjoint() * n << endl;
cout << (m.adjoint() * n).value() << endl;

转置与伴随矩阵

Matrix2d m, n;
m << 1, 2,
     3, 4;
n = m.transpose();

// m.transposeInPlace();    //m变成自己的转置矩阵

n = m.adjoint();    //伴随矩阵,实数的伴随矩阵等于转置矩阵
// 1 3
// 2 4

m.adjointInPlace();    //m变成自己的伴随矩阵

Matrix2cf m = Matrix2cf::Random(); //复数的伴随矩阵,除了转置,复数域要变号

cout << "Here is the 2x2 complex matrix m:" << endl << m << endl;
cout << "Here is the adjoint of m:" << endl << m.adjoint() << endl;


Here is the 2x2 complex matrix m:
(0.127171,-0.997497) (-0.0402539,0.170019)
(0.617481,-0.613392)  (0.791925,-0.299417)
Here is the adjoint of m:
(0.127171,0.997497)    (0.617481,0.613392)
(-0.0402539,-0.170019)    (0.791925,0.299417)

范数与单位化

Vector2d vec1(3, 4);
Vector2d vec2;
double scalar = vec1.norm();    // 二阶范数 5    

scalar = vec1.squaredNorm();    // 范数平方 25

vec2 = vec1.normalized();    // 单位化 0.6; 0.8

vec1.normalize();    // inplace 自己变成自己的单位化

叉积

Vector3d vec1(1, 2, 3);
Vector3d vec2(3, 4, 5);
cout << "cross: " << endl << vec1.cross(vec2) << endl; 
// 叉积只适用于三维向量
cross:
     -2
      4
     -2

文章作者: kunpeng
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 kunpeng !
  目录