14 template<
typename Other,
15 int OtherRows=Other::RowsAtCompileTime,
16 int OtherCols=Other::ColsAtCompileTime>
46 template<
typename _Scalar>
52 EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,4)
54 using Base::operator*;
69 inline Scalar
x()
const {
return m_coeffs.coeff(0); }
71 inline Scalar
y()
const {
return m_coeffs.coeff(1); }
73 inline Scalar
z()
const {
return m_coeffs.coeff(2); }
75 inline Scalar
w()
const {
return m_coeffs.coeff(3); }
78 inline Scalar&
x() {
return m_coeffs.coeffRef(0); }
80 inline Scalar&
y() {
return m_coeffs.coeffRef(1); }
82 inline Scalar&
z() {
return m_coeffs.coeffRef(2); }
84 inline Scalar&
w() {
return m_coeffs.coeffRef(3); }
93 inline const Coefficients&
coeffs()
const {
return m_coeffs; }
96 inline Coefficients&
coeffs() {
return m_coeffs; }
109 { m_coeffs << x, y, z, w; }
115 explicit inline Quaternion(
const AngleAxisType& aa) { *
this = aa; }
122 template<
typename Derived>
126 Quaternion& operator=(
const AngleAxisType& aa);
127 template<
typename Derived>
142 inline Scalar
squaredNorm()
const {
return m_coeffs.squaredNorm(); }
147 inline Scalar
norm()
const {
return m_coeffs.norm(); }
163 inline Scalar angularDistance(
const Quaternion& other)
const;
165 Matrix3 toRotationMatrix(
void)
const;
167 template<
typename Derived1,
typename Derived2>
178 template<
typename Derived>
186 template<
typename NewScalarType>
191 template<
typename OtherScalarType>
193 { m_coeffs = other.
coeffs().template cast<Scalar>(); }
200 {
return m_coeffs.isApprox(other.m_coeffs, prec); }
203 Coefficients m_coeffs;
219 a.
w() * b.
w() - a.
x() * b.
x() - a.
y() * b.
y() - a.
z() * b.
z(),
220 a.
w() * b.
x() + a.
x() * b.
w() + a.
y() * b.
z() - a.
z() * b.
y(),
221 a.
w() * b.
y() + a.
y() * b.
w() + a.
z() * b.
x() - a.
x() * b.
z(),
222 a.
w() * b.
z() + a.
z() * b.
w() + a.
x() * b.
y() - a.
y() * b.
x()
227 template <
typename Scalar>
230 return ei_quaternion_product(*
this,other);
234 template <
typename Scalar>
237 return (*
this = *
this * other);
247 template <
typename Scalar>
248 template<
typename Derived>
258 uv = 2 * this->vec().cross(v);
259 return v + this->w() * uv + this->vec().cross(uv);
262 template<
typename Scalar>
265 m_coeffs = other.m_coeffs;
271 template<
typename Scalar>
274 Scalar ha =
Scalar(0.5)*aa.angle();
275 this->w() = ei_cos(ha);
276 this->vec() = ei_sin(ha) * aa.axis();
285 template<
typename Scalar>
286 template<
typename Derived>
294 template<
typename Scalar>
304 const Scalar tx =
Scalar(2)*this->x();
305 const Scalar ty =
Scalar(2)*this->y();
306 const Scalar tz =
Scalar(2)*this->z();
307 const Scalar twx = tx*this->w();
308 const Scalar twy = ty*this->w();
309 const Scalar twz = tz*this->w();
310 const Scalar txx = tx*this->x();
311 const Scalar txy = ty*this->x();
312 const Scalar txz = tz*this->x();
313 const Scalar tyy = ty*this->y();
314 const Scalar tyz = tz*this->y();
315 const Scalar tzz = tz*this->z();
317 res.coeffRef(0,0) =
Scalar(1)-(tyy+tzz);
318 res.coeffRef(0,1) = txy-twz;
319 res.coeffRef(0,2) = txz+twy;
320 res.coeffRef(1,0) = txy+twz;
321 res.coeffRef(1,1) =
Scalar(1)-(txx+tzz);
322 res.coeffRef(1,2) = tyz-twx;
323 res.coeffRef(2,0) = txz-twy;
324 res.coeffRef(2,1) = tyz+twx;
325 res.coeffRef(2,2) =
Scalar(1)-(txx+tyy);
336 template<
typename Scalar>
337 template<
typename Derived1,
typename Derived2>
342 Scalar c = v0.eigen2_dot(v1);
345 if (ei_isApprox(c,
Scalar(1)))
348 this->w() = 1; this->vec().
setZero();
352 if (ei_isApprox(c,
Scalar(-1)))
354 this->vec() = v0.unitOrthogonal();
359 Vector3 axis = v0.cross(v1);
361 Scalar invs =
Scalar(1)/s;
362 this->vec() = axis * invs;
363 this->w() = s *
Scalar(0.5);
374 template <
typename Scalar>
378 Scalar n2 = this->squaredNorm();
394 template <
typename Scalar>
397 return Quaternion(this->w(),-this->x(),-this->y(),-this->z());
403 template <
typename Scalar>
406 double d = ei_abs(this->eigen2_dot(other));
409 return Scalar(2) * std::acos(d);
415 template <
typename Scalar>
418 static const Scalar one =
Scalar(1) - machine_epsilon<Scalar>();
419 Scalar d = this->eigen2_dot(other);
420 Scalar absD = ei_abs(d);
433 Scalar theta = std::acos(absD);
434 Scalar sinTheta = ei_sin(theta);
436 scale0 = ei_sin( (
Scalar(1) - t ) * theta) / sinTheta;
437 scale1 = ei_sin( ( t * theta) ) / sinTheta;
446 template<
typename Other>
454 Scalar t = mat.trace();
457 t = ei_sqrt(t +
Scalar(1.0));
460 q.
x() = (mat.coeff(2,1) - mat.coeff(1,2)) * t;
461 q.
y() = (mat.coeff(0,2) - mat.coeff(2,0)) * t;
462 q.
z() = (mat.coeff(1,0) - mat.coeff(0,1)) * t;
467 if (mat.coeff(1,1) > mat.coeff(0,0))
469 if (mat.coeff(2,2) > mat.coeff(i,i))
474 t = ei_sqrt(mat.coeff(i,i)-mat.coeff(j,j)-mat.coeff(k,k) +
Scalar(1.0));
477 q.
w() = (mat.coeff(k,j)-mat.coeff(j,k))*t;
478 q.
coeffs().coeffRef(j) = (mat.coeff(j,i)+mat.coeff(i,j))*t;
479 q.
coeffs().coeffRef(k) = (mat.coeff(k,i)+mat.coeff(i,k))*t;
485 template<
typename Other>
Matrix< Scalar, 4, 1 > Coefficients
the type of the Coefficients 4-vector
Definition: Quaternion.h:60
Definition: XprHelper.h:393
Quaternion & setIdentity()
Definition: Quaternion.h:137
Quaternion(const Quaternion &other)
Copy constructor.
Definition: Quaternion.h:112
Scalar & y()
Definition: Quaternion.h:80
Scalar squaredNorm() const
Definition: Quaternion.h:142
static Quaternion Identity()
Definition: Quaternion.h:133
Quaternion(Scalar w, Scalar x, Scalar y, Scalar z)
Constructs and initializes the quaternion from its four coefficients w, x, y and z...
Definition: Quaternion.h:108
const Coefficients & coeffs() const
Definition: Quaternion.h:93
Matrix< Scalar, 3, 1 > Vector3
the type of a 3D vector
Definition: Quaternion.h:62
Definition: Quaternion.h:17
Matrix3 toRotationMatrix(void) const
Convert the quaternion to a 3x3 rotation matrix.
Definition: Quaternion.h:296
Scalar norm() const
Definition: Quaternion.h:147
Derived & setZero()
Sets all coefficients in this expression to zero.
Definition: CwiseNullaryOp.h:499
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
Scalar y() const
Definition: Quaternion.h:71
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
Block< Coefficients, 3, 1 > vec()
Definition: Quaternion.h:90
const Block< const Coefficients, 3, 1 > vec() const
Definition: Quaternion.h:87
Coefficients & coeffs()
Definition: Quaternion.h:96
Quaternion()
Default constructor leaving the quaternion uninitialized.
Definition: Quaternion.h:99
Scalar x() const
Definition: Quaternion.h:69
AngleAxis< Scalar > AngleAxisType
the equivalent angle-axis type
Definition: Quaternion.h:66
Quaternion(const MatrixBase< Derived > &other)
Constructs and initializes a quaternion from either:
Definition: Quaternion.h:123
Quaternion slerp(Scalar t, const Quaternion &other) const
Definition: Quaternion.h:416
bool isApprox(const Quaternion &other, typename NumTraits< Scalar >::Real prec=precision< Scalar >()) const
Definition: Quaternion.h:199
Common base class for compact rotation representations.
Definition: ForwardDeclarations.h:231
void normalize()
Normalizes the quaternion *this.
Definition: Quaternion.h:151
internal::cast_return_type< Quaternion, Quaternion< NewScalarType > >::type cast() const
Definition: Quaternion.h:187
Quaternion conjugate(void) const
Definition: Quaternion.h:395
Scalar & w()
Definition: Quaternion.h:84
_Scalar Scalar
the scalar type of the coefficients
Definition: Quaternion.h:57
Scalar w() const
Definition: Quaternion.h:75
Scalar eigen2_dot(const Quaternion &other) const
Definition: Quaternion.h:161
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:103
Definition: Quaternion.h:47
Quaternion & operator*=(const Quaternion &q)
Definition: Quaternion.h:235
Quaternion(const AngleAxisType &aa)
Constructs and initializes a quaternion from the angle-axis aa.
Definition: Quaternion.h:115
Quaternion(const Quaternion< OtherScalarType > &other)
Copy constructor with scalar type conversion.
Definition: Quaternion.h:192
Scalar z() const
Definition: Quaternion.h:73
Quaternion operator*(const Quaternion &q) const
Definition: Quaternion.h:228
Quaternion< double > Quaterniond
double precision quaternion type
Definition: Quaternion.h:211
Scalar & x()
Definition: Quaternion.h:78
Scalar angularDistance(const Quaternion &other) const
Definition: Quaternion.h:404
Quaternion< float > Quaternionf
single precision quaternion type
Definition: Quaternion.h:208
Quaternion normalized() const
Definition: Quaternion.h:154
Quaternion inverse(void) const
Definition: Quaternion.h:375
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Definition: ForwardDeclarations.h:235
Scalar & z()
Definition: Quaternion.h:82
Matrix< Scalar, 3, 3 > Matrix3
the equivalent rotation matrix type
Definition: Quaternion.h:64
double Scalar
Common scalar type.
Definition: FlexibleKalmanBase.h:48