11#ifndef EIGEN_QUATERNION_H
12#define EIGEN_QUATERNION_H
22template<
typename Other,
23 int OtherRows=Other::RowsAtCompileTime,
24 int OtherCols=Other::ColsAtCompileTime>
34template<
class Derived>
40 using Base::operator*;
44 typedef typename NumTraits<Scalar>::Real
RealScalar;
61 inline Scalar
x()
const {
return this->derived().coeffs().coeff(0); }
63 inline Scalar
y()
const {
return this->derived().coeffs().coeff(1); }
65 inline Scalar
z()
const {
return this->derived().coeffs().coeff(2); }
67 inline Scalar
w()
const {
return this->derived().coeffs().coeff(3); }
70 inline Scalar&
x() {
return this->derived().coeffs().coeffRef(0); }
72 inline Scalar&
y() {
return this->derived().coeffs().coeffRef(1); }
74 inline Scalar&
z() {
return this->derived().coeffs().coeffRef(2); }
76 inline Scalar&
w() {
return this->derived().coeffs().coeffRef(3); }
142 template<
typename Derived1,
typename Derived2>
160 template<
class OtherDerived>
162 {
return coeffs().isApprox(other.coeffs(),
prec); }
172 template<
typename NewScalarType>
178#ifdef EIGEN_QUATERNIONBASE_PLUGIN
179# include EIGEN_QUATERNIONBASE_PLUGIN
213template<
typename _Scalar,
int _Options>
217 typedef _Scalar Scalar;
226template<
typename _Scalar,
int _Options>
233 typedef _Scalar Scalar;
235 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(
Quaternion)
236 using Base::operator*=;
251 inline Quaternion(
const Scalar&
w,
const Scalar&
x,
const Scalar&
y,
const Scalar&
z) : m_coeffs(
x,
y,
z,
w){}
254 explicit inline Quaternion(
const Scalar* data) : m_coeffs(data) {}
266 template<
typename Derived>
270 template<
typename OtherScalar,
int OtherOptions>
274 template<
typename Derived1,
typename Derived2>
277 inline Coefficients& coeffs() {
return m_coeffs;}
278 inline const Coefficients& coeffs()
const {
return m_coeffs;}
280 EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsAlignment)
282#ifdef EIGEN_QUATERNION_PLUGIN
283# include EIGEN_QUATERNION_PLUGIN
287 Coefficients m_coeffs;
289#ifndef EIGEN_PARSED_BY_DOXYGEN
290 static EIGEN_STRONG_INLINE
void _check_template_params()
292 EIGEN_STATIC_ASSERT( (_Options &
DontAlign) == _Options,
293 INVALID_MATRIX_TEMPLATE_PARAMETERS)
310 template<
typename _Scalar,
int _Options>
311 struct traits<
Map<
Quaternion<_Scalar>, _Options> > :
traits<Quaternion<_Scalar, (int(_Options)&Aligned)==Aligned ? AutoAlign : DontAlign> >
318 template<
typename _Scalar,
int _Options>
324 Flags = TraitsBase::Flags & ~LvalueBit
340template<
typename _Scalar,
int _Options>
342 :
public QuaternionBase<Map<const Quaternion<_Scalar>, _Options> >
347 typedef _Scalar Scalar;
349 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(
Map)
350 using Base::operator*=;
358 explicit EIGEN_STRONG_INLINE
Map(
const Scalar* coeffs) : m_coeffs(coeffs) {}
360 inline const Coefficients& coeffs()
const {
return m_coeffs;}
363 const Coefficients m_coeffs;
377template<
typename _Scalar,
int _Options>
384 typedef _Scalar Scalar;
386 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(
Map)
387 using Base::operator*=;
395 explicit EIGEN_STRONG_INLINE
Map(Scalar* coeffs) : m_coeffs(coeffs) {}
397 inline Coefficients& coeffs() {
return m_coeffs; }
398 inline const Coefficients& coeffs()
const {
return m_coeffs; }
401 Coefficients m_coeffs;
424template<
int Arch,
class Derived1,
class Derived2,
typename Scalar,
int _Options>
struct quat_product
429 a.w() * b.w() - a.x() * b.x() - a.y() * b.y() - a.z() * b.z(),
430 a.w() * b.x() + a.x() * b.w() + a.y() * b.z() - a.z() * b.y(),
431 a.w() * b.y() + a.y() * b.w() + a.z() * b.x() - a.x() * b.z(),
432 a.w() * b.z() + a.z() * b.w() + a.x() * b.y() - a.y() * b.x()
439template <
class Derived>
440template <
class OtherDerived>
445 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
452template <
class Derived>
453template <
class OtherDerived>
456 derived() = derived() * other.derived();
467template <
class Derived>
478 return v + this->w() *
uv + this->vec().cross(
uv);
481template<
class Derived>
484 coeffs() = other.coeffs();
488template<
class Derived>
489template<
class OtherDerived>
490EIGEN_STRONG_INLINE Derived& QuaternionBase<Derived>::operator=(
const QuaternionBase<OtherDerived>& other)
492 coeffs() = other.coeffs();
498template<
class Derived>
503 Scalar
ha = Scalar(0.5)*
aa.angle();
505 this->vec() = sin(
ha) *
aa.axis();
515template<
class Derived>
516template<
class MatrixDerived>
520 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
528template<
class Derived>
538 const Scalar
tx = Scalar(2)*this->x();
539 const Scalar
ty = Scalar(2)*this->y();
540 const Scalar
tz = Scalar(2)*this->z();
541 const Scalar
twx =
tx*this->w();
542 const Scalar
twy =
ty*this->w();
543 const Scalar
twz =
tz*this->w();
544 const Scalar
txx =
tx*this->x();
545 const Scalar
txy =
ty*this->x();
546 const Scalar
txz =
tz*this->x();
547 const Scalar
tyy =
ty*this->y();
548 const Scalar
tyz =
tz*this->y();
549 const Scalar
tzz =
tz*this->z();
551 res.coeffRef(0,0) = Scalar(1)-(
tyy+
tzz);
552 res.coeffRef(0,1) =
txy-
twz;
553 res.coeffRef(0,2) =
txz+
twy;
554 res.coeffRef(1,0) =
txy+
twz;
555 res.coeffRef(1,1) = Scalar(1)-(
txx+
tzz);
556 res.coeffRef(1,2) =
tyz-
twx;
557 res.coeffRef(2,0) =
txz-
twy;
558 res.coeffRef(2,1) =
tyz+
twx;
559 res.coeffRef(2,2) = Scalar(1)-(
txx+
tyy);
574template<
class Derived>
575template<
typename Derived1,
typename Derived2>
581 Scalar c =
v1.dot(
v0);
593 c = numext::maxi(c,Scalar(-1));
598 Scalar
w2 = (Scalar(1)+c)*Scalar(0.5);
599 this->w() = sqrt(
w2);
600 this->vec() = axis * sqrt(Scalar(1) -
w2);
604 Scalar s = sqrt((Scalar(1)+c)*Scalar(2));
605 Scalar
invs = Scalar(1)/s;
606 this->vec() = axis *
invs;
607 this->w() = s * Scalar(0.5);
623template<
typename Scalar,
int Options>
624template<
typename Derived1,
typename Derived2>
628 quat.setFromTwoVectors(a, b);
639template <
class Derived>
643 Scalar
n2 = this->squaredNorm();
655template<
int Arch,
class Derived,
typename Scalar,
int _Options>
struct quat_conj
669template <
class Derived>
682template <
class Derived>
683template <
class OtherDerived>
690 return Scalar(2) *
atan2( d.vec().norm(), abs(d.w()) );
701template <
class Derived>
702template <
class OtherDerived>
710 Scalar d = this->dot(other);
711 Scalar
absD = abs(d);
738template<
typename Other>
741 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;
779template<
typename Other>
782 typedef typename Other::Scalar Scalar;
\geometry_module
Definition AngleAxis.h:50
EIGEN_STRONG_INLINE Map(Scalar *coeffs)
Constructs a Mapped Quaternion object from the pointer coeffs.
Definition Quaternion.h:395
EIGEN_STRONG_INLINE Map(const Scalar *coeffs)
Constructs a Mapped Quaternion object from the pointer coeffs.
Definition Quaternion.h:358
A matrix or vector expression mapping an existing array of data.
Definition Map.h:91
\geometry_module
Definition Quaternion.h:36
Scalar y() const
Definition Quaternion.h:63
Scalar squaredNorm() const
Definition Quaternion.h:115
Scalar & y()
Definition Quaternion.h:72
QuaternionBase & setIdentity()
Definition Quaternion.h:110
Quaternion< Scalar > normalized() const
Definition Quaternion.h:127
internal::traits< Derived >::Coefficients & coeffs()
Definition Quaternion.h:88
internal::cast_return_type< Derived, Quaternion< NewScalarType > >::type cast() const
Definition Quaternion.h:173
VectorBlock< Coefficients, 3 > vec()
Definition Quaternion.h:82
const VectorBlock< const Coefficients, 3 > vec() const
Definition Quaternion.h:79
static Quaternion< Scalar > Identity()
Definition Quaternion.h:106
Scalar w() const
Definition Quaternion.h:67
Quaternion< Scalar > conjugate() const
Definition Quaternion.h:671
bool isApprox(const QuaternionBase< OtherDerived > &other, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition Quaternion.h:161
Scalar & z()
Definition Quaternion.h:74
void normalize()
Normalizes the quaternion *this.
Definition Quaternion.h:124
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:576
Derived & operator=(const AngleAxisType &aa)
Set *this from an angle-axis aa and returns a reference to *this.
Definition Quaternion.h:499
Scalar & x()
Definition Quaternion.h:70
Matrix3 toRotationMatrix() const
Convert the quaternion to a 3x3 rotation matrix.
Definition Quaternion.h:530
Matrix< Scalar, 3, 1 > Vector3
the type of a 3D vector
Definition Quaternion.h:52
Scalar dot(const QuaternionBase< OtherDerived > &other) const
Definition Quaternion.h:134
Scalar norm() const
Definition Quaternion.h:120
Quaternion< Scalar > inverse() const
Definition Quaternion.h:640
Scalar z() const
Definition Quaternion.h:65
Matrix< Scalar, 3, 3 > Matrix3
the equivalent rotation matrix type
Definition Quaternion.h:54
const internal::traits< Derived >::Coefficients & coeffs() const
Definition Quaternion.h:85
EIGEN_STRONG_INLINE Derived & operator*=(const QuaternionBase< OtherDerived > &q)
Definition Quaternion.h:454
EIGEN_STRONG_INLINE Vector3 _transformVector(const Vector3 &v) const
return the result vector of v through the rotation
Definition Quaternion.h:469
AngleAxis< Scalar > AngleAxisType
the equivalent angle-axis type
Definition Quaternion.h:56
Scalar x() const
Definition Quaternion.h:61
Scalar & w()
Definition Quaternion.h:76
\geometry_module
Definition Quaternion.h:228
EIGEN_STRONG_INLINE Quaternion(const QuaternionBase< Derived > &other)
Copy constructor.
Definition Quaternion.h:257
Quaternion(const AngleAxisType &aa)
Constructs and initializes a quaternion from the angle-axis aa.
Definition Quaternion.h:260
Quaternion(const Quaternion< OtherScalar, OtherOptions > &other)
Explicit copy constructor with scalar conversion.
Definition Quaternion.h:271
Quaternion(const MatrixBase< Derived > &other)
Constructs and initializes a quaternion from either:
Definition Quaternion.h:267
Quaternion()
Default constructor leaving the quaternion uninitialized.
Definition Quaternion.h:242
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:251
Quaternion(const Scalar *data)
Constructs and initialize a quaternion from the array data.
Definition Quaternion.h:254
Common base class for compact rotation representations.
Definition RotationBase.h:30
friend RotationMatrixType operator*(const EigenBase< OtherDerived > &l, const Derived &r)
Definition RotationBase.h:76
Pseudo expression representing a solving operation.
Definition Solve.h:63
@ Aligned
Definition Constants.h:235
@ DontAlign
Don't require alignment for the matrix itself (the array of coefficients, if dynamically allocated,...
Definition Constants.h:326
@ AutoAlign
Align the matrix itself if it is vectorizable fixed-size.
Definition Constants.h:324
@ ComputeFullV
Used in JacobiSVD to indicate that the square matrix V is to be computed.
Definition Constants.h:387
const unsigned int LvalueBit
Means the expression has a coeffRef() method, i.e.
Definition Constants.h:138
Holds information about the various numeric (i.e.
Definition NumTraits.h:108
Definition XprHelper.h:500
Definition Quaternion.h:656
Definition Quaternion.h:425
Definition Quaternion.h:25
Definition ForwardDeclarations.h:17