Quaternion.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2009 Mathieu Gautier <mathieu.gautier@cea.fr>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_QUATERNION_H
12 #define EIGEN_QUATERNION_H
13 #include "./InternalHeaderCheck.h"
14 
15 namespace Eigen {
16 
17 
18 
23 namespace internal {
24 template<typename Other,
25  int OtherRows=Other::RowsAtCompileTime,
26  int OtherCols=Other::ColsAtCompileTime>
27 struct quaternionbase_assign_impl;
28 }
29 
36 template<class Derived>
37 class QuaternionBase : public RotationBase<Derived, 3>
38 {
39  public:
41 
42  using Base::operator*;
43  using Base::derived;
44 
45  typedef typename internal::traits<Derived>::Scalar Scalar;
47  typedef typename internal::traits<Derived>::Coefficients Coefficients;
48  typedef typename Coefficients::CoeffReturnType CoeffReturnType;
49  typedef std::conditional_t<bool(internal::traits<Derived>::Flags&LvalueBit),
51 
52 
53  enum {
54  Flags = Eigen::internal::traits<Derived>::Flags
55  };
56 
57  // typedef typename Matrix<Scalar,4,1> Coefficients;
64 
65 
66 
68  EIGEN_DEVICE_FUNC inline CoeffReturnType x() const { return this->derived().coeffs().coeff(0); }
70  EIGEN_DEVICE_FUNC inline CoeffReturnType y() const { return this->derived().coeffs().coeff(1); }
72  EIGEN_DEVICE_FUNC inline CoeffReturnType z() const { return this->derived().coeffs().coeff(2); }
74  EIGEN_DEVICE_FUNC inline CoeffReturnType w() const { return this->derived().coeffs().coeff(3); }
75 
77  EIGEN_DEVICE_FUNC inline NonConstCoeffReturnType x() { return this->derived().coeffs().x(); }
79  EIGEN_DEVICE_FUNC inline NonConstCoeffReturnType y() { return this->derived().coeffs().y(); }
81  EIGEN_DEVICE_FUNC inline NonConstCoeffReturnType z() { return this->derived().coeffs().z(); }
83  EIGEN_DEVICE_FUNC inline NonConstCoeffReturnType w() { return this->derived().coeffs().w(); }
84 
86  EIGEN_DEVICE_FUNC inline const VectorBlock<const Coefficients,3> vec() const { return coeffs().template head<3>(); }
87 
89  EIGEN_DEVICE_FUNC inline VectorBlock<Coefficients,3> vec() { return coeffs().template head<3>(); }
90 
92  EIGEN_DEVICE_FUNC inline const typename internal::traits<Derived>::Coefficients& coeffs() const { return derived().coeffs(); }
93 
95  EIGEN_DEVICE_FUNC inline typename internal::traits<Derived>::Coefficients& coeffs() { return derived().coeffs(); }
96 
98  template<class OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const QuaternionBase<OtherDerived>& other);
99 
100 // disabled this copy operator as it is giving very strange compilation errors when compiling
101 // test_stdvector with GCC 4.4.2. This looks like a GCC bug though, so feel free to re-enable it if it's
102 // useful; however notice that we already have the templated operator= above and e.g. in MatrixBase
103 // we didn't have to add, in addition to templated operator=, such a non-templated copy operator.
104 // Derived& operator=(const QuaternionBase& other)
105 // { return operator=<Derived>(other); }
106 
108  template<class OtherDerived> EIGEN_DEVICE_FUNC Derived& operator=(const MatrixBase<OtherDerived>& m);
109 
114 
117  EIGEN_DEVICE_FUNC inline QuaternionBase& setIdentity() { coeffs() << Scalar(0), Scalar(0), Scalar(0), Scalar(1); return *this; }
118 
122  EIGEN_DEVICE_FUNC inline Scalar squaredNorm() const { return coeffs().squaredNorm(); }
123 
127  EIGEN_DEVICE_FUNC inline Scalar norm() const { return coeffs().norm(); }
128 
131  EIGEN_DEVICE_FUNC inline void normalize() { coeffs().normalize(); }
135 
141  template<class OtherDerived> EIGEN_DEVICE_FUNC inline Scalar dot(const QuaternionBase<OtherDerived>& other) const { return coeffs().dot(other.coeffs()); }
142 
143  template<class OtherDerived> EIGEN_DEVICE_FUNC Scalar angularDistance(const QuaternionBase<OtherDerived>& other) const;
144 
147 
149  template<typename Derived1, typename Derived2>
151 
152  template<class OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Quaternion<Scalar> operator* (const QuaternionBase<OtherDerived>& q) const;
153  template<class OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator*= (const QuaternionBase<OtherDerived>& q);
154 
157 
160 
161  template<class OtherDerived> EIGEN_DEVICE_FUNC Quaternion<Scalar> slerp(const Scalar& t, const QuaternionBase<OtherDerived>& other) const;
162 
167  template<class OtherDerived>
169  { return coeffs() == other.coeffs(); }
170 
175  template<class OtherDerived>
177  { return coeffs() != other.coeffs(); }
178 
183  template<class OtherDerived>
185  { return coeffs().isApprox(other.coeffs(), prec); }
186 
188  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Vector3 _transformVector(const Vector3& v) const;
189 
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;
198 
199  #else
200 
201  template<typename NewScalarType>
202  EIGEN_DEVICE_FUNC inline
203  std::enable_if_t<internal::is_same<Scalar,NewScalarType>::value,const Derived&> cast() const
204  {
205  return derived();
206  }
207 
208  template<typename NewScalarType>
209  EIGEN_DEVICE_FUNC inline
210  std::enable_if_t<!internal::is_same<Scalar,NewScalarType>::value,Quaternion<NewScalarType> > cast() const
211  {
212  return Quaternion<NewScalarType>(coeffs().template cast<NewScalarType>());
213  }
214  #endif
215 
216 #ifndef EIGEN_NO_IO
217  friend std::ostream& operator<<(std::ostream& s, const QuaternionBase<Derived>& q) {
218  s << q.x() << "i + " << q.y() << "j + " << q.z() << "k" << " + " << q.w();
219  return s;
220  }
221 #endif
222 
223 #ifdef EIGEN_QUATERNIONBASE_PLUGIN
224 # include EIGEN_QUATERNIONBASE_PLUGIN
225 #endif
226 protected:
229 };
230 
231 
260 namespace internal {
261 template<typename Scalar_,int Options_>
262 struct traits<Quaternion<Scalar_,Options_> >
263 {
264  typedef Quaternion<Scalar_,Options_> PlainObject;
265  typedef Scalar_ Scalar;
266  typedef Matrix<Scalar_,4,1,Options_> Coefficients;
267  enum{
268  Alignment = internal::traits<Coefficients>::Alignment,
269  Flags = LvalueBit
270  };
271 };
272 }
273 
274 template<typename Scalar_, int Options_>
275 class Quaternion : public QuaternionBase<Quaternion<Scalar_,Options_> >
276 {
277 public:
279  enum { NeedsAlignment = internal::traits<Quaternion>::Alignment>0 };
280 
281  typedef Scalar_ Scalar;
282 
284  using Base::operator*=;
285 
286  typedef typename internal::traits<Quaternion>::Coefficients Coefficients;
288 
291 
299  EIGEN_DEVICE_FUNC inline Quaternion(const Scalar& w, const Scalar& x, const Scalar& y, const Scalar& z) : m_coeffs(x, y, z, w){}
300 
304  template <typename Derived>
306  : m_coeffs(vec.x(), vec.y(), vec.z(), w) {
308  }
309 
311  EIGEN_DEVICE_FUNC explicit inline Quaternion(const Scalar* data) : m_coeffs(data) {}
312 
314  template<class Derived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Quaternion(const QuaternionBase<Derived>& other) { this->Base::operator=(other); }
315 
317  EIGEN_DEVICE_FUNC explicit inline Quaternion(const AngleAxisType& aa) { *this = aa; }
318 
323  template<typename Derived>
324  EIGEN_DEVICE_FUNC explicit inline Quaternion(const MatrixBase<Derived>& other) { *this = other; }
325 
327  template<typename OtherScalar, int OtherOptions>
329  { m_coeffs = other.coeffs().template cast<Scalar>(); }
330 
331  // We define a copy constructor, which means we don't get an implicit move constructor or assignment operator.
333  EIGEN_DEVICE_FUNC inline Quaternion(Quaternion&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_constructible<Scalar>::value)
334  : m_coeffs(std::move(other.coeffs()))
335  {}
336 
338  EIGEN_DEVICE_FUNC Quaternion& operator=(Quaternion&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_assignable<Scalar>::value)
339  {
340  m_coeffs = std::move(other.coeffs());
341  return *this;
342  }
343 
345 
346  template<typename Derived1, typename Derived2>
348 
350  EIGEN_DEVICE_FUNC inline const Coefficients& coeffs() const { return m_coeffs;}
351 
352  EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(bool(NeedsAlignment))
353 
354 #ifdef EIGEN_QUATERNION_PLUGIN
355 # include EIGEN_QUATERNION_PLUGIN
356 #endif
357 
358 protected:
360 
361 #ifndef EIGEN_PARSED_BY_DOXYGEN
362  EIGEN_STATIC_ASSERT( (Options_ & DontAlign) == Options_,
363  INVALID_MATRIX_TEMPLATE_PARAMETERS)
364 #endif
365 };
366 
373 
374 
378 namespace internal {
379  template<typename Scalar_, int Options_>
380  struct traits<Map<Quaternion<Scalar_>, Options_> > : traits<Quaternion<Scalar_, (int(Options_)&Aligned)==Aligned ? AutoAlign : DontAlign> >
381  {
382  typedef Map<Matrix<Scalar_,4,1>, Options_> Coefficients;
383  };
384 }
385 
386 namespace internal {
387  template<typename Scalar_, int Options_>
388  struct traits<Map<const Quaternion<Scalar_>, Options_> > : traits<Quaternion<Scalar_, (int(Options_)&Aligned)==Aligned ? AutoAlign : DontAlign> >
389  {
390  typedef Map<const Matrix<Scalar_,4,1>, Options_> Coefficients;
391  typedef traits<Quaternion<Scalar_, (int(Options_)&Aligned)==Aligned ? AutoAlign : DontAlign> > TraitsBase;
392  enum {
393  Flags = TraitsBase::Flags & ~LvalueBit
394  };
395  };
396 }
397 
409 template<typename Scalar_, int Options_>
410 class Map<const Quaternion<Scalar_>, Options_ >
411  : public QuaternionBase<Map<const Quaternion<Scalar_>, Options_> >
412 {
413  public:
415 
416  typedef Scalar_ Scalar;
417  typedef typename internal::traits<Map>::Coefficients Coefficients;
419  using Base::operator*=;
420 
427  EIGEN_DEVICE_FUNC explicit EIGEN_STRONG_INLINE Map(const Scalar* coeffs) : m_coeffs(coeffs) {}
428 
429  EIGEN_DEVICE_FUNC inline const Coefficients& coeffs() const { return m_coeffs;}
430 
431  protected:
433 };
434 
446 template<typename Scalar_, int Options_>
447 class Map<Quaternion<Scalar_>, Options_ >
448  : public QuaternionBase<Map<Quaternion<Scalar_>, Options_> >
449 {
450  public:
452 
453  typedef Scalar_ Scalar;
454  typedef typename internal::traits<Map>::Coefficients Coefficients;
456  using Base::operator*=;
457 
464  EIGEN_DEVICE_FUNC explicit EIGEN_STRONG_INLINE Map(Scalar* coeffs) : m_coeffs(coeffs) {}
465 
466  EIGEN_DEVICE_FUNC inline Coefficients& coeffs() { return m_coeffs; }
467  EIGEN_DEVICE_FUNC inline const Coefficients& coeffs() const { return m_coeffs; }
468 
469  protected:
471 };
472 
485 
486 
490 // Generic Quaternion * Quaternion product
491 // This product can be specialized for a given architecture via the Arch template argument.
492 namespace internal {
493 template<int Arch, class Derived1, class Derived2, typename Scalar> struct quat_product
494 {
495  EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Quaternion<Scalar> run(const QuaternionBase<Derived1>& a, const QuaternionBase<Derived2>& b){
496  return Quaternion<Scalar>
497  (
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()
502  );
503  }
504 };
505 }
506 
508 template <class Derived>
509 template <class OtherDerived>
512 {
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)
515  return internal::quat_product<Architecture::Target, Derived, OtherDerived,
516  typename internal::traits<Derived>::Scalar>::run(*this, other);
517 }
518 
520 template <class Derived>
521 template <class OtherDerived>
523 {
524  derived() = derived() * other.derived();
525  return derived();
526 }
527 
535 template <class Derived>
536 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename QuaternionBase<Derived>::Vector3
538 {
539  // Note that this algorithm comes from the optimization by hand
540  // of the conversion to a Matrix followed by a Matrix/Vector product.
541  // It appears to be much faster than the common algorithm found
542  // in the literature (30 versus 39 flops). It also requires two
543  // Vector3 as temporaries.
544  Vector3 uv = this->vec().cross(v);
545  uv += uv;
546  return v + this->w() * uv + this->vec().cross(uv);
547 }
548 
549 template<class Derived>
551 {
552  coeffs() = other.coeffs();
553  return derived();
554 }
555 
556 template<class Derived>
557 template<class OtherDerived>
559 {
560  coeffs() = other.coeffs();
561  return derived();
562 }
563 
566 template<class Derived>
568 {
571  Scalar ha = Scalar(0.5)*aa.angle(); // Scalar(0.5) to suppress precision loss warnings
572  this->w() = cos(ha);
573  this->vec() = sin(ha) * aa.axis();
574  return derived();
575 }
576 
583 template<class Derived>
584 template<class MatrixDerived>
586 {
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());
590  return derived();
591 }
592 
596 template<class Derived>
599 {
600  // NOTE if inlined, then gcc 4.2 and 4.4 get rid of the temporary (not gcc 4.3 !!)
601  // if not inlined then the cost of the return by value is huge ~ +35%,
602  // however, not inlining this function is an order of magnitude slower, so
603  // it has to be inlined, and so the return by value is not an issue
604  Matrix3 res;
605 
606  const Scalar tx = Scalar(2)*this->x();
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();
618 
619  res.coeffRef(0,0) = Scalar(1)-(tyy+tzz);
620  res.coeffRef(0,1) = txy-twz;
621  res.coeffRef(0,2) = txz+twy;
622  res.coeffRef(1,0) = txy+twz;
623  res.coeffRef(1,1) = Scalar(1)-(txx+tzz);
624  res.coeffRef(1,2) = tyz-twx;
625  res.coeffRef(2,0) = txz-twy;
626  res.coeffRef(2,1) = tyz+twx;
627  res.coeffRef(2,2) = Scalar(1)-(txx+tyy);
628 
629  return res;
630 }
631 
642 template<class Derived>
643 template<typename Derived1, typename Derived2>
645 {
647  Vector3 v0 = a.normalized();
648  Vector3 v1 = b.normalized();
649  Scalar c = v1.dot(v0);
650 
651  // if dot == -1, vectors are nearly opposites
652  // => accurately compute the rotation axis by computing the
653  // intersection of the two planes. This is done by solving:
654  // x^T v0 = 0
655  // x^T v1 = 0
656  // under the constraint:
657  // ||x|| = 1
658  // which yields a singular value problem
660  {
661  c = numext::maxi(c,Scalar(-1));
662  Matrix<Scalar,2,3> m; m << v0.transpose(), v1.transpose();
664  Vector3 axis = svd.matrixV().col(2);
665 
666  Scalar w2 = (Scalar(1)+c)*Scalar(0.5);
667  this->w() = sqrt(w2);
668  this->vec() = axis * sqrt(Scalar(1) - w2);
669  return derived();
670  }
671  Vector3 axis = v0.cross(v1);
672  Scalar s = sqrt((Scalar(1)+c)*Scalar(2));
673  Scalar invs = Scalar(1)/s;
674  this->vec() = axis * invs;
675  this->w() = s * Scalar(0.5);
676 
677  return derived();
678 }
679 
684 template<typename Scalar, int Options>
686 {
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);
693  const Scalar a = sqrt(Scalar(1) - u1),
694  b = sqrt(u1);
695  return Quaternion (a * sin(u2), a * cos(u2), b * sin(u3), b * cos(u3));
696 }
697 
698 
709 template<typename Scalar, int Options>
710 template<typename Derived1, typename Derived2>
712 {
713  Quaternion quat;
714  quat.setFromTwoVectors(a, b);
715  return quat;
716 }
717 
718 
725 template <class Derived>
727 {
728  // FIXME should this function be called multiplicativeInverse and conjugate() be called inverse() or opposite() ??
729  Scalar n2 = this->squaredNorm();
730  if (n2 > Scalar(0))
731  return Quaternion<Scalar>(conjugate().coeffs() / n2);
732  else
733  {
734  // return an invalid result to flag the error
735  return Quaternion<Scalar>(Coefficients::Zero());
736  }
737 }
738 
739 // Generic conjugate of a Quaternion
740 namespace internal {
741 template<int Arch, class Derived, typename Scalar> struct quat_conj
742 {
743  EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Quaternion<Scalar> run(const QuaternionBase<Derived>& q){
744  return Quaternion<Scalar>(q.w(),-q.x(),-q.y(),-q.z());
745  }
746 };
747 }
748 
755 template <class Derived>
758 {
759  return internal::quat_conj<Architecture::Target, Derived,
760  typename internal::traits<Derived>::Scalar>::run(*this);
761 
762 }
763 
767 template <class Derived>
768 template <class OtherDerived>
769 EIGEN_DEVICE_FUNC inline typename internal::traits<Derived>::Scalar
771 {
773  Quaternion<Scalar> d = (*this) * other.conjugate();
774  return Scalar(2) * atan2( d.vec().norm(), numext::abs(d.w()) );
775 }
776 
777 
778 
785 template <class Derived>
786 template <class OtherDerived>
789 {
792  const Scalar one = Scalar(1) - NumTraits<Scalar>::epsilon();
793  Scalar d = this->dot(other);
794  Scalar absD = numext::abs(d);
795 
796  Scalar scale0;
797  Scalar scale1;
798 
799  if(absD>=one)
800  {
801  scale0 = Scalar(1) - t;
802  scale1 = t;
803  }
804  else
805  {
806  // theta is the angle between the 2 quaternions
807  Scalar theta = acos(absD);
808  Scalar sinTheta = sin(theta);
809 
810  scale0 = sin( ( Scalar(1) - t ) * theta) / sinTheta;
811  scale1 = sin( ( t * theta) ) / sinTheta;
812  }
813  if(d<Scalar(0)) scale1 = -scale1;
814 
815  return Quaternion<Scalar>(scale0 * coeffs() + scale1 * other.coeffs());
816 }
817 
818 namespace internal {
819 
820 // set from a rotation matrix
821 template<typename Other>
822 struct quaternionbase_assign_impl<Other,3,3>
823 {
824  typedef typename Other::Scalar Scalar;
825  template<class Derived> EIGEN_DEVICE_FUNC static inline void run(QuaternionBase<Derived>& q, const Other& a_mat)
826  {
827  const typename internal::nested_eval<Other,2>::type mat(a_mat);
829  // This algorithm comes from "Quaternion Calculus and Fast Animation",
830  // Ken Shoemake, 1987 SIGGRAPH course notes
831  Scalar t = mat.trace();
832  if (t > Scalar(0))
833  {
834  t = sqrt(t + Scalar(1.0));
835  q.w() = Scalar(0.5)*t;
836  t = 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;
840  }
841  else
842  {
843  Index i = 0;
844  if (mat.coeff(1,1) > mat.coeff(0,0))
845  i = 1;
846  if (mat.coeff(2,2) > mat.coeff(i,i))
847  i = 2;
848  Index j = (i+1)%3;
849  Index k = (j+1)%3;
850 
851  t = sqrt(mat.coeff(i,i)-mat.coeff(j,j)-mat.coeff(k,k) + Scalar(1.0));
852  q.coeffs().coeffRef(i) = Scalar(0.5) * t;
853  t = Scalar(0.5)/t;
854  q.w() = (mat.coeff(k,j)-mat.coeff(j,k))*t;
855  q.coeffs().coeffRef(j) = (mat.coeff(j,i)+mat.coeff(i,j))*t;
856  q.coeffs().coeffRef(k) = (mat.coeff(k,i)+mat.coeff(i,k))*t;
857  }
858  }
859 };
860 
861 // set from a vector of coefficients assumed to be a quaternion
862 template<typename Other>
863 struct quaternionbase_assign_impl<Other,4,1>
864 {
865  typedef typename Other::Scalar Scalar;
866  template<class Derived> EIGEN_DEVICE_FUNC static inline void run(QuaternionBase<Derived>& q, const Other& vec)
867  {
868  q.coeffs() = vec;
869  }
870 };
871 
872 } // end namespace internal
873 
874 } // end namespace Eigen
875 
876 #endif // EIGEN_QUATERNION_H
Matrix3f m
const CwiseBinaryOp< atan2< Scalar >, const Derived, const OtherDerived > atan2(const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
Array< int, Dynamic, 1 > v
Array< int, 3, 1 > b
ConjugateReturnType conjugate() const
Array33i c
cout<< "Here is the matrix m:"<< endl<< m<< endl;JacobiSVD< MatrixXf, ComputeThinU|ComputeThinV > svd(m)
#define EIGEN_DEFAULT_COPY_CONSTRUCTOR(CLASS)
Definition: Macros.h:1113
#define EIGEN_NOEXCEPT_IF(x)
Definition: Macros.h:1261
#define EIGEN_USING_STD(FUNC)
Definition: Macros.h:1080
#define EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(Derived)
Definition: Macros.h:1133
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:883
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived)
Definition: Macros.h:1122
int data[]
#define EIGEN_PI
Definition: MathFunctions.h:16
RowVector3d w
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign)
Definition: Memory.h:917
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
#define EIGEN_STATIC_ASSERT(X, MSG)
Definition: StaticAssert.h:26
#define EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(TYPE, SIZE)
Definition: StaticAssert.h:51
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.
Definition: AngleAxis.h:52
const Vector3 & axis() const
Definition: AngleAxis.h:98
Scalar angle() const
Definition: AngleAxis.h:93
Two-sided Jacobi SVD decomposition of a rectangular matrix.
Definition: JacobiSVD.h:514
const Coefficients & coeffs() const
Definition: Quaternion.h:467
internal::traits< Map >::Coefficients Coefficients
Definition: Quaternion.h:454
QuaternionBase< Map< Quaternion< Scalar_ >, Options_ > > Base
Definition: Quaternion.h:451
QuaternionBase< Map< const Quaternion< Scalar_ >, Options_ > > Base
Definition: Quaternion.h:414
internal::traits< Map >::Coefficients Coefficients
Definition: Quaternion.h:417
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:98
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
Base class for quaternion expressions.
Definition: Quaternion.h:38
QuaternionBase< Derived > & operator=(const QuaternionBase< Derived > &other)
Definition: Quaternion.h:550
Scalar squaredNorm() const
Definition: Quaternion.h:122
Derived & operator=(const MatrixBase< OtherDerived > &m)
const internal::traits< Derived >::Coefficients & coeffs() const
Definition: Quaternion.h:92
friend std::ostream & operator<<(std::ostream &s, const QuaternionBase< Derived > &q)
Definition: Quaternion.h:217
QuaternionBase & setIdentity()
Definition: Quaternion.h:117
Scalar angularDistance(const QuaternionBase< OtherDerived > &other) const
bool operator!=(const QuaternionBase< OtherDerived > &other) const
Definition: Quaternion.h:176
Quaternion< Scalar > conjugate() const
Definition: Quaternion.h:757
NonConstCoeffReturnType y()
Definition: Quaternion.h:79
std::conditional_t< bool(internal::traits< Derived >::Flags &LvalueBit), Scalar &, CoeffReturnType > NonConstCoeffReturnType
Definition: Quaternion.h:50
bool isApprox(const QuaternionBase< OtherDerived > &other, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: Quaternion.h:184
static Quaternion< Scalar > Identity()
Definition: Quaternion.h:113
Derived & setFromTwoVectors(const MatrixBase< Derived1 > &a, const MatrixBase< Derived2 > &b)
Definition: Quaternion.h:644
CoeffReturnType z() const
Definition: Quaternion.h:72
NonConstCoeffReturnType x()
Definition: Quaternion.h:77
Matrix3 toRotationMatrix() const
Definition: Quaternion.h:598
VectorBlock< Coefficients, 3 > vec()
Definition: Quaternion.h:89
internal::cast_return_type< Derived, Quaternion< NewScalarType > >::type cast() const
Matrix< Scalar, 3, 1 > Vector3
Definition: Quaternion.h:59
NonConstCoeffReturnType z()
Definition: Quaternion.h:81
Scalar dot(const QuaternionBase< OtherDerived > &other) const
Definition: Quaternion.h:141
Derived & operator=(const AngleAxisType &aa)
Definition: Quaternion.h:567
Vector3 _transformVector(const Vector3 &v) const
Definition: Quaternion.h:537
CoeffReturnType y() const
Definition: Quaternion.h:70
Scalar norm() const
Definition: Quaternion.h:127
Quaternion< Scalar > inverse() const
Definition: Quaternion.h:726
CoeffReturnType w() const
Definition: Quaternion.h:74
Derived & operator=(const QuaternionBase< OtherDerived > &other)
Definition: Quaternion.h:558
Matrix< Scalar, 3, 3 > Matrix3
Definition: Quaternion.h:61
internal::traits< Derived >::Coefficients Coefficients
Definition: Quaternion.h:47
Quaternion< Scalar > slerp(const Scalar &t, const QuaternionBase< OtherDerived > &other) const
RotationBase< Derived, 3 > Base
Definition: Quaternion.h:40
bool operator==(const QuaternionBase< OtherDerived > &other) const
Definition: Quaternion.h:168
Quaternion< Scalar > operator*(const QuaternionBase< OtherDerived > &q) const
Coefficients::CoeffReturnType CoeffReturnType
Definition: Quaternion.h:48
NonConstCoeffReturnType w()
Definition: Quaternion.h:83
const VectorBlock< const Coefficients, 3 > vec() const
Definition: Quaternion.h:86
Quaternion< Scalar > normalized() const
Definition: Quaternion.h:134
NumTraits< Scalar >::Real RealScalar
Definition: Quaternion.h:46
internal::traits< Derived >::Coefficients & coeffs()
Definition: Quaternion.h:95
internal::traits< Derived >::Scalar Scalar
Definition: Quaternion.h:45
AngleAxis< Scalar > AngleAxisType
Definition: Quaternion.h:63
Derived & operator*=(const QuaternionBase< OtherDerived > &q)
Definition: Quaternion.h:522
CoeffReturnType x() const
Definition: Quaternion.h:68
The quaternion class used to represent 3D orientations and rotations.
Definition: Quaternion.h:276
Quaternion & operator=(Quaternion &&other) EIGEN_NOEXCEPT_IF(std
Definition: Quaternion.h:338
Base::AngleAxisType AngleAxisType
Definition: Quaternion.h:287
QuaternionBase< Quaternion< Scalar_, Options_ > > Base
Definition: Quaternion.h:278
Quaternion(const Quaternion< OtherScalar, OtherOptions > &other)
Definition: Quaternion.h:328
Coefficients m_coeffs
Definition: Quaternion.h:359
Quaternion(const Scalar &w, const Scalar &x, const Scalar &y, const Scalar &z)
Definition: Quaternion.h:299
Quaternion(const QuaternionBase< Derived > &other)
Definition: Quaternion.h:314
static Quaternion FromTwoVectors(const MatrixBase< Derived1 > &a, const MatrixBase< Derived2 > &b)
Quaternion(const Scalar &w, const Eigen::MatrixBase< Derived > &vec)
Definition: Quaternion.h:305
internal::traits< Quaternion >::Coefficients Coefficients
Definition: Quaternion.h:286
static Quaternion UnitRandom()
Definition: Quaternion.h:685
Quaternion(const MatrixBase< Derived > &other)
Definition: Quaternion.h:324
Quaternion(const AngleAxisType &aa)
Definition: Quaternion.h:317
const Coefficients & coeffs() const
Definition: Quaternion.h:350
Quaternion(Quaternion &&other) EIGEN_NOEXCEPT_IF(std
Definition: Quaternion.h:333
Coefficients & coeffs()
Definition: Quaternion.h:349
Quaternion(const Scalar *data)
Definition: Quaternion.h:311
Common base class for compact rotation representations.
Definition: RotationBase.h:32
const Derived & derived() const
Definition: RotationBase.h:43
Expression of a fixed-size or dynamic-size sub-vector.
Definition: VectorBlock.h:62
Map< Quaternion< double >, Aligned > QuaternionMapAlignedd
Definition: Quaternion.h:484
Quaternion< double > Quaterniond
Definition: Quaternion.h:372
Quaternion< float > Quaternionf
Definition: Quaternion.h:369
Map< Quaternion< float >, 0 > QuaternionMapf
Definition: Quaternion.h:475
Map< Quaternion< double >, 0 > QuaternionMapd
Definition: Quaternion.h:478
Map< Quaternion< float >, Aligned > QuaternionMapAlignedf
Definition: Quaternion.h:481
@ Aligned
Definition: Constants.h:242
@ DontAlign
Definition: Constants.h:327
@ AutoAlign
Definition: Constants.h:325
@ ComputeFullV
Definition: Constants.h:399
const unsigned int LvalueBit
Definition: Constants.h:146
const Scalar & y
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)
: InteropHeaders
Definition: Core:139
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.
Definition: Meta.h:82
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)
Definition: BFloat16.h:222
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:231
std::ptrdiff_t j