51 bool sanitize_cosine =
false) {
53 auto cos_phi = (vec1 * vec2) / std::sqrt(vec1.
norm2() * vec2.
norm2());
54 if (sanitize_cosine) {
73template <
typename ForceFactor>
74std::tuple<Utils::Vector3d, Utils::Vector3d, Utils::Vector3d>
76 ForceFactor forceFactor,
bool sanitize_cosine) {
77 auto const d1 = vec1.
norm();
78 auto const d2 = vec2.
norm();
79 auto cos_phi = (vec1 * vec2) / (d1 * d2);
80 if (sanitize_cosine) {
84 auto const fac = forceFactor(cos_phi);
86 auto const v1 = vec1 / d1;
87 auto const v2 = vec2 / d2;
88 auto f_left = (fac / d1) * (v1 * cos_phi - v2);
89 auto f_right = (fac / d2) * (v2 * cos_phi - v1);
90 auto f_mid = -(f_left + f_right);
91 return std::make_tuple(f_mid, f_left, f_right);
Vector implementation and trait types for boost qvm interoperability.
std::tuple< Utils::Vector3d, Utils::Vector3d, Utils::Vector3d > angle_generic_force(Utils::Vector3d const &vec1, Utils::Vector3d const &vec2, ForceFactor forceFactor, bool sanitize_cosine)
Compute a three-body angle interaction force.
constexpr auto tiny_cos_angle_value
Tiny angle cutoff for cosine calculations.
double calc_cosine(Utils::Vector3d const &vec1, Utils::Vector3d const &vec2, bool sanitize_cosine=false)
Compute the cosine of the angle between three particles.
constexpr T norm2() const