ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
vec_rotate.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19#ifndef UTILS_VEC_ROTATE_HPP
20#define UTILS_VEC_ROTATE_HPP
21
22#include <boost/qvm/quat_vec_operations.hpp>
23
24#include "utils/Vector.hpp"
25#include "utils/math/sqr.hpp"
26#include "utils/quaternion.hpp"
27
28#include <cmath>
29#include <tuple>
30
31namespace Utils {
32/**
33 * @brief Rotate a vector around an axis.
34 *
35 * @param axis The axis to rotate about
36 * @param angle Angle to rotate
37 * @param vector Vector to act on
38 * @return Rotated vector
39 */
40inline Vector3d vec_rotate(const Vector3d &axis, double angle,
41 const Vector3d &vector) {
42 if (std::abs(angle) > std::numeric_limits<double>::epsilon()) {
43 Quaternion<double> q = boost::qvm::rot_quat(axis, angle);
44 return q * vector;
45 }
46 return vector;
47}
48
49/**
50 * @brief Determine the angle between two vectors.
51 */
52inline double angle_between(Vector3d const &v1, Vector3d const &v2) {
53 return std::acos(v1 * v2 / std::sqrt(v1.norm2() * v2.norm2()));
54}
55
56} // namespace Utils
57
58#endif
Vector implementation and trait types for boost qvm interoperability.
T norm2() const
Definition Vector.hpp:137
Vector3d vec_rotate(const Vector3d &axis, double angle, const Vector3d &vector)
Rotate a vector around an axis.
double angle_between(Vector3d const &v1, Vector3d const &v2)
Determine the angle between two vectors.
Quaternion implementation and trait types for boost qvm interoperability.
Quaternion representation.