/* -*- C++ -*- ------------------------------------------------------------ Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/ The Configurable Math Library (CML) is distributed under the terms of the Boost Software License, v1.0 (see cml/LICENSE for details). *-----------------------------------------------------------------------*/ /** @file * @brief Functions on quaternions. * * @todo The functions that return quaternions and vectors should be changed * to return quaternion expression nodes, as should the corresponding * class methods. */ #ifndef quaternion_functions_h #define quaternion_functions_h #include // For CheckQuat() #include #include // For acos_safe() namespace cml { /** Returns the real part of the quaternion. */ template inline typename quaternion::value_type real(const quaternion& q) { return q.real(); } /** Returns the real (scalar) part of the QuaternionXpr. */ template inline typename et::QuaternionXpr::value_type real(const et::QuaternionXpr& e) { return e.real(); } /** Returns the imaginary (vector) part of the quaternion. */ template inline typename quaternion::imaginary_type imaginary(const quaternion& q) { return q.imaginary(); } /** Returns the imaginary (vector) part of the QuaternionXpr. */ template //inline typename et::QuaternionXpr::temporary_type inline typename et::QuaternionXpr::imaginary_type imaginary(const et::QuaternionXpr& e) { return e.imaginary(); } /** Cayley norm of a quaternion. */ template inline typename quaternion::value_type norm(const quaternion& arg) { return arg.length_squared(); } /** Cayley norm of a QuaternionXpr. */ template inline typename XprT::value_type norm(QUATXPR_ARG_TYPE arg) { return arg.length_squared(); } /** Squared length of a quaternion. */ template inline typename quaternion::value_type length_squared(const quaternion& arg) { return arg.length_squared(); } /** Squared length of a quaternion expr. */ template inline typename XprT::value_type length_squared(QUATXPR_ARG_TYPE arg) { return arg.length_squared(); } /** Length of a quaternion. */ template inline typename quaternion::value_type length(const quaternion& arg) { return arg.length(); } /** Length of a quaternion expr. */ template inline typename XprT::value_type length(QUATXPR_ARG_TYPE arg) { return arg.length(); } /** Normalize a quaternion. * * The input quaternion is not changed. */ template inline quaternion normalize(const quaternion& arg) { typename quaternion::temporary_type result(arg); result.normalize(); return result; } /** Normalize a quaternion expr. */ template inline typename XprT::temporary_type normalize(QUATXPR_ARG_TYPE arg) { return arg.normalize(); } /** Set a quaternion to the multiplicative identity. * * The input quaternion is not changed. */ template inline quaternion identity(const quaternion& arg) { typename quaternion::temporary_type result(arg); result.identity(); return result; } /** Log of a quaternion or quaternion expression. */ template < class QuatT > typename QuatT::temporary_type log( const QuatT& q, typename QuatT::value_type tolerance = epsilon::placeholder()) { detail::CheckQuat(q); return q.log(); } /** Exponential function of a quaternion or quaternion expression. */ template < class QuatT > typename QuatT::temporary_type exp( const QuatT& q, typename QuatT::value_type tolerance = epsilon::placeholder()) { detail::CheckQuat(q); return q.exp(); } } // namespace cml #endif // ------------------------------------------------------------------------- // vim:ft=cpp