11 #ifndef EIGEN_QUATERNION_H
12 #define EIGEN_QUATERNION_H
24 template<
typename Other,
25 int OtherRows=Other::RowsAtCompileTime,
26 int OtherCols=Other::ColsAtCompileTime>
27 struct quaternionbase_assign_impl;
36 template<
class Derived>
42 using Base::operator*;
45 typedef typename internal::traits<Derived>::Scalar
Scalar;
47 typedef typename internal::traits<Derived>::Coefficients
Coefficients;
49 typedef std::conditional_t<
bool(internal::traits<Derived>::Flags&
LvalueBit),
54 Flags = Eigen::internal::traits<Derived>::Flags
149 template<
typename Derived1,
typename Derived2>
167 template<
class OtherDerived>
175 template<
class OtherDerived>
183 template<
class OtherDerived>
190 #ifdef EIGEN_PARSED_BY_DOXYGEN
196 template<
typename NewScalarType>
197 EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<Derived,Quaternion<NewScalarType> >::type
cast()
const;
201 template<
typename NewScalarType>
203 std::enable_if_t<internal::is_same<Scalar,NewScalarType>::value,
const Derived&>
cast()
const
208 template<
typename NewScalarType>
218 s << q.
x() <<
"i + " << q.
y() <<
"j + " << q.
z() <<
"k" <<
" + " << q.
w();
223 #ifdef EIGEN_QUATERNIONBASE_PLUGIN
224 # include EIGEN_QUATERNIONBASE_PLUGIN
261 template<
typename Scalar_,
int Options_>
262 struct traits<Quaternion<Scalar_,Options_> >
264 typedef Quaternion<Scalar_,Options_> PlainObject;
265 typedef Scalar_ Scalar;
266 typedef Matrix<Scalar_,4,1,Options_> Coefficients;
268 Alignment = internal::traits<Coefficients>::Alignment,
274 template<
typename Scalar_,
int Options_>
279 enum { NeedsAlignment = internal::traits<Quaternion>::Alignment>0 };
284 using Base::operator*=;
286 typedef typename internal::traits<Quaternion>::Coefficients
Coefficients;
304 template <
typename Derived>
323 template<
typename Derived>
327 template<
typename OtherScalar,
int OtherOptions>
346 template<
typename Derived1,
typename Derived2>
354 #ifdef EIGEN_QUATERNION_PLUGIN
355 # include EIGEN_QUATERNION_PLUGIN
361 #ifndef EIGEN_PARSED_BY_DOXYGEN
363 INVALID_MATRIX_TEMPLATE_PARAMETERS)
379 template<
typename Scalar_,
int Options_>
380 struct traits<
Map<
Quaternion<Scalar_>, Options_> > : traits<Quaternion<Scalar_, (int(Options_)&Aligned)==Aligned ? AutoAlign : DontAlign> >
387 template<
typename Scalar_,
int Options_>
388 struct traits<Map<const Quaternion<Scalar_>, Options_> > : traits<Quaternion<Scalar_, (int(Options_)&Aligned)==Aligned ? AutoAlign : DontAlign> >
390 typedef Map<const Matrix<Scalar_,4,1>, Options_> Coefficients;
409 template<
typename Scalar_,
int Options_>
411 :
public QuaternionBase<Map<const Quaternion<Scalar_>, Options_> >
419 using Base::operator*=;
446 template<
typename Scalar_,
int Options_>
456 using Base::operator*=;
493 template<
int Arch,
class Derived1,
class Derived2,
typename Scalar>
struct quat_product
498 a.w() *
b.w() -
a.x() *
b.x() -
a.y() *
b.y() -
a.z() *
b.z(),
499 a.w() *
b.x() +
a.x() *
b.w() +
a.y() *
b.z() -
a.z() *
b.y(),
500 a.w() *
b.y() +
a.y() *
b.w() +
a.z() *
b.x() -
a.x() *
b.z(),
501 a.w() *
b.z() +
a.z() *
b.w() +
a.x() *
b.y() -
a.y() *
b.x()
508 template <
class Derived>
509 template <
class OtherDerived>
513 EIGEN_STATIC_ASSERT((internal::is_same<typename Derived::Scalar, typename OtherDerived::Scalar>::value),
514 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
516 typename internal::traits<Derived>::Scalar>::run(*
this, other);
520 template <
class Derived>
521 template <
class OtherDerived>
524 derived() = derived() * other.
derived();
535 template <
class Derived>
546 return v + this->
w() * uv + this->vec().cross(uv);
549 template<
class Derived>
552 coeffs() = other.
coeffs();
556 template<
class Derived>
557 template<
class OtherDerived>
560 coeffs() = other.
coeffs();
566 template<
class Derived>
573 this->vec() =
sin(ha) * aa.
axis();
583 template<
class Derived>
584 template<
class MatrixDerived>
587 EIGEN_STATIC_ASSERT((internal::is_same<typename Derived::Scalar, typename MatrixDerived::Scalar>::value),
588 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
589 internal::quaternionbase_assign_impl<MatrixDerived>::run(*
this, xpr.
derived());
596 template<
class Derived>
607 const Scalar ty =
Scalar(2)*this->
y();
608 const Scalar tz =
Scalar(2)*this->z();
609 const Scalar twx = tx*this->
w();
610 const Scalar twy = ty*this->
w();
611 const Scalar twz = tz*this->
w();
612 const Scalar txx = tx*this->
x();
613 const Scalar txy = ty*this->
x();
614 const Scalar txz = tz*this->
x();
615 const Scalar tyy = ty*this->
y();
616 const Scalar tyz = tz*this->
y();
617 const Scalar tzz = tz*this->z();
620 res.coeffRef(0,1) = txy-twz;
621 res.coeffRef(0,2) = txz+twy;
622 res.coeffRef(1,0) = txy+twz;
624 res.coeffRef(1,2) = tyz-twx;
625 res.coeffRef(2,0) = txz-twy;
626 res.coeffRef(2,1) = tyz+twx;
642 template<
class Derived>
643 template<
typename Derived1,
typename Derived2>
667 this->
w() =
sqrt(w2);
674 this->vec() = axis * invs;
684 template<
typename Scalar,
int Options>
690 const Scalar u1 = internal::random<Scalar>(0, 1),
691 u2 = internal::random<Scalar>(0, 2*
EIGEN_PI),
692 u3 = internal::random<Scalar>(0, 2*
EIGEN_PI);
709 template<
typename Scalar,
int Options>
710 template<
typename Derived1,
typename Derived2>
725 template <
class Derived>
729 Scalar n2 = this->squaredNorm();
741 template<
int Arch,
class Derived,
typename Scalar>
struct quat_conj
755 template <
class Derived>
760 typename internal::traits<Derived>::Scalar>::run(*
this);
767 template <
class Derived>
768 template <
class OtherDerived>
785 template <
class Derived>
786 template <
class OtherDerived>
793 Scalar d = this->dot(other);
810 scale0 =
sin( (
Scalar(1) - t ) * theta) / sinTheta;
811 scale1 =
sin( ( t * theta) ) / sinTheta;
813 if(d<
Scalar(0)) scale1 = -scale1;
821 template<
typename Other>
822 struct quaternionbase_assign_impl<Other,3,3>
824 typedef typename Other::Scalar Scalar;
827 const typename internal::nested_eval<Other,2>::type
mat(a_mat);
831 Scalar t =
mat.trace();
834 t =
sqrt(t + Scalar(1.0));
835 q.
w() = Scalar(0.5)*t;
837 q.
x() = (
mat.coeff(2,1) -
mat.coeff(1,2)) * t;
838 q.
y() = (
mat.coeff(0,2) -
mat.coeff(2,0)) * t;
839 q.
z() = (
mat.coeff(1,0) -
mat.coeff(0,1)) * t;
844 if (
mat.coeff(1,1) >
mat.coeff(0,0))
846 if (
mat.coeff(2,2) >
mat.coeff(
i,
i))
852 q.
coeffs().coeffRef(
i) = Scalar(0.5) * t;
854 q.
w() = (
mat.coeff(k,
j)-
mat.coeff(
j,k))*t;
862 template<
typename Other>
863 struct quaternionbase_assign_impl<Other,4,1>
865 typedef typename Other::Scalar Scalar;
866 template<
class Derived>
EIGEN_DEVICE_FUNC static inline void run(QuaternionBase<Derived>& q,
const Other& vec)
const CwiseBinaryOp< atan2< Scalar >, const Derived, const OtherDerived > atan2(const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
Array< int, Dynamic, 1 > v
ConjugateReturnType conjugate() const
cout<< "Here is the matrix m:"<< endl<< m<< endl;JacobiSVD< MatrixXf, ComputeThinU|ComputeThinV > svd(m)
#define EIGEN_DEFAULT_COPY_CONSTRUCTOR(CLASS)
#define EIGEN_NOEXCEPT_IF(x)
#define EIGEN_USING_STD(FUNC)
#define EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(Derived)
#define EIGEN_DEVICE_FUNC
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived)
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign)
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
#define EIGEN_STATIC_ASSERT(X, MSG)
#define EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(TYPE, SIZE)
M1<< 1, 2, 3, 4, 5, 6, 7, 8, 9;Map< RowVectorXf > v1(M1.data(), M1.size())
Represents a 3D rotation as a rotation angle around an arbitrary 3D axis.
const Vector3 & axis() const
Two-sided Jacobi SVD decomposition of a rectangular matrix.
const Coefficients & coeffs() const
internal::traits< Map >::Coefficients Coefficients
QuaternionBase< Map< Quaternion< Scalar_ >, Options_ > > Base
Map(const Scalar *coeffs)
const Coefficients & coeffs() const
QuaternionBase< Map< const Quaternion< Scalar_ >, Options_ > > Base
internal::traits< Map >::Coefficients Coefficients
const Coefficients m_coeffs
A matrix or vector expression mapping an existing array of data.
Base class for all dense matrices, vectors, and expressions.
Base class for quaternion expressions.
QuaternionBase< Derived > & operator=(const QuaternionBase< Derived > &other)
Scalar squaredNorm() const
Derived & operator=(const MatrixBase< OtherDerived > &m)
const internal::traits< Derived >::Coefficients & coeffs() const
friend std::ostream & operator<<(std::ostream &s, const QuaternionBase< Derived > &q)
QuaternionBase & setIdentity()
Scalar angularDistance(const QuaternionBase< OtherDerived > &other) const
bool operator!=(const QuaternionBase< OtherDerived > &other) const
Quaternion< Scalar > conjugate() const
NonConstCoeffReturnType y()
std::conditional_t< bool(internal::traits< Derived >::Flags &LvalueBit), Scalar &, CoeffReturnType > NonConstCoeffReturnType
bool isApprox(const QuaternionBase< OtherDerived > &other, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
static Quaternion< Scalar > Identity()
Derived & setFromTwoVectors(const MatrixBase< Derived1 > &a, const MatrixBase< Derived2 > &b)
CoeffReturnType z() const
NonConstCoeffReturnType x()
Matrix3 toRotationMatrix() const
VectorBlock< Coefficients, 3 > vec()
internal::cast_return_type< Derived, Quaternion< NewScalarType > >::type cast() const
Matrix< Scalar, 3, 1 > Vector3
NonConstCoeffReturnType z()
Scalar dot(const QuaternionBase< OtherDerived > &other) const
Derived & operator=(const AngleAxisType &aa)
Vector3 _transformVector(const Vector3 &v) const
CoeffReturnType y() const
Quaternion< Scalar > inverse() const
CoeffReturnType w() const
Derived & operator=(const QuaternionBase< OtherDerived > &other)
Matrix< Scalar, 3, 3 > Matrix3
internal::traits< Derived >::Coefficients Coefficients
Quaternion< Scalar > slerp(const Scalar &t, const QuaternionBase< OtherDerived > &other) const
RotationBase< Derived, 3 > Base
bool operator==(const QuaternionBase< OtherDerived > &other) const
Quaternion< Scalar > operator*(const QuaternionBase< OtherDerived > &q) const
Coefficients::CoeffReturnType CoeffReturnType
NonConstCoeffReturnType w()
const VectorBlock< const Coefficients, 3 > vec() const
Quaternion< Scalar > normalized() const
NumTraits< Scalar >::Real RealScalar
internal::traits< Derived >::Coefficients & coeffs()
internal::traits< Derived >::Scalar Scalar
AngleAxis< Scalar > AngleAxisType
Derived & operator*=(const QuaternionBase< OtherDerived > &q)
CoeffReturnType x() const
The quaternion class used to represent 3D orientations and rotations.
Quaternion & operator=(Quaternion &&other) EIGEN_NOEXCEPT_IF(std
Base::AngleAxisType AngleAxisType
QuaternionBase< Quaternion< Scalar_, Options_ > > Base
Quaternion(const Quaternion< OtherScalar, OtherOptions > &other)
Quaternion(const Scalar &w, const Scalar &x, const Scalar &y, const Scalar &z)
Quaternion(const QuaternionBase< Derived > &other)
static Quaternion FromTwoVectors(const MatrixBase< Derived1 > &a, const MatrixBase< Derived2 > &b)
Quaternion(const Scalar &w, const Eigen::MatrixBase< Derived > &vec)
internal::traits< Quaternion >::Coefficients Coefficients
static Quaternion UnitRandom()
Quaternion(const MatrixBase< Derived > &other)
Quaternion(const AngleAxisType &aa)
const Coefficients & coeffs() const
Quaternion(Quaternion &&other) EIGEN_NOEXCEPT_IF(std
Quaternion(const Scalar *data)
Common base class for compact rotation representations.
const Derived & derived() const
Expression of a fixed-size or dynamic-size sub-vector.
Map< Quaternion< double >, Aligned > QuaternionMapAlignedd
Quaternion< double > Quaterniond
Quaternion< float > Quaternionf
Map< Quaternion< float >, 0 > QuaternionMapf
Map< Quaternion< double >, 0 > QuaternionMapd
Map< Quaternion< float >, Aligned > QuaternionMapAlignedf
const unsigned int LvalueBit
EIGEN_ALWAYS_INLINE T maxi(const T &x, const T &y)
EIGEN_ALWAYS_INLINE std::enable_if_t< NumTraits< T >::IsSigned||NumTraits< T >::IsComplex, typename NumTraits< T >::Real > abs(const T &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_acos_op< typename Derived::Scalar >, const Derived > acos(const Eigen::ArrayBase< Derived > &x)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_cos_op< typename Derived::Scalar >, const Derived > cos(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sin_op< typename Derived::Scalar >, const Derived > sin(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sqrt_op< typename Derived::Scalar >, const Derived > sqrt(const Eigen::ArrayBase< Derived > &x)
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.