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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
| #include<cmath> #include<eigen3/Eigen/Core> #include<eigen3/Eigen/Dense> #include<iostream> using namespace std;
void Test() { std::cout << "Example of cpp \n"; float a = 1.0, b = 2.0; std::cout << a << std::endl; std::cout << a/b << std::endl; std::cout << std::sqrt(b) << std::endl; std::cout << std::acos(-1) << std::endl; std::cout << std::sin(30.0/180.0*acos(-1)) << std::endl;
std::cout << "Example of vector \n"; Eigen::Vector3f v(1.0f,2.0f,3.0f); Eigen::Vector3f w(1.0f,0.0f,0.0f); std::cout << "Example of output \n"; std::cout << v << std::endl; std::cout << "Example of add \n"; std::cout << v + w << std::endl; std::cout << "Example of scalar multiply \n"; std::cout << v * 3.0f << std::endl; std::cout << 2.0f * v << std::endl;
std::cout << "Example of matrix \n";
Eigen::Matrix3f i,j,ans; i << 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0; j << 2.0, 3.0, 1.0, 4.0, 6.0, 5.0, 9.0, 7.0, 8.0; cout << "Example of output \n"; cout << i << "\n\n"; cout << "this is matrix add : \n"; ans = i + j; cout << ans << "\n\n";
cout << "this is matrix scalar multiply : \n"; ans = i * 20; cout << ans << "\n\n";
cout << "this is matrix multiply : \n"; ans = i * j; cout << ans << "\n\n";
cout << "this is matrix multiply vector : \n"; Eigen::MatrixXf ans1(1,3); ans1 = i * v; cout << ans1 << "\n\n"; }
double DegToRad(double Deg) { return Deg / 180.0 * M_PI; }
void solve() { Eigen::Vector3f Point(2.0, 1.0, 1.0);
double Deg = 45.0; double Rad = DegToRad(Deg);
Eigen::Matrix3f RotationMatrix; RotationMatrix << cos(Rad), -sin(Rad), 0, sin(Rad), cos(Rad), 0, 0, 0, 1; Point = RotationMatrix * Point; cout << "旋转变换之后:\n" << Point << "\n\n";
double tx = 1.0; double ty = 2.0;
Eigen::Matrix3f TranslationMatrix; TranslationMatrix << 1, 0, tx, 0, 1, ty, 0, 0, 1;
Point = TranslationMatrix * Point; cout << "最终结果:\n" << Point <<'\n'; }
int main() { solve();
return 0; }
|