Eigen and quaternion

eigen

Eigen is a C++ template library for linear algebra including the manipulation of quaternion.

#include <iostream>
#include <Eigen/Dense>
#include <Eigen/Core>
#include <Eigen/Geometry>
using namespace std;
using namespace Eigen;

int main(int argc, const char * argv[]) {
    Matrix3f A, B;
    A << 1,0,0, 0,2,0, 0,0,4;
    B = A.inverse();
    cout << A << endl;
    cout << B << endl;
    
    Quaternionf q1(AngleAxisf(M_PI/3.0f, Vector3f::UnitZ()));
    cout << q1.w() << ", " << q1.x() << ", " << q1.y() << ", " << q1.z() << endl;
    return 0;
}
1 0 0
0 2 0
0 0 4
   1    0    0
   0  0.5    0
   0    0 0.25
0.866025, 0, 0, 0.5

Unit quaternions offer you a better way to represent orientations and rotations of objects in three dimensions than rotation matrices do.

euler

Leave a Reply

Your email address will not be published. Required fields are marked *