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>
39 using Base::operator*;
60 inline Scalar
x()
const {
return this->derived().coeffs().coeff(0); }
62 inline Scalar
y()
const {
return this->derived().coeffs().coeff(1); }
64 inline Scalar
z()
const {
return this->derived().coeffs().coeff(2); }
66 inline Scalar
w()
const {
return this->derived().coeffs().coeff(3); }
69 inline Scalar&
x() {
return this->derived().coeffs().coeffRef(0); }
71 inline Scalar&
y() {
return this->derived().coeffs().coeffRef(1); }
73 inline Scalar&
z() {
return this->derived().coeffs().coeffRef(2); }
75 inline Scalar&
w() {
return this->derived().coeffs().coeffRef(3); }
99 Derived& operator=(
const AngleAxisType& aa);
114 inline Scalar
squaredNorm()
const {
return coeffs().squaredNorm(); }
119 inline Scalar
norm()
const {
return coeffs().norm(); }
138 Matrix3 toRotationMatrix()
const;
141 template<
typename Derived1,
typename Derived2>
159 template<
class OtherDerived>
161 {
return coeffs().isApprox(other.
coeffs(), prec); }
164 EIGEN_STRONG_INLINE Vector3 _transformVector(
const Vector3& v)
const;
171 template<
typename NewScalarType>
177 #ifdef EIGEN_QUATERNIONBASE_PLUGIN 178 # include EIGEN_QUATERNIONBASE_PLUGIN 212 template<
typename _Scalar,
int _Options>
225 template<
typename _Scalar,
int _Options>
234 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(
Quaternion)
235 using Base::operator*=;
238 typedef typename Base::AngleAxisType AngleAxisType;
250 inline Quaternion(
const Scalar& w,
const Scalar& x,
const Scalar& y,
const Scalar& z) : m_coeffs(x, y, z, w){}
259 explicit inline Quaternion(
const AngleAxisType& aa) { *
this = aa; }
265 template<
typename Derived>
269 template<
typename OtherScalar,
int OtherOptions>
271 { m_coeffs = other.
coeffs().template cast<Scalar>(); }
273 template<
typename Derived1,
typename Derived2>
276 inline Coefficients& coeffs() {
return m_coeffs;}
277 inline const Coefficients& coeffs()
const {
return m_coeffs;}
279 EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(IsAligned)
282 Coefficients m_coeffs;
284 #ifndef EIGEN_PARSED_BY_DOXYGEN 285 static EIGEN_STRONG_INLINE
void _check_template_params()
287 EIGEN_STATIC_ASSERT( (_Options &
DontAlign) == _Options,
288 INVALID_MATRIX_TEMPLATE_PARAMETERS)
305 template<
typename _Scalar,
int _Options>
306 struct traits<
Map<
Quaternion<_Scalar>, _Options> > :
traits<Quaternion<_Scalar, (int(_Options)&Aligned)==Aligned ? AutoAlign : DontAlign> >
313 template<
typename _Scalar,
int _Options>
314 struct traits<
Map<const
Quaternion<_Scalar>, _Options> > :
traits<Quaternion<_Scalar, (int(_Options)&Aligned)==Aligned ? AutoAlign : DontAlign> >
335 template<
typename _Scalar,
int _Options>
337 :
public QuaternionBase<Map<const Quaternion<_Scalar>, _Options> >
344 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(
Map)
345 using Base::operator*=;
353 EIGEN_STRONG_INLINE
Map(
const Scalar* coeffs) : m_coeffs(coeffs) {}
355 inline const Coefficients& coeffs()
const {
return m_coeffs;}
358 const Coefficients m_coeffs;
372 template<
typename _Scalar,
int _Options>
381 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(
Map)
382 using Base::operator*=;
390 EIGEN_STRONG_INLINE
Map(Scalar* coeffs) : m_coeffs(coeffs) {}
392 inline Coefficients& coeffs() {
return m_coeffs; }
393 inline const Coefficients& coeffs()
const {
return m_coeffs; }
396 Coefficients m_coeffs;
419 template<
int Arch,
class Derived1,
class Derived2,
typename Scalar,
int _Options>
struct quat_product 424 a.
w() * b.
w() - a.
x() * b.
x() - a.
y() * b.
y() - a.
z() * b.
z(),
425 a.
w() * b.
x() + a.
x() * b.
w() + a.
y() * b.
z() - a.
z() * b.
y(),
426 a.
w() * b.
y() + a.
y() * b.
w() + a.
z() * b.
x() - a.
x() * b.
z(),
427 a.
w() * b.
z() + a.
z() * b.
w() + a.
x() * b.
y() - a.
y() * b.
x()
434 template <
class Derived>
435 template <
class OtherDerived>
440 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
447 template <
class Derived>
448 template <
class OtherDerived>
451 derived() = derived() * other.derived();
462 template <
class Derived>
471 Vector3 uv = this->vec().cross(v);
473 return v + this->w() * uv + this->vec().cross(uv);
476 template<
class Derived>
479 coeffs() = other.
coeffs();
483 template<
class Derived>
484 template<
class OtherDerived>
487 coeffs() = other.
coeffs();
493 template<
class Derived>
498 Scalar ha =
Scalar(0.5)*aa.angle();
500 this->vec() = sin(ha) * aa.axis();
510 template<
class Derived>
511 template<
class MatrixDerived>
515 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
523 template<
class Derived>
533 const Scalar tx =
Scalar(2)*this->x();
534 const Scalar ty =
Scalar(2)*this->y();
535 const Scalar tz =
Scalar(2)*this->z();
536 const Scalar twx = tx*this->w();
537 const Scalar twy = ty*this->w();
538 const Scalar twz = tz*this->w();
539 const Scalar txx = tx*this->x();
540 const Scalar txy = ty*this->x();
541 const Scalar txz = tz*this->x();
542 const Scalar tyy = ty*this->y();
543 const Scalar tyz = tz*this->y();
544 const Scalar tzz = tz*this->z();
546 res.coeffRef(0,0) =
Scalar(1)-(tyy+tzz);
547 res.coeffRef(0,1) = txy-twz;
548 res.coeffRef(0,2) = txz+twy;
549 res.coeffRef(1,0) = txy+twz;
550 res.coeffRef(1,1) =
Scalar(1)-(txx+tzz);
551 res.coeffRef(1,2) = tyz-twx;
552 res.coeffRef(2,0) = txz-twy;
553 res.coeffRef(2,1) = tyz+twx;
554 res.coeffRef(2,2) =
Scalar(1)-(txx+tyy);
569 template<
class Derived>
570 template<
typename Derived1,
typename Derived2>
577 Scalar c = v1.dot(v0);
592 Vector3 axis = svd.
matrixV().col(2);
595 this->w() = sqrt(w2);
596 this->vec() = axis * sqrt(
Scalar(1) - w2);
599 Vector3 axis = v0.cross(v1);
601 Scalar invs =
Scalar(1)/s;
602 this->vec() = axis * invs;
603 this->w() = s *
Scalar(0.5);
619 template<
typename Scalar,
int Options>
620 template<
typename Derived1,
typename Derived2>
624 quat.setFromTwoVectors(a, b);
635 template <
class Derived>
639 Scalar n2 = this->squaredNorm();
655 template <
class Derived>
665 template <
class Derived>
666 template <
class OtherDerived>
673 return Scalar(2) * atan2( d.
vec().norm(), abs(d.
w()) );
684 template <
class Derived>
685 template <
class OtherDerived>
693 Scalar d = this->dot(other);
694 Scalar absD = abs(d);
707 Scalar theta = acos(absD);
708 Scalar sinTheta = sin(theta);
710 scale0 = sin( (
Scalar(1) - t ) * theta) / sinTheta;
711 scale1 = sin( ( t * theta) ) / sinTheta;
713 if(d<
Scalar(0)) scale1 = -scale1;
721 template<
typename Other>
725 typedef DenseIndex Index;
731 Scalar t = mat.trace();
734 t = sqrt(t +
Scalar(1.0));
737 q.
x() = (mat.coeff(2,1) - mat.coeff(1,2)) * t;
738 q.
y() = (mat.coeff(0,2) - mat.coeff(2,0)) * t;
739 q.
z() = (mat.coeff(1,0) - mat.coeff(0,1)) * t;
744 if (mat.coeff(1,1) > mat.coeff(0,0))
746 if (mat.coeff(2,2) > mat.coeff(i,i))
748 DenseIndex j = (i+1)%3;
749 DenseIndex k = (j+1)%3;
751 t = sqrt(mat.coeff(i,i)-mat.coeff(j,j)-mat.coeff(k,k) +
Scalar(1.0));
754 q.
w() = (mat.coeff(k,j)-mat.coeff(j,k))*t;
755 q.
coeffs().coeffRef(j) = (mat.coeff(j,i)+mat.coeff(i,j))*t;
756 q.
coeffs().coeffRef(k) = (mat.coeff(k,i)+mat.coeff(i,k))*t;
762 template<
typename Other>
776 #endif // EIGEN_QUATERNION_H Definition: gtest_unittest.cc:5031
Definition: XprHelper.h:393
Scalar z() const
Definition: Quaternion.h:64
const Coefficients & coeffs() const
Definition: Quaternion.h:93
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:104
EIGEN_STRONG_INLINE Map(const Scalar *coeffs)
Constructs a Mapped Quaternion object from the pointer coeffs.
Definition: Quaternion.h:353
Matrix< Scalar, 3, 1 > Vector3
the type of a 3D vector
Definition: Quaternion.h:51
bool isApprox(const QuaternionBase< OtherDerived > &other, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: Quaternion.h:160
const unsigned int LvalueBit
Means the expression has a coeffRef() method, i.e.
Definition: Constants.h:131
Scalar dot(const QuaternionBase< OtherDerived > &other) const
Definition: Quaternion.h:133
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
Holds information about the various numeric (i.e.
Definition: NumTraits.h:88
const PlainObject normalized() const
Definition: Dot.h:139
const internal::permut_matrix_product_retval< PermutationDerived, Derived, OnTheRight > operator*(const MatrixBase< Derived > &matrix, const PermutationBase< PermutationDerived > &permutation)
Definition: PermutationMatrix.h:539
Scalar norm() const
Definition: Quaternion.h:119
internal::cast_return_type< Derived, Quaternion< NewScalarType > >::type cast() const
Definition: Quaternion.h:172
Quaternion(const Quaternion< OtherScalar, OtherOptions > &other)
Explicit copy constructor with scalar conversion.
Definition: Quaternion.h:270
AngleAxis< Scalar > AngleAxisType
the equivalent angle-axis type
Definition: Quaternion.h:55
const Block< const Coefficients, 3, 1 > vec() const
Definition: Quaternion.h:87
Scalar x() const
Definition: Quaternion.h:60
Object is aligned for vectorization.
Definition: Constants.h:194
static Quaternion< Scalar > Identity()
Definition: Quaternion.h:105
Definition: Quaternion.h:25
Quaternion()
Default constructor leaving the quaternion uninitialized.
Definition: Quaternion.h:241
void normalize()
Normalizes the quaternion *this.
Definition: Quaternion.h:123
Derived & setFromTwoVectors(const MatrixBase< Derived1 > &a, const MatrixBase< Derived2 > &b)
Sets *this to be a quaternion representing a rotation between the two arbitrary vectors a and b...
Definition: Quaternion.h:571
const unsigned int AlignedBit
means the first coefficient packet is guaranteed to be aligned
Definition: Constants.h:147
Expression of a fixed-size or dynamic-size sub-vector.
Definition: ForwardDeclarations.h:83
Scalar squaredNorm() const
Definition: Quaternion.h:114
EIGEN_STRONG_INLINE Derived & operator*=(const QuaternionBase< OtherDerived > &q)
Definition: Quaternion.h:449
internal::traits< Derived >::Coefficients & coeffs()
Definition: Quaternion.h:87
Quaternion(const MatrixBase< Derived > &other)
Constructs and initializes a quaternion from either:
Definition: Quaternion.h:266
const VectorBlock< const Coefficients, 3 > vec() const
Definition: Quaternion.h:78
Scalar & x()
Definition: Quaternion.h:69
EIGEN_STRONG_INLINE Quaternion(const QuaternionBase< Derived > &other)
Copy constructor.
Definition: Quaternion.h:256
Quaternion(const Scalar &w, const Scalar &x, const Scalar &y, const Scalar &z)
Constructs and initializes the quaternion from its four coefficients w, x, y and z...
Definition: Quaternion.h:250
Common base class for compact rotation representations.
Definition: ForwardDeclarations.h:231
EIGEN_STRONG_INLINE Map(Scalar *coeffs)
Constructs a Mapped Quaternion object from the pointer coeffs.
Definition: Quaternion.h:390
Quaternion< Scalar > normalized() const
Definition: Quaternion.h:126
Scalar & z()
Definition: Quaternion.h:73
Definition: ForwardDeclarations.h:233
const MatrixVType & matrixV() const
Definition: JacobiSVD.h:629
Quaternion< Scalar > inverse() const
Definition: Quaternion.h:636
Scalar w() const
Definition: Quaternion.h:75
Map< Quaternion< float >, 0 > QuaternionMapf
Map an unaligned array of single precision scalars as a quaternion.
Definition: Quaternion.h:401
Definition: BandTriangularSolver.h:13
Don't require alignment for the matrix itself (the array of coefficients, if dynamically allocated...
Definition: Constants.h:270
Definition: Quaternion.h:419
Definition: Quaternion.h:47
Map< Quaternion< double >, 0 > QuaternionMapd
Map an unaligned array of double precision scalars as a quaternion.
Definition: Quaternion.h:404
Two-sided Jacobi SVD decomposition of a rectangular matrix.
Definition: ForwardDeclarations.h:224
Map< Quaternion< float >, Aligned > QuaternionMapAlignedf
Map a 16-byte aligned array of single precision scalars as a quaternion.
Definition: Quaternion.h:407
Quaternion(const AngleAxisType &aa)
Constructs and initializes a quaternion from the angle-axis aa.
Definition: Quaternion.h:259
QuaternionBase & setIdentity()
Definition: Quaternion.h:109
Scalar & w()
Definition: Quaternion.h:75
Quaternion< Scalar > conjugate() const
Definition: Quaternion.h:657
Quaternion< double > Quaterniond
double precision quaternion type
Definition: Quaternion.h:211
Scalar y() const
Definition: Quaternion.h:62
Scalar & y()
Definition: Quaternion.h:71
Quaternion(const Scalar *data)
Constructs and initialize a quaternion from the array data.
Definition: Quaternion.h:253
Matrix< Scalar, 3, 3 > Matrix3
the equivalent rotation matrix type
Definition: Quaternion.h:53
VectorBlock< Coefficients, 3 > vec()
Definition: Quaternion.h:81
Used in JacobiSVD to indicate that the square matrix V is to be computed.
Definition: Constants.h:331
Quaternion< float > Quaternionf
single precision quaternion type
Definition: Quaternion.h:208
EIGEN_STRONG_INLINE Vector3 _transformVector(const Vector3 &v) const
return the result vector of v through the rotation
Definition: Quaternion.h:464
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Definition: ForwardDeclarations.h:235
Matrix3 toRotationMatrix() const
Convert the quaternion to a 3x3 rotation matrix.
Definition: Quaternion.h:525
Definition: ForwardDeclarations.h:17
Scalar w() const
Definition: Quaternion.h:66
const internal::traits< Derived >::Coefficients & coeffs() const
Definition: Quaternion.h:84
double Scalar
Common scalar type.
Definition: FlexibleKalmanBase.h:48
Map< Quaternion< double >, Aligned > QuaternionMapAlignedd
Map a 16-byte aligned array of double precision scalars as a quaternion.
Definition: Quaternion.h:410