Lines Matching refs:Quaternion
21 * \class Quaternion
23 * \brief The quaternion class used to represent 3D orientations and rotations
27 * This class represents a quaternion \f$ w+xi+yj+zk \f$ that is a convenient representation of
41 template<typename _Scalar> struct ei_traits<Quaternion<_Scalar> >
47 class Quaternion : public RotationBase<Quaternion<_Scalar>,3>
49 typedef RotationBase<Quaternion<_Scalar>,3> Base;
98 /** Default constructor leaving the quaternion uninitialized. */
99 inline Quaternion() {}
101 /** Constructs and initializes the quaternion \f$ w+xi+yj+zk \f$ from
108 inline Quaternion(Scalar w, Scalar x, Scalar y, Scalar z)
112 inline Quaternion(const Quaternion& other) { m_coeffs = other.m_coeffs; }
114 /** Constructs and initializes a quaternion from the angle-axis \a aa */
115 explicit inline Quaternion(const AngleAxisType& aa) { *this = aa; }
117 /** Constructs and initializes a quaternion from either:
119 * - a 4D vector expression representing quaternion coefficients.
123 explicit inline Quaternion(const MatrixBase<Derived>& other) { *this = other; }
125 Quaternion& operator=(const Quaternion& other);
126 Quaternion& operator=(const AngleAxisType& aa);
128 Quaternion& operator=(const MatrixBase<Derived>& m);
130 /** \returns a quaternion representing an identity rotation
133 static inline Quaternion Identity() { return Quaternion(1, 0, 0, 0); }
135 /** \sa Quaternion::Identity(), MatrixBase::setIdentity()
137 inline Quaternion& setIdentity() { m_coeffs << 0, 0, 0, 1; return *this; }
139 /** \returns the squared norm of the quaternion's coefficients
140 * \sa Quaternion::norm(), MatrixBase::squaredNorm()
144 /** \returns the norm of the quaternion's coefficients
145 * \sa Quaternion::squaredNorm(), MatrixBase::norm()
149 /** Normalizes the quaternion \c *this
154 inline Quaternion normalized() const { return Quaternion(m_coeffs.normalized()); }
161 inline Scalar eigen2_dot(const Quaternion& other) const { return m_coeffs.eigen2_dot(other.m_coeffs); }
163 inline Scalar angularDistance(const Quaternion& other) const;
168 Quaternion& setFromTwoVectors(const MatrixBase<Derived1>& a, const MatrixBase<Derived2>& b);
170 inline Quaternion operator* (const Quaternion& q) const;
171 inline Quaternion& operator*= (const Quaternion& q);
173 Quaternion inverse(void) const;
174 Quaternion conjugate(void) const;
176 Quaternion slerp(Scalar t, const Quaternion& other) const;
187 inline typename internal::cast_return_type<Quaternion,Quaternion<NewScalarType> >::type cast() const
188 { return typename internal::cast_return_type<Quaternion,Quaternion<NewScalarType> >::type(*this); }
192 inline explicit Quaternion(const Quaternion<OtherScalarType>& other)
199 bool isApprox(const Quaternion& other, typename NumTraits<Scalar>::Real prec = precision<Scalar>()) const
207 * single precision quaternion type */
208 typedef Quaternion<float> Quaternionf;
210 * double precision quaternion type */
211 typedef Quaternion<double> Quaterniond;
213 // Generic Quaternion * Quaternion product
214 template<typename Scalar> inline Quaternion<Scalar>
215 ei_quaternion_product(const Quaternion<Scalar>& a, const Quaternion<Scalar>& b)
217 return Quaternion<Scalar>
226 /** \returns the concatenation of two rotations as a quaternion-quaternion product */
228 inline Quaternion<Scalar> Quaternion<Scalar>::operator* (const Quaternion& other) const
233 /** \sa operator*(Quaternion) */
235 inline Quaternion<Scalar>& Quaternion<Scalar>::operator*= (const Quaternion& other)
240 /** Rotation of a vector by a quaternion.
241 * \remarks If the quaternion is used to rotate several points (>1)
244 * - Quaternion: 30n
249 inline typename Quaternion<Scalar>::Vector3
250 Quaternion<Scalar>::operator* (const MatrixBase<Derived>& v) const
263 inline Quaternion<Scalar>& Quaternion<Scalar>::operator=(const Quaternion& other)
272 inline Quaternion<Scalar>& Quaternion<Scalar>::operator=(const AngleAxisType& aa)
281 * - if \a xpr is a 4x1 vector, then \a xpr is assumed to be a quaternion
283 * and \a xpr is converted to a quaternion
287 inline Quaternion<Scalar>& Quaternion<Scalar>::operator=(const MatrixBase<Derived>& xpr)
293 /** Convert the quaternion to a 3x3 rotation matrix */
295 inline typename Quaternion<Scalar>::Matrix3
296 Quaternion<Scalar>::toRotationMatrix(void) const
330 /** Sets *this to be a quaternion representing a rotation sending the vector \a a to the vector \a b.
338 inline Quaternion<Scalar>& Quaternion<Scalar>::setFromTwoVectors(const MatrixBase<Derived1>& a, const MatrixBase<Derived2>& b)
370 * and/or the quaternion is normalized, then it is enough to use the conjugate.
372 * \sa Quaternion::conjugate()
375 inline Quaternion<Scalar> Quaternion<Scalar>::inverse() const
380 return Quaternion(conjugate().coeffs() / n2);
384 return Quaternion(Coefficients::Zero());
389 * if the quaternion is normalized.
390 * The conjugate of a quaternion represents the opposite rotation.
392 * \sa Quaternion::inverse()
395 inline Quaternion<Scalar> Quaternion<Scalar>::conjugate() const
397 return Quaternion(this->w(),-this->x(),-this->y(),-this->z());
404 inline Scalar Quaternion<Scalar>::angularDistance(const Quaternion& other) const
416 Quaternion<Scalar> Quaternion<Scalar>::slerp(Scalar t, const Quaternion& other) const
442 return Quaternion<Scalar>(scale0 * coeffs() + scale1 * other.coeffs());
450 static inline void run(Quaternion<Scalar>& q, const Other& mat)
452 // This algorithm comes from "Quaternion Calculus and Fast Animation",
484 // set from a vector of coefficients assumed to be a quaternion
489 static inline void run(Quaternion<Scalar>& q, const Other& vec)