笔记
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63题目: /* 已知旋转矩阵定义是沿着Z轴旋转45°。请按照该定义初始化旋转向量、旋转矩阵、四元数、欧拉角。请编程实现: 1、以上四种表达方式的相互转换关系并输出 2、假设平移向量为(1,2,3),请输出旋转矩阵和该平移矩阵构成的欧式变换矩阵,并根据欧式变换矩阵提取旋转向量及平移向量 本程序学习目标: 1、学习eigen中刚体旋转的四种表达方式,熟悉他们之间的相互转换关系 2、熟悉旋转平移和欧式变换矩阵的相互转换关系 */ #include <iostream> #include <cmath> #include <eigen3/Eigen/Core> #include <eigen3/Eigen/Geometry> using std::cout; using std::endl; int main(int argc, char **argv) { // 定义绕Z轴旋转45°的旋转向量 Eigen::AngleAxisd rotationVector(M_PI / 4, Eigen::Vector3d(0, 0, 1)); // 打印旋转向量 cout << "AlgleAxis : " << rotationVector.angle() * rotationVector.axis().transpose() << endl; // 旋转向量 -> 旋转矩阵 Eigen::Matrix3d rotationMatrix = rotationVector.toRotationMatrix(); // 打印旋转矩阵 cout << "Rotation Matrix :n" << rotationMatrix << endl; // 旋转向量 -> 四元数 Eigen::Quaterniond quaternion_M(rotationMatrix); // 四元数必须归一化 quaternion_M.normalize(); // 打印四元数,顺序(x, y, z, w) cout << "Quaternion(x, y, z, w) : " << quaternion_M.coeffs().transpose() << endl; // 旋转矩阵 -> 欧拉角,顺序(Z, Y, X) Eigen::Vector3d eulerAngle = rotationMatrix.eulerAngles(2, 1, 0); // 打印四元数 cout << "EulerAngle : " << eulerAngle.transpose() << endl; // 定义平移量t Eigen::Vector3d t(1, 2, 3); // 打印平移向量 cout << "t : " << t.transpose() << endl; // 欧式变换矩阵 Eigen::Isometry3d T(rotationMatrix); T.pretranslate(t); // 打印欧式变换矩阵 cout << "Transform Matrix :n" << T.matrix() << endl; // 欧式变换矩阵提取旋转矩阵 Eigen::Matrix3d rotationMatrix_T = T.rotation(); // Eigen::Matrix3d rotationMatrix_T = T.matrix().block(0, 0, 3, 3); cout << "Rotation Matrix frome Transform Matrix :n" << rotationMatrix_T << endl; // 欧式变换矩阵提取旋转向量 Eigen::Vector3d rotationVector_T = T.translation(); // Eigen::Vector3d rotationVector_T = T.matrix().block(0, 3, 3, 1); cout << "t from Transform Matrix : " << rotationVector_T.transpose() << endl; return 0; }
最后
以上就是高挑黑裤最近收集整理的关于Eigen:几何变换的全部内容,更多相关Eigen内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复