23
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Eigenの使い方チートシート

Last updated at Posted at 2014-05-19

公式のドキュメント
http://eigen.tuxfamily.org/index.php?title=Main_Page

定義

行列

#include “Eigen/Core”
Eigen::MatrixXd mat(3,3); 
Eigen::MatrixXd mat;                                                                               
mat = Eigen::MatrixXd::Identity(3,3);
Eigen::MatrixXd mat(3,3); 
mat << 1,2,3,4,5,6,7,8,9;
cout << mat << endl;

出力結果
1 2 3
4 5 6
7 8 9
初期化
mat.setZero();

演算

行列式

A.determinant();

連立方程式を解く

#include “Eigen/Core”
#include “Eigen/LU”

Eigen::MatrixXd A(3,3);
A << 1,1,1, 1,2,1, 1,2,3;
cout <<"A = " << endl << A << endl;

Eigen::VectorXd b(3);
b << 5,3,8;
cout <<"b = " << endl << b << endl;

Eigen::VectorXd x = A.fullPivLu().solve(b);

cout <<"x = " << endl << x << endl;

出力結果
A =
1 1 1
1 2 1
1 2 3
b =
5
3
8
x =
4.5
-2
2.5

アフィン変換

並進

Eigen::Translation<double, 3> trans(x,y,z); // Eigen::Translation<double, 3>(Eigen::Vector3d) も可

回転

Eigen::Matrix3d rot = Eigen::AngleAxisd(roll, Eigen::Vector3d::UnitX())
                    * Eigen::AngleAxisd(pitch, Eigen::Vector3d::UnitY())
                    * Eigen::AngleAxisd(yaw, Eigen::Vector3d::UnitZ());

並進と回転からアフィン変換を作る

Eigen::Affine3d affine = trans * rot;

アフィン変換から並進と回転を取り出す

Eigen::Vector3d trans_ = affine.translation(); // 並進
Eigen::Matrix3d rot_ = affine.rotation(); // 回転
Eigen::Vector3d euler = rot_.eulerAngles(0,1,2); // オイラー角. 

メモ : オイラー角について, 回転行列からオイラー角は24パターンあり得るので順番を指定する。この場合 roll, pitch, yaw の順番に取り出される.

調べたら追記する

23
22
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?