-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
58 lines (53 loc) · 1.77 KB
/
main.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
#include <cmath>
#include <eigen3/Eigen/Core>
#include <eigen3/Eigen/Dense>
#include <iostream>
int main()
{
// Basic Example of cpp
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;
// Example of vector
std::cout << "Example of vector \n";
// vector definition
Eigen::Vector3f v(1.0f, 2.0f, 3.0f);
Eigen::Vector3f w(1.0f, 0.0f, 0.0f);
// vector output
std::cout << "Example of output \n";
std::cout << v << std::endl;
// vector add
std::cout << "Example of add \n";
std::cout << v + w << std::endl;
// vector scalar multiply
std::cout << "Example of scalar multiply \n";
std::cout << v * 3.0f << std::endl;
std::cout << 2.0f * v << std::endl;
// Example of matrix
std::cout << "Example of matrix \n";
// matrix definition
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;
// matrix output
std::cout << "Example of output \n";
std::cout << i << std::endl;
// matrix add i + j
std::cout << (i + j) << std::endl;
// matrix scalar multiply i * 2.0
std::cout << (i * 2.0) << std::endl;
// matrix multiply i * j
std::cout << (i * j) << std::endl;
// matrix multiply vector i * v
std::cout << (i * v) << std::endl;
std::cout << "transformed" << std::endl;
Eigen::Vector3f p(2.0, 1.0, 1.0);
Eigen::Matrix3f m_transform;
m_transform << sqrt(0.5), -sqrt(0.5), 1, sqrt(0.5), sqrt(0.5), 2, 0, 0, 1;
std::cout << (m_transform * p) << std::endl;
return 0;
}