Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
RationalOrthogonalApproximation.cpp
Go to the documentation of this file.
1/* This file is part of PIL, the Particle Interaction Library.
2 *
3 *
4 * MODEL is distributed without any warranty under the
5 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
6 */
7
8#ifndef model_RationalOrthogonalApproximation_cpp_
9#define model_RationalOrthogonalApproximation_cpp_
10
12
13namespace model
14{
23
24 /**********************************************************************/
25 std::pair<Eigen::Matrix<long int, 3, 3>, long int> RationalOrthogonalApproximation::compute(const double &angle,
26 const Eigen::Matrix<double, 3, 1> &axis,
27 const double &maxDen)
28 {
29 const Eigen::AngleAxisd aa(angle, axis.normalized());
30 const Eigen::Quaterniond q(aa);
31
32 const double root(sqrt(fabs(maxDen)));
33
34 Eigen::Quaterniond q1(std::round(q.w() * root),
35 std::round(q.x() * root),
36 std::round(q.y() * root),
37 std::round(q.z() * root));
38
39 const double n2(q1.squaredNorm());
40 q1.normalize();
41
42 Eigen::Matrix<double, 3, 3> R(q1.toRotationMatrix());
43 Eigen::Matrix<long int, 3, 3> Q;
44 for (int i = 0; i < 3; ++i)
45 {
46 for (int j = 0; j < 3; ++j)
47 {
48 if (std::fabs(R(i, j) * n2 - std::round(R(i, j) * n2)) > FLT_EPSILON)
49 {
50 std::cout << i << " " << j << std::endl;
51 std::cout << R(i, j) * n2 << std::endl;
52 std::cout << std::round(R(i, j) * n2) << std::endl;
53 std::cout << R * n2 << std::endl;
54 assert(0 && "RationalOrthogonalApproximation failed.");
55 }
56 else
57 {
58 Q(i, j) = std::round(R(i, j) * n2);
59 }
60 }
61 }
62
63 return std::make_pair(Q, n2);
64 }
65
66
67 /**********************************************************************/
69 const Eigen::Matrix<double,3,1>& axis,
70 const long int& maxDen) :
71 /* init */ resultPair(compute(angle,axis,maxDen)),
72 /* init */ m(resultPair.first),
73 /* init */ den(resultPair.second)
74 {
75
76 }
77}
78#endif
const Eigen::Matrix< long int, 3, 3 > & m
RationalOrthogonalApproximation(const double &angle, const Eigen::Matrix< double, 3, 1 > &axis, const long int &maxDen)
the magnitude of the R vector q
Q
REAL aa[4]
int j
REAL angle
int axis
int i
vertex first