-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.cpp
executable file
·59 lines (41 loc) · 888 Bytes
/
utils.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
59
#include <Eigen/Geometry>
inline double wrapToPi(double angle){
double ret=angle;
while(ret>M_PI){
ret-=2*M_PI;
}
while(ret<=-M_PI){
ret+=2*M_PI;
}
return ret;
}
inline double angDiff(double thetaD, double theta){
double alpha=0;
Eigen::Vector2d nD,n;
nD<<cos(thetaD), sin(thetaD);
n<<cos(theta), sin(theta);
double alphaAbs = acos(nD.transpose()*n);
Eigen::Vector3d n3,nD3;
n3<<n(0),n(1),0;
nD3<<nD(0),nD(1),0;
Eigen::Vector3d nC3;
nC3=n3.cross(nD3);
if(nC3(2)>0){
alpha=alphaAbs;
}
else{
alpha=-alphaAbs;
}
return alpha;
}
inline Eigen::MatrixXd matrixPower(Eigen::MatrixXd& A, int exp){
Eigen::MatrixXd result = Eigen::MatrixXd::Identity(A.rows(),A.cols());
for (int i=0; i<exp;++i)
result *= A;
return result;
}
inline double sign(double x){
if(x>0) return +1;
if(x<0) return -1;
return -1;
}