-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathch3_exercise.cpp
101 lines (72 loc) · 2.74 KB
/
ch3_exercise.cpp
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//
// Created by bob on 19-3-11.
//
#include <iostream>
#include <Eigen/Core>
#include <Eigen/Geometry>
using namespace std;
void ch3_5(Eigen::MatrixXd &xd){
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
if (i == j)
xd(i,j) = 1;
else
xd(i,j) = 0;
}
}
}
int main(int argc,char * argv[]){
// //第五题
// Eigen::MatrixXd test_matrix = Eigen::MatrixXd::Random(5,5);
//
// cout << "原矩阵:\n" << test_matrix << endl;
//
// ch3_5(test_matrix);
//
// cout << "提取左上角3*3块并赋值单位矩阵后的矩阵:\n" << test_matrix << endl;
//第七题
//小萝卜一号的位姿相对于世界坐标系变化
Eigen::Quaterniond q1 = Eigen::Quaterniond(0.35,0.2,0.3,0.1);
Eigen::Vector3d t1 = Eigen::Vector3d(0.3,0.1,0.1);
//小萝卜一号的位姿相对于世界坐标系变化
Eigen::Quaterniond q2 = Eigen::Quaterniond(-0.5,0.4,-0.1,0.2);
Eigen::Vector3d t2 = Eigen::Vector3d(-0.1,0.5,0.3);
//点p在世界坐标系下面的坐标是不变的,由此得到等式:Tcw1.inverse()*p1c = Tcw2.inverse()*p2c,p1c已知,求p2c
Eigen::Vector3d p1c = Eigen::Vector3d(0.5,0,0.2);
Eigen::Matrix3d r1 = q1.matrix();
Eigen::Matrix3d r2 = q2.matrix();
cout << "r1:\n" << r1 << endl;
Eigen::Isometry3d tcw1 = Eigen::Isometry3d::Identity();
Eigen::Isometry3d tcw2 = Eigen::Isometry3d::Identity();
tcw1.rotate(r1);
tcw1.pretranslate(t1);
cout << "变换矩阵1:\n" << tcw1.matrix() << endl;
tcw2.rotate(r2);
tcw2.pretranslate(t2);
cout << "变换矩阵2:\n" << tcw2.matrix() << endl;
Eigen::Vector3d p2c;
p2c = tcw2*tcw1.inverse()*p1c;
cout << "四元数未进行归一化:p点在小萝卜头二号坐标系下的坐标为:\n" << p2c.transpose() << endl;
//四元数归一化
q1.normalize();
q2.normalize();
r1 = q1.toRotationMatrix();
r2 = q2.toRotationMatrix();
cout << "r1:\n" << r1 << endl;
tcw1.rotate(r1);
tcw1.pretranslate(t1);
cout << "变换矩阵1:\n" << tcw1.matrix() << endl;
tcw2.rotate(r2);
tcw2.pretranslate(t2);
cout << "变换矩阵2:\n" << tcw2.matrix() << endl;
p2c = tcw2*tcw1.inverse()*p1c;
cout << "四元数进行归一化后:p点在小萝卜头二号坐标系下的坐标为:\n" << p2c.transpose() << endl;
tcw1.rotate(q1);
tcw1.pretranslate(t1);
cout << "变换矩阵1:\n" << tcw1.matrix() << endl;
tcw2.rotate(q2);
tcw2.pretranslate(t2);
cout << "变换矩阵2:\n" << tcw2.matrix() << endl;
p2c = tcw2*tcw1.inverse()*p1c;
cout << "四元数进行归一化后:p点在小萝卜头二号坐标系下的坐标为:\n" << p2c.transpose() << endl;
}