10 #ifndef EIGEN_LGSM_ROTATIONS_H    11 #define EIGEN_LGSM_ROTATIONS_H    13 template <
typename QuatDerived, 
typename Derived>
    15     const QuaternionBase<QuatDerived>& q,
    16     const MatrixBase<Derived>& n,
    17     typename internal::traits<Derived>::Scalar& theta)
    19   typedef typename internal::traits<Derived>::Scalar Scalar;
    20   typedef typename internal::traits<QuatDerived>::PlainObject Quaternion;
    21   typedef Matrix<Scalar, 3, 3> AdjointMatrix;
    23   const AdjointMatrix& R = q.toRotationMatrix();
    26   Scalar tr1 = (R(2,1)-R(1,2))*n[0] + (R(0,2)-R(2,0))*n[1] + (R(1,0)-R(0,1))*n[2];
    28   Scalar tr2 =  n[0] * (R(0,0)*n[0]+R(1,0)*n[1]+R(2,0)*n[2])
    29     + n[1] * (R(0,1)*n[0]+R(1,1)*n[1]+R(2,1)*n[2])
    30     + n[2] * (R(0,2)*n[0]+R(1,2)*n[1]+R(2,2)*n[2])
    31     - R(0,0) - R(1,1) - R(2,2);
    33   Scalar alpha = atan2(tr1, tr2);
    35   Scalar s = sin(theta);
    36   Scalar c = cos(theta);
    40   Rp(0,0) =          + ic*n[0]*n[0] + c;
    41   Rp(0,1) = -s*n[2] + ic*n[0]*n[1];
    42   Rp(0,2) =  s*n[1] + ic*n[0]*n[2];
    43   Rp(1,0) =  s*n[2] + ic*n[1]*n[0];
    44   Rp(1,1) =          + ic*n[1]*n[1] + c;
    45   Rp(1,2) = -s*n[0] + ic*n[1]*n[2];
    46   Rp(2,0) = -s*n[1] + ic*n[2]*n[0];
    47   Rp(2,1) =  s*n[0] + ic*n[2]*n[1];
    48   Rp(2,2) =          + ic*n[2]*n[2] + c;
    50   return Quaternion(Rp);
    53 template <
typename QuatDerived, 
typename Derived>
    55     const QuaternionBase<QuatDerived>& q,
    56     const MatrixBase<Derived>& v)
    58   typename internal::traits<Derived>::Scalar tmp;
    62   template <
typename QuatDerived, 
typename Derived>
    63 inline bool isRotationAround(
const QuaternionBase<QuatDerived>& q, 
const MatrixBase<Derived>& v)
    65   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
    66   typedef typename QuaternionBase<QuatDerived>::Scalar Scalar;
    67   AngleAxis<Scalar> aa(q);
    68   return aa.axis().isApprox(v) || aa.axis().isApprox(-v) || aa.angle() == 0;  
    71   template <
typename QuatDerived, 
typename Derived>
    72 inline typename QuaternionBase<QuatDerived>::Scalar 
getAngleAround(
const QuaternionBase<QuatDerived>& q, 
const MatrixBase<Derived>& v)
    74   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
    76   typedef typename QuaternionBase<QuatDerived>::Scalar Scalar;
    77   AngleAxis<Scalar> aa(q);
    78   return aa.angle()*(aa.axis().dot(v));
 QuaternionBase< QuatDerived >::Scalar getAngleAround(const QuaternionBase< QuatDerived > &q, const MatrixBase< Derived > &v)
internal::traits< QuatDerived >::PlainObject projectRotation(const QuaternionBase< QuatDerived > &q, const MatrixBase< Derived > &n, typename internal::traits< Derived >::Scalar &theta)
bool isRotationAround(const QuaternionBase< QuatDerived > &q, const MatrixBase< Derived > &v)