26 #ifndef EIGEN_QUATERNION_H
27 #define EIGEN_QUATERNION_H
37 template<
typename Other,
38 int OtherRows=Other::RowsAtCompileTime,
39 int OtherCols=Other::ColsAtCompileTime>
40 struct quaternionbase_assign_impl;
49 template<
class Derived>
54 using Base::operator*;
57 typedef typename internal::traits<Derived>::Scalar
Scalar;
59 typedef typename internal::traits<Derived>::Coefficients
Coefficients;
61 Flags = Eigen::internal::traits<Derived>::Flags
99 inline const typename internal::traits<Derived>::Coefficients&
coeffs()
const {
return derived().coeffs(); }
102 inline typename internal::traits<Derived>::Coefficients&
coeffs() {
return derived().coeffs(); }
156 template<
typename Derived1,
typename Derived2>
178 template<
class OtherDerived>
190 template<
typename NewScalarType>
191 inline typename internal::cast_return_type<Derived,Quaternion<NewScalarType> >::type
cast()
const
193 return typename internal::cast_return_type<Derived,Quaternion<NewScalarType> >::type(
derived());
196 #ifdef EIGEN_QUATERNIONBASE_PLUGIN
197 # include EIGEN_QUATERNIONBASE_PLUGIN
228 template<
typename _Scalar,
int _Options>
229 struct traits<Quaternion<_Scalar,_Options> >
231 typedef Quaternion<_Scalar,_Options> PlainObject;
232 typedef _Scalar Scalar;
233 typedef Matrix<_Scalar,4,1,_Options> Coefficients;
235 IsAligned = internal::traits<Coefficients>::Flags &
AlignedBit,
241 template<
typename _Scalar,
int _Options>
245 enum { IsAligned = internal::traits<Quaternion>::IsAligned };
251 using
Base::operator*=;
281 template<
typename Derived>
285 template<
typename OtherScalar,
int OtherOptions>
287 { m_coeffs = other.
coeffs().template cast<Scalar>(); }
289 template<
typename Derived1,
typename Derived2>
300 #ifndef EIGEN_PARSED_BY_DOXYGEN
304 INVALID_MATRIX_TEMPLATE_PARAMETERS)
321 template<
typename _Scalar,
int _Options>
322 struct traits<Map<Quaternion<_Scalar>, _Options> >:
323 traits<Quaternion<_Scalar, _Options> >
325 typedef _Scalar Scalar;
330 IsAligned = TraitsBase::IsAligned,
332 Flags = TraitsBase::Flags
338 template<
typename _Scalar,
int _Options>
339 struct traits<Map<const Quaternion<_Scalar>, _Options> >:
340 traits<Quaternion<_Scalar> >
342 typedef _Scalar Scalar;
343 typedef Map<const Matrix<_Scalar,4,1>, _Options> Coefficients;
347 IsAligned = TraitsBase::IsAligned,
363 template<
typename _Scalar,
int _Options>
365 :
public QuaternionBase<Map<const Quaternion<_Scalar>, _Options> >
373 using
Base::operator*=;
399 template<
typename _Scalar,
int _Options>
409 using
Base::operator*=;
446 template<
int Arch,
class Derived1,
class Derived2,
typename Scalar,
int _Options>
struct quat_product
451 a.
w() * b.
w() - a.
x() * b.
x() - a.
y() * b.
y() - a.
z() * b.
z(),
452 a.
w() * b.
x() + a.
x() * b.
w() + a.
y() * b.
z() - a.
z() * b.
y(),
453 a.
w() * b.
y() + a.
y() * b.
w() + a.
z() * b.
x() - a.
x() * b.
z(),
454 a.
w() * b.
z() + a.
z() * b.
w() + a.
x() * b.
y() - a.
y() * b.
x()
461 template <
class Derived>
462 template <
class OtherDerived>
466 EIGEN_STATIC_ASSERT((internal::is_same<typename Derived::Scalar, typename OtherDerived::Scalar>::value),
467 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
469 typename internal::traits<Derived>::Scalar,
470 internal::traits<Derived>::IsAligned && internal::traits<OtherDerived>::IsAligned>::run(*
this, other);
474 template <
class Derived>
475 template <
class OtherDerived>
478 derived() = derived() * other.
derived();
489 template <
class Derived>
498 Vector3 uv = this->vec().cross(v);
500 return v + this->w() * uv + this->vec().cross(uv);
503 template<
class Derived>
506 coeffs() = other.
coeffs();
510 template<
class Derived>
511 template<
class OtherDerived>
514 coeffs() = other.
coeffs();
520 template<
class Derived>
535 template<
class Derived>
536 template<
class MatrixDerived>
539 EIGEN_STATIC_ASSERT((internal::is_same<typename Derived::Scalar, typename MatrixDerived::Scalar>::value),
540 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
541 internal::quaternionbase_assign_impl<MatrixDerived>::run(*
this, xpr.derived());
548 template<
class Derived>
561 const Scalar twx = tx*this->w();
562 const Scalar twy = ty*this->w();
563 const Scalar twz = tz*this->w();
564 const Scalar txx = tx*this->x();
565 const Scalar txy = ty*this->x();
566 const Scalar txz = tz*this->x();
567 const Scalar tyy = ty*this->
y();
568 const Scalar tyz = tz*this->
y();
569 const Scalar tzz = tz*this->z();
594 template<
class Derived>
595 template<
typename Derived1,
typename Derived2>
613 c = max<Scalar>(c,-1);
626 this->vec() = axis * invs;
627 this->w() = s *
Scalar(0.5);
643 template<
typename Scalar,
int Options>
644 template<
typename Derived1,
typename Derived2>
659 template <
class Derived>
663 Scalar n2 = this->squaredNorm();
679 template <
class Derived>
689 template <
class Derived>
690 template <
class OtherDerived>
691 inline typename internal::traits<Derived>::Scalar
704 template <
class Derived>
705 template <
class OtherDerived>
711 Scalar d = this->dot(other);
731 if(d<0) scale1 = -scale1;
739 template<
typename Other>
740 struct quaternionbase_assign_impl<Other,3,3>
742 typedef typename Other::Scalar Scalar;
748 Scalar t = mat.trace();
751 t =
sqrt(t + Scalar(1.0));
752 q.
w() = Scalar(0.5)*t;
754 q.
x() = (mat.coeff(2,1) - mat.coeff(1,2)) * t;
755 q.
y() = (mat.coeff(0,2) - mat.coeff(2,0)) * t;
756 q.
z() = (mat.coeff(1,0) - mat.coeff(0,1)) * t;
761 if (mat.coeff(1,1) > mat.coeff(0,0))
763 if (mat.coeff(2,2) > mat.coeff(i,i))
768 t =
sqrt(mat.coeff(i,i)-mat.coeff(j,j)-mat.coeff(k,k) + Scalar(1.0));
769 q.
coeffs().coeffRef(i) = Scalar(0.5) * t;
771 q.
w() = (mat.coeff(k,j)-mat.coeff(j,k))*t;
772 q.
coeffs().coeffRef(j) = (mat.coeff(j,i)+mat.coeff(i,j))*t;
773 q.
coeffs().coeffRef(k) = (mat.coeff(k,i)+mat.coeff(i,k))*t;
779 template<
typename Other>
780 struct quaternionbase_assign_impl<Other,4,1>
782 typedef typename Other::Scalar Scalar;
783 template<
class Derived>
static inline void run(QuaternionBase<Derived>& q,
const Other& vec)
793 #endif // EIGEN_QUATERNION_H