10 ippl::Vector<double, 3> normalize(
const ippl::Vector<double, 3>& vec) {
23 (*this)(0) = std::sqrt(std::max(0.0, 1 + M(0, 0) + M(1, 1) + M(2, 2))) / 2;
24 (*this)(1) = std::sqrt(std::max(0.0, 1 + M(0, 0) - M(1, 1) - M(2, 2))) / 2;
25 (*this)(2) = std::sqrt(std::max(0.0, 1 - M(0, 0) + M(1, 1) - M(2, 2))) / 2;
26 (*this)(3) = std::sqrt(std::max(0.0, 1 - M(0, 0) - M(1, 1) + M(2, 2))) / 2;
28 std::abs(M(2, 1) - M(1, 2)) > 0 ? std::copysign((*
this)(1), M(2, 1) - M(1, 2)) : 0.0;
30 std::abs(M(0, 2) - M(2, 0)) > 0 ? std::copysign((*
this)(2), M(0, 2) - M(2, 0)) : 0.0;
32 std::abs(M(1, 0) - M(0, 1)) > 0 ? std::copysign((*
this)(3), M(1, 0) - M(0, 1)) : 0.0;
36 const double tol = 1e-12;
41 ippl::Vector<double, 3> axis =
cross(u, ref);
42 double normAxis = std::sqrt(
dot(axis, axis));
45 if (std::abs(
dot(u, ref) - 1.0) < tol) {
46 return Quaternion(1.0, ippl::Vector<double, 3>(0.0));
50 double u = rand() / RAND_MAX;
52 axis(0) = std::sqrt(1 - u * u) * std::cos(v);
53 axis(1) = std::sqrt(1 - u * u) * std::sin(v);
55 }
while (std::abs(
dot(axis, ref)) > 0.9);
57 axis -=
dot(axis, ref) * ref;
58 axis = normalize(axis);
65 double cosAngle = sqrt(0.5 * (1 +
dot(u, ref)));
66 double sinAngle = sqrt(1 - cosAngle * cosAngle);
140 mat(0, 0) = 1 - 2 * (rot(2) * rot(2) + rot(3) * rot(3));
141 mat(0, 1) = 2 * (-rot(0) * rot(3) + rot(1) * rot(2));
142 mat(0, 2) = 2 * (rot(0) * rot(2) + rot(1) * rot(3));
143 mat(1, 0) = 2 * (rot(0) * rot(3) + rot(1) * rot(2));
144 mat(1, 1) = 1 - 2 * (rot(1) * rot(1) + rot(3) * rot(3));
145 mat(1, 2) = 2 * (-rot(0) * rot(1) + rot(2) * rot(3));
146 mat(2, 0) = 2 * (-rot(0) * rot(2) + rot(1) * rot(3));
147 mat(2, 1) = 2 * (rot(0) * rot(1) + rot(2) * rot(3));
148 mat(2, 2) = 1 - 2 * (rot(1) * rot(1) + rot(2) * rot(2));