Eigenは、四元数の操作も含む線型代数のC++テンプレートライブラリです。
#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
単位四元数は、3次元空間内での物体の向きと回転とを表現するのに回転行列よりも優れた方法を提供します。