11 double length = std::sqrt(
dot(vec, 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 = 1
e-12;
42 double normAxis = std::sqrt(
dot(axis, axis));
45 if (std::abs(
dot(u, ref) - 1.0) < tol) {
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);
79 return result *= other;
88 for (
unsigned i = 0; i < 3; i++)
89 res += imagThis(i) * imagOther(i);
90 double dp = std::sqrt(res);
93 (*
this)(0) * other(0) - dp,
94 (*
this)(0) * imagOther + other(0) * imagThis +
cross(imagThis, imagOther));
106 if (this->
Norm() < 1
e-12)
108 "Quaternion::normalize()",
"length of quaternion less than 1e-12");
111 (*this) /= this->
length();
126 "Quaternion::rotate()",
127 "quaternion isn't unit quaternion. Norm: " + std::to_string(this->
Norm()));
132 return ((*
this) * (quat * (*this).
conjugate())).imag();
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));
Vector3D cross(const Vector3D &lhs, const Vector3D &rhs)
Vector cross product.
double dot(const Vector3D &lhs, const Vector3D &rhs)
Vector dot product.
Quaternion getQuaternion(ippl::Vector< double, 3 > u, ippl::Vector< double, 3 > ref)
boost::numeric::ublas::matrix< double > matrix_t
constexpr double e
The value of.
constexpr double pi
The value of.
Implementations for FFT constructor/destructor and transforms.
KOKKOS_INLINE_FUNCTION Vector< T, Dim > max(const Vector< T, Dim > &a, const Vector< T, Dim > &b)
Quaternion conjugate() const
Quaternion inverse() const
ippl::Vector< double, 3 > rotate(const ippl::Vector< double, 3 > &) const
Quaternion & operator*=(const Quaternion &)
Quaternion operator/(const double &) const
Quaternion operator*(const double &) const
matrix_t getRotationMatrix() const
ippl::Vector< double, 3 > imag() const