quaternion_functions.h

Go to the documentation of this file.
00001 /* -*- C++ -*- ------------------------------------------------------------
00002  
00003 Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
00004 
00005 The Configurable Math Library (CML) is distributed under the terms of the
00006 Boost Software License, v1.0 (see cml/LICENSE for details).
00007 
00008  *-----------------------------------------------------------------------*/
00017 #ifndef quaternion_functions_h
00018 #define quaternion_functions_h
00019 
00020 #include <cml/mathlib/checking.h> // For CheckQuat()
00021 #include <cml/mathlib/epsilon.h>
00022 #include <cml/util.h> // For acos_safe()
00023 
00024 namespace cml {
00025 
00027 template<typename E, class AT, class OT, class CT>
00028 inline typename quaternion<E,AT,OT,CT>::value_type
00029 real(const quaternion<E,AT,OT,CT>& q)
00030 {
00031     return q.real();
00032 }
00033 
00035 template<typename XprT>
00036 inline typename et::QuaternionXpr<XprT>::value_type
00037 real(const et::QuaternionXpr<XprT>& e)
00038 {
00039     return e.real();
00040 }
00041 
00043 template<typename E, class AT, class OT, class CT>
00044 inline typename quaternion<E,AT,OT,CT>::imaginary_type
00045 imaginary(const quaternion<E,AT,OT,CT>& q)
00046 {
00047     return q.imaginary();
00048 }
00049 
00051 template<typename XprT>
00052 //inline typename et::QuaternionXpr<XprT>::temporary_type
00053 inline typename et::QuaternionXpr<XprT>::imaginary_type
00054 imaginary(const et::QuaternionXpr<XprT>& e)
00055 {
00056     return e.imaginary();
00057 }
00058 
00060 template<typename E, class AT, class OT, class CT>
00061 inline typename quaternion<E,AT,OT,CT>::value_type
00062 norm(const quaternion<E,AT,OT,CT>& arg)
00063 {
00064     return arg.length_squared();
00065 }
00066 
00068 template<typename XprT>
00069 inline typename XprT::value_type
00070 norm(QUATXPR_ARG_TYPE arg)
00071 {
00072     return arg.length_squared();
00073 }
00074 
00076 template<typename E, class AT, class OT, class CT>
00077 inline typename quaternion<E,AT,OT,CT>::value_type
00078 length_squared(const quaternion<E,AT,OT,CT>& arg)
00079 {
00080     return arg.length_squared();
00081 }
00082 
00084 template<typename XprT>
00085 inline typename XprT::value_type
00086 length_squared(QUATXPR_ARG_TYPE arg)
00087 {
00088     return arg.length_squared();
00089 }
00090 
00092 template<typename E, class AT, class OT, class CT>
00093 inline typename quaternion<E,AT,OT,CT>::value_type
00094 length(const quaternion<E,AT,OT,CT>& arg)
00095 {
00096     return arg.length();
00097 }
00098 
00100 template<typename XprT>
00101 inline typename XprT::value_type
00102 length(QUATXPR_ARG_TYPE arg)
00103 {
00104     return arg.length();
00105 }
00106 
00111 template<typename E, class AT, class OT, class CT>
00112 inline quaternion<E,AT,OT,CT>
00113 normalize(const quaternion<E,AT,OT,CT>& arg)
00114 {
00115     typename quaternion<E,AT,OT,CT>::temporary_type result(arg);
00116     result.normalize();
00117     return result;
00118 }
00119 
00121 template<typename XprT>
00122 inline typename XprT::temporary_type
00123 normalize(QUATXPR_ARG_TYPE arg)
00124 {
00125     return arg.normalize();
00126 }
00127 
00132 template<typename E, class AT, class OT, class CT>
00133 inline quaternion<E,AT,OT,CT>
00134 identity(const quaternion<E,AT,OT,CT>& arg)
00135 {
00136     typename quaternion<E,AT,OT,CT>::temporary_type result(arg);
00137     result.identity();
00138     return result;
00139 }
00140 
00143 template < class QuatT >
00144 typename QuatT::temporary_type log(
00145     const QuatT& q,
00146     typename QuatT::value_type tolerance =
00147         epsilon<typename QuatT::value_type>::placeholder())
00148 {
00149     detail::CheckQuat(q);
00150 
00151     return q.log();
00152 }
00153 
00156 template < class QuatT >
00157 typename QuatT::temporary_type exp(
00158     const QuatT& q,
00159     typename QuatT::value_type tolerance =
00160         epsilon<typename QuatT::value_type>::placeholder())
00161 {
00162     detail::CheckQuat(q);
00163 
00164     return q.exp();
00165 }
00166 
00167 } // namespace cml
00168 
00169 #endif
00170 
00171 // -------------------------------------------------------------------------
00172 // vim:ft=cpp

Generated on Sat Jul 18 19:35:31 2009 for CML 1.0 by  doxygen 1.5.9