11 #ifndef EIGEN_QUATERNION_H 12 #define EIGEN_QUATERNION_H 22 template<
typename Other,
23 int OtherRows=Other::RowsAtCompileTime,
24 int OtherCols=Other::ColsAtCompileTime>
34 template<
class Derived>
40 using Base::operator*;
66 EIGEN_DEVICE_FUNC
inline CoeffReturnType
x()
const {
return this->derived().coeffs().coeff(0); }
68 EIGEN_DEVICE_FUNC
inline CoeffReturnType
y()
const {
return this->derived().coeffs().coeff(1); }
70 EIGEN_DEVICE_FUNC
inline CoeffReturnType
z()
const {
return this->derived().coeffs().coeff(2); }
72 EIGEN_DEVICE_FUNC
inline CoeffReturnType
w()
const {
return this->derived().coeffs().coeff(3); }
105 EIGEN_DEVICE_FUNC Derived& operator=(
const AngleAxisType& aa);
120 EIGEN_DEVICE_FUNC
inline Scalar
squaredNorm()
const {
return coeffs().squaredNorm(); }
125 EIGEN_DEVICE_FUNC
inline Scalar
norm()
const {
return coeffs().norm(); }
129 EIGEN_DEVICE_FUNC
inline void normalize() { coeffs().normalize(); }
147 template<
typename Derived1,
typename Derived2>
165 template<
class OtherDerived>
167 {
return coeffs().isApprox(other.
coeffs(), prec); }
177 template<
typename NewScalarType>
183 #ifdef EIGEN_QUATERNIONBASE_PLUGIN 184 # include EIGEN_QUATERNIONBASE_PLUGIN 218 template<
typename _Scalar,
int _Options>
231 template<
typename _Scalar,
int _Options>
241 using Base::operator*=;
244 typedef typename Base::AngleAxisType AngleAxisType;
256 EIGEN_DEVICE_FUNC
inline Quaternion(
const Scalar&
w,
const Scalar&
x,
const Scalar&
y,
const Scalar&
z) : m_coeffs(x, y, z, w){}
259 EIGEN_DEVICE_FUNC
explicit inline Quaternion(
const Scalar*
data) : m_coeffs(data) {}
265 EIGEN_DEVICE_FUNC
explicit inline Quaternion(
const AngleAxisType& aa) { *
this = aa; }
271 template<
typename Derived>
275 template<
typename OtherScalar,
int OtherOptions>
277 { m_coeffs = other.
coeffs().template cast<Scalar>(); }
279 EIGEN_DEVICE_FUNC
static Quaternion UnitRandom();
281 template<
typename Derived1,
typename Derived2>
284 EIGEN_DEVICE_FUNC
inline Coefficients&
coeffs() {
return m_coeffs;}
285 EIGEN_DEVICE_FUNC
inline const Coefficients&
coeffs()
const {
return m_coeffs;}
289 #ifdef EIGEN_QUATERNION_PLUGIN 290 # include EIGEN_QUATERNION_PLUGIN 296 #ifndef EIGEN_PARSED_BY_DOXYGEN 300 INVALID_MATRIX_TEMPLATE_PARAMETERS)
317 template<
typename _Scalar,
int _Options>
318 struct traits<
Map<
Quaternion<_Scalar>, _Options> > :
traits<Quaternion<_Scalar, (int(_Options)&Aligned)==Aligned ? AutoAlign : DontAlign> >
325 template<
typename _Scalar,
int _Options>
326 struct traits<
Map<const
Quaternion<_Scalar>, _Options> > :
traits<Quaternion<_Scalar, (int(_Options)&Aligned)==Aligned ? AutoAlign : DontAlign> >
347 template<
typename _Scalar,
int _Options>
349 :
public QuaternionBase<Map<const Quaternion<_Scalar>, _Options> >
357 using Base::operator*=;
367 EIGEN_DEVICE_FUNC
inline const Coefficients&
coeffs()
const {
return m_coeffs;}
384 template<
typename _Scalar,
int _Options>
394 using Base::operator*=;
404 EIGEN_DEVICE_FUNC
inline Coefficients&
coeffs() {
return m_coeffs; }
405 EIGEN_DEVICE_FUNC
inline const Coefficients&
coeffs()
const {
return m_coeffs; }
431 template<
int Arch,
class Derived1,
class Derived2,
typename Scalar>
struct quat_product 436 a.
w() * b.
w() - a.
x() * b.
x() - a.
y() * b.
y() - a.
z() * b.
z(),
437 a.
w() * b.
x() + a.
x() * b.
w() + a.
y() * b.
z() - a.
z() * b.
y(),
438 a.
w() * b.
y() + a.
y() * b.
w() + a.
z() * b.
x() - a.
x() * b.
z(),
439 a.
w() * b.
z() + a.
z() * b.
w() + a.
x() * b.
y() - a.
y() * b.
x()
446 template <
class Derived>
447 template <
class OtherDerived>
452 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
458 template <
class Derived>
459 template <
class OtherDerived>
462 derived() = derived() * other.
derived();
473 template <
class Derived>
482 Vector3 uv = this->vec().cross(v);
484 return v + this->
w() * uv + this->vec().cross(uv);
487 template<
class Derived>
490 coeffs() = other.
coeffs();
494 template<
class Derived>
495 template<
class OtherDerived>
498 coeffs() = other.
coeffs();
504 template<
class Derived>
507 EIGEN_USING_STD_MATH(
cos)
508 EIGEN_USING_STD_MATH(
sin)
511 this->vec() =
sin(ha) * aa.
axis();
521 template<
class Derived>
522 template<
class MatrixDerived>
526 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
534 template<
class Derived>
544 const Scalar tx =
Scalar(2)*this->
x();
545 const Scalar ty =
Scalar(2)*this->
y();
546 const Scalar tz =
Scalar(2)*this->
z();
547 const Scalar twx = tx*this->
w();
548 const Scalar twy = ty*this->
w();
549 const Scalar twz = tz*this->
w();
550 const Scalar txx = tx*this->
x();
551 const Scalar txy = ty*this->
x();
552 const Scalar txz = tz*this->
x();
553 const Scalar tyy = ty*this->
y();
554 const Scalar tyz = tz*this->
y();
555 const Scalar tzz = tz*this->
z();
580 template<
class Derived>
581 template<
typename Derived1,
typename Derived2>
584 EIGEN_USING_STD_MATH(
sqrt)
587 Scalar
c = v1.dot(v0);
602 Vector3 axis = svd.
matrixV().col(2);
605 this->
w() =
sqrt(w2);
609 Vector3 axis = v0.cross(v1);
612 this->vec() = axis * invs;
622 template<
typename Scalar,
int Options>
625 EIGEN_USING_STD_MATH(
sqrt)
626 EIGEN_USING_STD_MATH(
sin)
627 EIGEN_USING_STD_MATH(
cos)
628 const Scalar u1 = internal::random<Scalar>(0, 1),
630 u3 = internal::random<Scalar>(0, 2*
EIGEN_PI);
631 const Scalar a =
sqrt(1 - u1),
647 template<
typename Scalar,
int Options>
648 template<
typename Derived1,
typename Derived2>
663 template <
class Derived>
667 Scalar
n2 = this->squaredNorm();
679 template<
int Arch,
class Derived,
typename Scalar>
struct quat_conj 693 template <
class Derived>
705 template <
class Derived>
706 template <
class OtherDerived>
710 EIGEN_USING_STD_MATH(
atan2)
723 template <
class Derived>
724 template <
class OtherDerived>
728 EIGEN_USING_STD_MATH(
acos)
729 EIGEN_USING_STD_MATH(
sin)
731 Scalar
d = this->
dot(other);
746 Scalar sinTheta =
sin(theta);
748 scale0 =
sin( (
Scalar(1) - t ) * theta) / sinTheta;
749 scale1 =
sin( ( t * theta) ) / sinTheta;
751 if(d<
Scalar(0)) scale1 = -scale1;
759 template<
typename Other>
766 EIGEN_USING_STD_MATH(
sqrt)
769 Scalar t = mat.trace();
800 template<
typename Other>
814 #endif // EIGEN_QUATERNION_H
EIGEN_DEVICE_FUNC Coefficients & coeffs()
internal::traits< Derived >::Coefficients Coefficients
EIGEN_DEVICE_FUNC internal::cast_return_type< Derived, Quaternion< NewScalarType > >::type cast() const
cout<< "Here is the matrix m:"<< endl<< m<< endl;JacobiSVD< MatrixXf > svd(m, ComputeThinU|ComputeThinV)
#define EIGEN_STRONG_INLINE
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half & operator*=(half &a, const half &b)
EIGEN_DEVICE_FUNC CoeffReturnType x() const
NumTraits< Scalar >::Real RealScalar
Quaternion< _Scalar, _Options > PlainObject
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Quaternion(const QuaternionBase< Derived > &other)
EIGEN_DEVICE_FUNC CoeffReturnType y() const
EIGEN_DEVICE_FUNC Quaternion< Scalar > normalized() const
A matrix or vector expression mapping an existing array of data.
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived & operator*=(const QuaternionBase< OtherDerived > &q)
Matrix< Scalar, 3, 1 > Vector3
Quaternion< double > Quaterniond
const unsigned int LvalueBit
EIGEN_DEVICE_FUNC Matrix3 toRotationMatrix() const
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
Namespace containing all symbols from the Eigen library.
EIGEN_DEVICE_FUNC Quaternion(const Scalar &w, const Scalar &x, const Scalar &y, const Scalar &z)
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Quaternion< Scalar > run(const QuaternionBase< Derived > &q)
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
EIGEN_DEVICE_FUNC Quaternion< Scalar > conjugate() const
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T maxi(const T &x, const T &y)
AngleAxis< Scalar > AngleAxisType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Quaternion< Scalar > operator*(const QuaternionBase< OtherDerived > &q) const
EIGEN_DEVICE_FUNC const Coefficients & coeffs() const
virtual EIGEN_DEVICE_FUNC const Scalar coeff(DenseIndex index) const
Map< const Matrix< _Scalar, 4, 1 >, _Options > Coefficients
EIGEN_DEVICE_FUNC Quaternion< Scalar > inverse() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRef(Index rowId, Index colId)
EIGEN_DEVICE_FUNC const Vector3 & axis() const
EIGEN_DEVICE_FUNC Quaternion(const MatrixBase< Derived > &other)
static EIGEN_DEVICE_FUNC void run(QuaternionBase< Derived > &q, const Other &vec)
EIGEN_DEVICE_FUNC Derived & setFromTwoVectors(const MatrixBase< Derived1 > &a, const MatrixBase< Derived2 > &b)
EIGEN_DEVICE_FUNC CoeffReturnType w() const
EIGEN_DEVICE_FUNC const VectorBlock< const Coefficients, 3 > vec() const
EIGEN_DEVICE_FUNC CoeffReturnType z() const
static EIGEN_STRONG_INLINE void _check_template_params()
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign)
EIGEN_DEVICE_FUNC const CosReturnType cos() const
EIGEN_DEVICE_FUNC Scalar angle() const
Expression of a fixed-size or dynamic-size sub-vector.
static EIGEN_DEVICE_FUNC Quaternion< Scalar > Identity()
EIGEN_DEVICE_FUNC const internal::traits< Derived >::Coefficients & coeffs() const
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE internal::enable_if< NumTraits< T >::IsSigned||NumTraits< T >::IsComplex, typename NumTraits< T >::Real >::type abs(const T &x)
Scalar EIGEN_BLAS_FUNC() dot(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
EIGEN_DEVICE_FUNC void normalize()
EIGEN_DEVICE_FUNC bool isApprox(const QuaternionBase< OtherDerived > &other, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
EIGEN_DEVICE_FUNC VectorBlock< Coefficients, 3 > vec()
EIGEN_DEVICE_FUNC const Coefficients & coeffs() const
Map< Matrix< _Scalar, 4, 1 >, _Options > Coefficients
traits< Quaternion< _Scalar,(int(_Options)&Aligned)==Aligned?AutoAlign:DontAlign > > TraitsBase
EIGEN_DEVICE_FUNC internal::traits< Derived >::Coefficients & coeffs()
static EIGEN_DEVICE_FUNC Matrix< Scalar, 2, 2 > toRotationMatrix(const Scalar &s)
EIGEN_DEVICE_FUNC Scalar dot(const QuaternionBase< OtherDerived > &other) const
EIGEN_DEVICE_FUNC ConjugateReturnType conjugate() const
EIGEN_DEVICE_FUNC Scalar angularDistance(const QuaternionBase< OtherDerived > &other) const
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
static EIGEN_DEVICE_FUNC Quaternion FromTwoVectors(const MatrixBase< Derived1 > &a, const MatrixBase< Derived2 > &b)
EIGEN_DEVICE_FUNC Quaternion(const Scalar *data)
EIGEN_DEVICE_FUNC NonConstCoeffReturnType x()
Common base class for compact rotation representations.
const MatrixVType & matrixV() const
EIGEN_DEVICE_FUNC const Scalar & q
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived)
EIGEN_DEVICE_FUNC Quaternion(const Quaternion< OtherScalar, OtherOptions > &other)
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorUInt128< uint64_t, uint64_t > operator*(const TensorUInt128< HL, LL > &lhs, const TensorUInt128< HR, LR > &rhs)
Coefficients::CoeffReturnType CoeffReturnType
Base class for quaternion expressions.
internal::traits< Map >::Coefficients Coefficients
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE QuaternionBase< Derived > & operator=(const QuaternionBase< Derived > &other)
EIGEN_DEVICE_FUNC Quaternion(const AngleAxisType &aa)
EIGEN_DEVICE_FUNC NonConstCoeffReturnType y()
EIGEN_DEVICE_FUNC QuaternionBase & setIdentity()
const Coefficients m_coeffs
EIGEN_DEVICE_FUNC NonConstCoeffReturnType w()
QuaternionBase< Map< const Quaternion< _Scalar >, _Options > > Base
EIGEN_DEVICE_FUNC const Derived & derived() const
EIGEN_DEVICE_FUNC const AcosReturnType acos() const
Map< Quaternion< float >, 0 > QuaternionMapf
EIGEN_DEVICE_FUNC Coefficients & coeffs()
Matrix< _Scalar, 4, 1, _Options > Coefficients
EIGEN_DEVICE_FUNC NonConstCoeffReturnType z()
EIGEN_DEVICE_FUNC Scalar norm() const
EIGEN_DEVICE_FUNC const Coefficients & coeffs() const
The quaternion class used to represent 3D orientations and rotations.
RotationBase< Derived, 3 > Base
Map< Quaternion< double >, 0 > QuaternionMapd
Two-sided Jacobi SVD decomposition of a rectangular matrix.
Map< Quaternion< float >, Aligned > QuaternionMapAlignedf
const AutoDiffScalar< Matrix< typename internal::traits< typename internal::remove_all< DerTypeA >::type >::Scalar, Dynamic, 1 > > atan2(const AutoDiffScalar< DerTypeA > &a, const AutoDiffScalar< DerTypeB > &b)
EIGEN_DEVICE_FUNC Quaternion< Scalar > slerp(const Scalar &t, const QuaternionBase< OtherDerived > &other) const
EIGEN_DEVICE_FUNC const SinReturnType sin() const
internal::traits< Map >::Coefficients Coefficients
Matrix< Scalar, 3, 3 > Matrix3
EIGEN_DEVICE_FUNC const PlainObject normalized() const
static EIGEN_DEVICE_FUNC Quaternion UnitRandom()
void run(Expr &expr, Dev &dev)
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
internal::traits< Derived >::Scalar Scalar
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Vector3 _transformVector(const Vector3 &v) const
Base class for all dense matrices, vectors, and expressions.
Represents a 3D rotation as a rotation angle around an arbitrary 3D axis.
EIGEN_DEVICE_FUNC const InverseReturnType inverse() const
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Quaternion< Scalar > run(const QuaternionBase< Derived1 > &a, const QuaternionBase< Derived2 > &b)
QuaternionBase< Quaternion< _Scalar, _Options > > Base
Quaternion< float > Quaternionf
Map< Quaternion< double >, Aligned > QuaternionMapAlignedd
EIGEN_DEVICE_FUNC Scalar squaredNorm() const
Eigen::Quaternion< double, Eigen::DontAlign > Quaternion
QuaternionBase< Map< Quaternion< _Scalar >, _Options > > Base
static EIGEN_DEVICE_FUNC void run(QuaternionBase< Derived > &q, const Other &a_mat)