-
Notifications
You must be signed in to change notification settings - Fork 0
/
rot.h
58 lines (48 loc) · 1.74 KB
/
rot.h
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
/**
* rot.h
* Computing rotations in 3D
*
* @author Manuel Infosec
* @version 1.0
*/
#ifndef ROT_H
#include <cmath>
#include "matrix.h"
/**
* Euler Angle class, for computing rotations in 3D
*/
class euler_angle {
matrix<long double>m;
/**
* Constructor for an euler_angle
*
* @param theta_x the rotation about the x axis, in radians
* @param theta_y the rotation about the y axis, in radians
* @param theta_z the rotation about the z axis, in radians
*/
euler_angle(long double theta_x, long double theta_y, long double theta_z) {
m = matrix<long double>(3, 3);
matrix<long double> x = matrix<long double>(3, 3);
x(0, 0) = 1.0; x(0, 1) = 0.0; x(0, 2) = 0.0;
x(1, 0) = 0.0; x(1, 1) = cos(theta_x); x(0, 2) = -sin(theta_x);
x(2, 0) = 0.0; x(2, 1) = sin(theta_x); x(2, 2) = cos(theta_x);
matrix<long double> y = matrix<long double>(3, 3);
y(0, 0) = cos(theta_y); y(0, 1) = 0.0; y(0, 2) = sin(theta_y);
y(1, 0) = 0.0; y(1, 1) = 1.0; y(1, 2) = 0.0;
y(2, 0) = -sin(theta_y); y(2, 1) = 0.0; y(2, 2) = cos(theta_y);
matrix<long double> z = matrix<long double>(3, 3);
z(0, 0) = cos(theta_z); z(0, 1) = -sin(theta_z); z(0, 2) = 0.0;
z(1, 0) = sin(theta_z); z(1, 1) = cos(theta_z); z(1, 2) = 0.0;
z(2, 0) = 0.0; z(2, 1) = 0.0; z(2, 2) = 1.0;
m = z * y * x;
}
/**
* Returns the rotational matrix
*
* @return a 3x3 matrix representing the Euler Angle.
*/
inline matrix<long double> to_matrix() const {
return m;
}
}
#endif