quaternion_basis.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00013 #ifndef quaternion_basis_h
00014 #define quaternion_basis_h
00015
00016 #include <cml/mathlib/checking.h>
00017
00018
00019
00020 namespace cml {
00021
00023 template < class QuatT > vector< typename QuatT::value_type, fixed<3> >
00024 quaternion_get_basis_vector(const QuatT& q, size_t i)
00025 {
00026 typedef QuatT quaternion_type;
00027 typedef typename quaternion_type::value_type value_type;
00028 typedef typename quaternion_type::order_type order_type;
00029 typedef vector< value_type, fixed<3> > vector_type;
00030
00031
00032 detail::CheckQuat(q);
00033 detail::CheckIndex3(i);
00034
00035 size_t j, k;
00036 cyclic_permutation(i, i, j, k);
00037
00038
00039 const size_t W = order_type::W;
00040 const size_t I = order_type::X + i;
00041 const size_t J = order_type::X + j;
00042 const size_t K = order_type::X + k;
00043
00044 value_type j2 = q[J] + q[J];
00045 value_type k2 = q[K] + q[K];
00046
00047
00048
00049 vector_type result;
00050 result[i] = value_type(1) - q[J] * j2 - q[K] * k2;
00051 result[j] = q[I] * j2 + q[W] * k2;
00052 result[k] = q[I] * k2 - q[W] * j2;
00053 return result;
00054 }
00055
00057 template < class QuatT > vector< typename QuatT::value_type, fixed<3> >
00058 quaternion_get_x_basis_vector(const QuatT& q) {
00059 return quaternion_get_basis_vector(q,0);
00060 }
00061
00063 template < class QuatT > vector< typename QuatT::value_type, fixed<3> >
00064 quaternion_get_y_basis_vector(const QuatT& q) {
00065 return quaternion_get_basis_vector(q,1);
00066 }
00067
00069 template < class QuatT > vector< typename QuatT::value_type, fixed<3> >
00070 quaternion_get_z_basis_vector(const QuatT& q) {
00071 return quaternion_get_basis_vector(q,2);
00072 }
00073
00075 template < class QuatT, typename E, class A > void
00076 quaternion_get_basis_vectors(
00077 const QuatT& q,
00078 vector<E,A>& x,
00079 vector<E,A>& y,
00080 vector<E,A>& z)
00081 {
00082 x = quaternion_get_x_basis_vector(q);
00083 y = quaternion_get_y_basis_vector(q);
00084 z = quaternion_get_z_basis_vector(q);
00085 }
00086
00087 }
00088
00089 #endif