-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
145 lines (116 loc) · 4.09 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include "dualquat.hpp"
#include <random>
#define NUM_TESTS (1<<22)
#define THRESHOLD (1E-10)
int main () {
std::mt19937 engine;
engine.seed(0);
std::uniform_real_distribution<double> dist(-1, 1);
for (size_t i = 0; i < NUM_TESTS; i++) {
quat<double> Q(dist(engine), dist(engine), dist(engine), dist(engine)), R;
Q = Q.N();
// check if unit
if(!Q.isunit()) {
std::cout << "not unit" << std::endl;
}
// check +,-,*,/
R = (Q-Q*4+Q)/2+Q;
if (R.dot(R) > THRESHOLD) {
std::cout << "+,-,*,/ " << R.dot(R) << std::endl;
R.print();
}
// check left inverse
R = (Q.I()*Q)-quat<double>();
if (R.dot(R) > THRESHOLD) {
std::cout << "left inverse" << R.dot(R) << std::endl;
R.print();
}
// check right inverse
R = (Q*Q.I())-quat<double>();
if (R.dot(R) > THRESHOLD) {
std::cout << "right inverse" << R.dot(R) << std::endl;
R.print();
}
// check left conjugate inverse
R = (Q.C()*Q)-quat<double>();
if (R.dot(R) > THRESHOLD) {
std::cout << "left conjugate inverse" << R.dot(R) << std::endl;
R.print();
}
// check right conjugate inverse
R = (Q*Q.C())-quat<double>();
if (R.dot(R) > THRESHOLD) {
std::cout << "right conjugate inverse" << R.dot(R) << std::endl;
R.print();
}
// check log exp
R = Q.log().exp()-Q;
if (R.dot(R) > THRESHOLD) {
std::cout << "log exp " << R.dot(R) << std::endl;
R.print();
}
// check numexp exp
R = Q.log().numexp()-Q.log().exp();
if (R.dot(R) > THRESHOLD) {
std::cout << "numexp exp " << R.dot(R) << std::endl;
}
const double eucdist = Q.eucdist(Q*(-1.0)),
logdist = Q.logdist(Q*(-1.0));
if (eucdist > THRESHOLD || logdist > THRESHOLD)
std::cout << "distances: " << eucdist << ", " << logdist << std::endl;
}
for (size_t i = 0; i < NUM_TESTS; i++) {
dualquat<double> Q(dist(engine), dist(engine), dist(engine), dist(engine),
dist(engine), dist(engine), dist(engine), dist(engine)), R;
Q = Q.N();
// check if unit
if(!Q.isunit()) {
std::cout << "not unit" << std::endl;
}
// check +,-,*,/
R = (Q-Q*4+Q)/2+Q;
if (R.dot(R) > THRESHOLD) {
std::cout << "+,-,*,/ " << R.dot(R) << std::endl;
R.print();
}
// check left inverse
R = (Q.I()*Q)-dualquat<double>();
if (R.dot(R) > THRESHOLD) {
std::cout << "left inverse" << R.dot(R) << std::endl;
R.print();
}
// check right inverse
R = (Q*Q.I())-dualquat<double>();
if (R.dot(R) > THRESHOLD) {
std::cout << "right inverse" << R.dot(R) << std::endl;
R.print();
}
// check left conjugate inverse
R = (Q.C()*Q)-dualquat<double>();
if (R.dot(R) > THRESHOLD) {
std::cout << "left conjugate inverse" << R.dot(R) << std::endl;
R.print();
}
// check right conjugate inverse
R = (Q*Q.C())-dualquat<double>();
if (R.dot(R) > THRESHOLD) {
std::cout << "right conjugate inverse" << R.dot(R) << std::endl;
R.print();
}
// check log exp
R = Q.log().exp()-Q;
if (R.dot(R) > THRESHOLD) {
std::cout << "log exp " << R.dot(R) << std::endl;
R.print();
}
// check numexp exp
R = Q.log().numexp()-Q.log().exp();
if (R.dot(R) > THRESHOLD) {
std::cout << "numexp exp " << R.dot(R) << std::endl;
}
const double eucdist = Q.eucdist(Q*(-1.0)),
logdist = Q.logdist(Q*(-1.0));
if (eucdist > THRESHOLD || logdist > THRESHOLD)
std::cout << "distances: " << eucdist << ", " << logdist << std::endl;
}
}