]>
Dogcows Code - chaz/yoink/blob - cml/quaternion/quaternion_functions.h
1 /* -*- C++ -*- ------------------------------------------------------------
3 Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
5 The Configurable Math Library (CML) is distributed under the terms of the
6 Boost Software License, v1.0 (see cml/LICENSE for details).
8 *-----------------------------------------------------------------------*/
10 * @brief Functions on quaternions.
12 * @todo The functions that return quaternions and vectors should be changed
13 * to return quaternion expression nodes, as should the corresponding
17 #ifndef quaternion_functions_h
18 #define quaternion_functions_h
20 #include <cml/mathlib/checking.h> // For CheckQuat()
21 #include <cml/mathlib/epsilon.h>
22 #include <cml/util.h> // For acos_safe()
26 /** Returns the real part of the quaternion. */
27 template<typename E
, class AT
, class OT
, class CT
>
28 inline typename quaternion
<E
,AT
,OT
,CT
>::value_type
29 real(const quaternion
<E
,AT
,OT
,CT
>& q
)
34 /** Returns the real (scalar) part of the QuaternionXpr. */
35 template<typename XprT
>
36 inline typename
et::QuaternionXpr
<XprT
>::value_type
37 real(const et::QuaternionXpr
<XprT
>& e
)
42 /** Returns the imaginary (vector) part of the quaternion. */
43 template<typename E
, class AT
, class OT
, class CT
>
44 inline typename quaternion
<E
,AT
,OT
,CT
>::imaginary_type
45 imaginary(const quaternion
<E
,AT
,OT
,CT
>& q
)
50 /** Returns the imaginary (vector) part of the QuaternionXpr. */
51 template<typename XprT
>
52 //inline typename et::QuaternionXpr<XprT>::temporary_type
53 inline typename
et::QuaternionXpr
<XprT
>::imaginary_type
54 imaginary(const et::QuaternionXpr
<XprT
>& e
)
59 /** Cayley norm of a quaternion. */
60 template<typename E
, class AT
, class OT
, class CT
>
61 inline typename quaternion
<E
,AT
,OT
,CT
>::value_type
62 norm(const quaternion
<E
,AT
,OT
,CT
>& arg
)
64 return arg
.length_squared();
67 /** Cayley norm of a QuaternionXpr. */
68 template<typename XprT
>
69 inline typename
XprT::value_type
70 norm(QUATXPR_ARG_TYPE arg
)
72 return arg
.length_squared();
75 /** Squared length of a quaternion. */
76 template<typename E
, class AT
, class OT
, class CT
>
77 inline typename quaternion
<E
,AT
,OT
,CT
>::value_type
78 length_squared(const quaternion
<E
,AT
,OT
,CT
>& arg
)
80 return arg
.length_squared();
83 /** Squared length of a quaternion expr. */
84 template<typename XprT
>
85 inline typename
XprT::value_type
86 length_squared(QUATXPR_ARG_TYPE arg
)
88 return arg
.length_squared();
91 /** Length of a quaternion. */
92 template<typename E
, class AT
, class OT
, class CT
>
93 inline typename quaternion
<E
,AT
,OT
,CT
>::value_type
94 length(const quaternion
<E
,AT
,OT
,CT
>& arg
)
99 /** Length of a quaternion expr. */
100 template<typename XprT
>
101 inline typename
XprT::value_type
102 length(QUATXPR_ARG_TYPE arg
)
107 /** Normalize a quaternion.
109 * The input quaternion is not changed.
111 template<typename E
, class AT
, class OT
, class CT
>
112 inline quaternion
<E
,AT
,OT
,CT
>
113 normalize(const quaternion
<E
,AT
,OT
,CT
>& arg
)
115 typename quaternion
<E
,AT
,OT
,CT
>::temporary_type
result(arg
);
120 /** Normalize a quaternion expr. */
121 template<typename XprT
>
122 inline typename
XprT::temporary_type
123 normalize(QUATXPR_ARG_TYPE arg
)
125 return arg
.normalize();
128 /** Set a quaternion to the multiplicative identity.
130 * The input quaternion is not changed.
132 template<typename E
, class AT
, class OT
, class CT
>
133 inline quaternion
<E
,AT
,OT
,CT
>
134 identity(const quaternion
<E
,AT
,OT
,CT
>& arg
)
136 typename quaternion
<E
,AT
,OT
,CT
>::temporary_type
result(arg
);
141 /** Log of a quaternion or quaternion expression.
143 template < class QuatT
>
144 typename
QuatT::temporary_type
log(
146 typename
QuatT::value_type tolerance
=
147 epsilon
<typename
QuatT::value_type
>::placeholder())
149 detail::CheckQuat(q
);
154 /** Exponential function of a quaternion or quaternion expression.
156 template < class QuatT
>
157 typename
QuatT::temporary_type
exp(
159 typename
QuatT::value_type tolerance
=
160 epsilon
<typename
QuatT::value_type
>::placeholder())
162 detail::CheckQuat(q
);
171 // -------------------------------------------------------------------------
This page took 0.041574 seconds and 4 git commands to generate.