19#ifndef SRC_UTILS_INCLUDE_UTILS_QUATERNION_HPP
20#define SRC_UTILS_INCLUDE_UTILS_QUATERNION_HPP
29#include <boost/qvm/deduce_quat.hpp>
30#include <boost/qvm/deduce_scalar.hpp>
31#include <boost/qvm/deduce_vec.hpp>
32#include <boost/qvm/quat.hpp>
33#include <boost/qvm/quat_access.hpp>
34#include <boost/qvm/quat_operations.hpp>
35#include <boost/qvm/quat_traits.hpp>
36#include <boost/qvm/quat_vec_operations.hpp>
38#include <boost/serialization/array.hpp>
39#include <boost/serialization/is_bitwise_serializable.hpp>
40#include <boost/serialization/level.hpp>
60 using pointer =
typename container::pointer;
67 template <
class Archive>
void serialize(Archive &ar,
const unsigned int) {
140template <
typename T,
typename U,
141 std::enable_if_t<std::is_arithmetic_v<U>,
bool> =
true>
143 return boost::qvm::operator*(a, b);
154 auto const id_mat = Utils::identity_mat<double, 3, 3>();
155 auto const v1 = normed_q * id_mat.col<0>();
156 auto const v2 = normed_q * id_mat.col<1>();
157 auto const v3 = normed_q * id_mat.col<2>();
158 return {{v1[0], v2[0], v3[0]}, {v1[1], v2[1], v3[1]}, {v1[2], v2[2], v3[2]}};
161using boost::qvm::operator*;
162using boost::qvm::operator*=;
163using boost::qvm::operator==;
164using boost::qvm::dot;
165using boost::qvm::operator/;
166using boost::qvm::operator/=;
167using boost::qvm::operator+;
168using boost::qvm::operator+=;
169using boost::qvm::operator-;
170using boost::qvm::operator-=;
178template <
class T>
struct quat_traits<
Utils::Quaternion<T>> {
182 template <std::
size_t I>
184 static_assert(I < 4,
"Invalid index into quaternion.");
188 template <std::
size_t I>
190 static_assert(I < 4,
"Invalid index into quaternion.");
206template <
typename T,
typename U>
208 using type = std::common_type_t<T, U>;
211template <
typename T,
typename U, std::
size_t N>
213 using type = std::common_type_t<T, U>;
216template <
typename T,
typename U>
221template <
typename T>
struct deduce_quat<
Utils::Quaternion<T>> {
225template <
typename T,
typename U>
Array implementation with CUDA support.
Vector implementation and trait types for boost qvm interoperability.
#define UTILS_ARRAY_BOOST_MPI_T(Container, N)
Mark array types as MPI data types.
#define UTILS_ARRAY_BOOST_BIT_S(Container, N)
Mark array types as MPI bitwise serializable.
#define UTILS_ARRAY_BOOST_CLASS(Container, N, ImplementationLevel)
Redefinition of BOOST_CLASS_IMPLEMENTATION for array types.
#define UTILS_ARRAY_BOOST_TRACK(Container, N, TrackingLevel)
Redefinition of BOOST_CLASS_TRACKING for array types.
Matrix implementation and trait types for boost qvm interoperability.
Quaternion< T > operator*(const U &b, const Quaternion< T > &a)
Product quaternion and arithmetic type.
Matrix< T, 3, 3 > rotation_matrix(Quaternion< T > const &q)
Convert quaternion to rotation matrix.
Matrix representation with static size.
Quaternion representation.
typename container::const_pointer const_pointer
constexpr pointer data()
Access to the underlying data (non const).
typename container::pointer pointer
typename Utils::Array< T, 4 > container
static Quaternion< T > zero()
Construct a zero quaternion.
static Quaternion< T > identity()
Construct an identity quaternion.
value_type norm2() const
Retrieve the square of the norm of the quaternion.
Quaternion< T > normalized() const
Retrieve a normalized copy of the quaternion.
reference operator[](std::size_t i)
Element access (non const).
typename container::reference reference
value_type operator[](std::size_t i) const
Element access (const).
void normalize()
Normalize the quaternion in place.
typename container::value_type value_type
friend class boost::serialization::access
constexpr const_pointer data() const noexcept
Access to the underlying data (const).
value_type norm() const
Retrieve the norm of the quaternion.
typename Utils::Quaternion< std::common_type_t< T, U > > type
typename Utils::Quaternion< T > type
std::common_type_t< T, U > type
std::common_type_t< T, U > type
typename Utils::Vector< std::common_type_t< T, U >, 3 > type
static scalar_type read_element_idx(std::size_t i, quat_type const &q)
static scalar_type & write_element_idx(std::size_t i, quat_type &q)
static constexpr scalar_type & write_element(quat_type &q)
static constexpr scalar_type read_element(quat_type const &q)