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
| #include<cmath> #include<eigen3/Eigen/Core> #include<eigen3/Eigen/Dense> #include<iostream>
#define M_PI 3.14159265358979323846
int main(){
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; 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; std::cout << "Example of output \n"; std::cout << i << std::endl; Eigen::Matrix3f sum1 = i + j; std::cout << "Matrix sum" << std::endl; std::cout << sum1 << std::endl; std::cout << "Std sum" << std::endl; std::cout << i + j << std::endl; Eigen::Matrix3f scalar_mult = i * 2.0; std::cout << "Matrix i * 2.0:\n" << scalar_mult << std::endl; Eigen::Matrix3f matrix_mult = i * j; std::cout << "Matrix i * j:\n" << matrix_mult << std::endl; Eigen::Vector3f matrix_vector_mult = i * v; std::cout << "Matrix i * Vector v:\n" << matrix_vector_mult << std::endl;
Eigen::Vector3f P(2.0, 1.0, 1.0); double theta = M_PI / 4.0; Eigen::Matrix3f rotation; rotation << cos(theta), -sin(theta), 0, sin(theta), cos(theta), 0, 0, 0, 1; Eigen::Matrix3f translation; translation << 1, 0, 1, 0, 1, 2, 0, 0, 1;
Eigen::Vector3f P_transformed = translation * rotation * P; std::cout << P_transformed << std::endl;
return 0; }
|