-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtestCompatibility.hpp
61 lines (54 loc) · 2.21 KB
/
testCompatibility.hpp
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
#pragma once
#include <iostream>
#include <cmath>
#include <sstream>
#include <string>
#include "quaternion.hpp"
#include "matrix.hpp"
#include "test.hpp"
#include <iomanip>
void TestCompatibility(){
int numErrors = 0;
// Testing compatibility of matrix-quaternion structures:
//
// Start from v = (0., 1., 0.) || y, and rotate by 15 degrees and then 20 degrees around x axis.
// Matrix :
{
//M1 =
/*[ 1.0000000, 0.0000000, 0.0000000;
0.0000000, -0.7596879, -0.6502879;
0.0000000, 0.6502879, -0.7596879 ]
//M2 = [ 1.0000000, 0.0000000, 0.0000000;
0.0000000, 0.4080821, -0.9129453;
0.0000000, 0.9129453, 0.4080821 ]*/
// quaternion: [ x = 0.6502878, y = 0, z = 0, w = -0.7596879 ]
Matrix3<double> m1({1., 0., 0., 0. , -0.7596879 , -0.6502879, 0., 0.6502879, -0.7596879});
Matrix3<double> m2({1., 0., 0., 0. , 0.4080821 , -0.9129453, 0., 0.9129453, 0.4080821});
Matrix3<double> mComposite = m1*m2;
std::array<double,3> v{0., 1., 0.};
std::optional<std::array<double,3>> one = m1*v;
std::optional<std::array<double,3>> result1 = m2*(one.value());
std::optional<std::array<double,3>> result2 = mComposite*v;
if(!areEqual(result1.value(), result2.value())){
numErrors++;
std::cout << "Matrix composition failed. \n";
}
//rotation by 35 degrees:
/*[ 1.0000000, 0.0000000, 0.0000000;
0.0000000, -0.9036922, 0.4281827;
0.0000000, -0.4281827, -0.9036922 ]*/
Matrix3<double> m({1., 0., 0., 0. , -0.9036922 , 0.4281827, 0., -0.4281827, -0.9036922});
std::optional<std::array<double,3>> two = m*v;
if(!areEqual(two.value(), result2.value())){
numErrors++;
std::cout << "Matrix composition (35degs) failed. \n";
}
//Same with the quaternion:
quaternion<double> q { 0.21944, -0.975626, 0., 0.};
std::optional<std::array<double,3>> three = rotateByQuaternion(q, v);
if(!areEqual(*three, *result2)){
numErrors++;
std::cout << "Matrix composition (not equal to quaternion) failed. \n";
}
}
}