-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathrotate_around_center.cpp
33 lines (28 loc) · 1017 Bytes
/
rotate_around_center.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
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include <Eigen/Core>
#include <Eigen/Geometry>
// https://stackoverflow.com/questions/38274455/eigen-perform-an-3d-rotation-around-an-axis-w-and-anchored-at-a-point-p
// https://stackoverflow.com/questions/1727881/how-to-use-the-pi-constant-in-c
// https://stackoverflow.com/questions/6563810/m-pi-works-with-math-h-but-not-with-cmath-in-visual-studio
int main(int argc, char** argv) {
Eigen::Vector3f point(0, 0, 1);
Eigen::Vector3f axis(1, 0, 0);
float theta = 90.0f / 180.0f * M_PI;
Eigen::Vector3f rotation_center(0, 1, 0);
Eigen::Affine3f affine = Eigen::Translation3f(rotation_center) *
Eigen::AngleAxisf(theta, axis) *
Eigen::Translation3f(-rotation_center);
std::cout << "original point: " << point << std::endl;
std::cout << "rotated point: " << affine * point << std::endl;
return 0;
}
/*
original point: 0
0
1
rotated point: 0
0
-1
*/