OpenCV  4.10.0
Open Source Computer Vision
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Friends | List of all members
cv::Quat< _Tp > Class Template Reference

#include <opencv2/core/quaternion.hpp>

Collaboration diagram for cv::Quat< _Tp >:

Public Member Functions

 Quat ()
 
 Quat (_Tp w, _Tp x, _Tp y, _Tp z)
 from four numbers.
 
 Quat (const Vec< _Tp, 4 > &coeff)
 From Vec4d or Vec4f.
 
Quat< _Tpacos () const
 return arccos value of this quaternion, arccos could be calculated as:
 
Quat< _Tpacosh () const
 return arccosh value of this quaternion, arccosh could be calculated as:
 
Quat< _Tpasin () const
 return arcsin value of this quaternion, arcsin could be calculated as:
 
Quat< _Tpasinh () const
 return arcsinh value of this quaternion, arcsinh could be calculated as:
 
void assertNormal (_Tp eps=CV_QUAT_EPS) const
 to throw an error if this quaternion is not a unit quaternion.
 
_Tp at (size_t index) const
 a way to get element.
 
Quat< _Tpatan () const
 return arctan value of this quaternion, arctan could be calculated as:
 
Quat< _Tpatanh () const
 return arctanh value of this quaternion, arctanh could be calculated as:
 
Quat< _Tpconjugate () const
 return the conjugate of this quaternion.
 
Quat< _Tpcos () const
 return cos value of this quaternion, cos could be calculated as:
 
Quat< _Tpcosh () const
 return cosh value of this quaternion, cosh could be calculated as:
 
Quat< _TpcrossProduct (const Quat< _Tp > &q) const
 return the crossProduct between \(p = (a, b, c, d) = (a, \boldsymbol{u})\) and \(q = (w, x, y, z) = (w, \boldsymbol{v})\).
 
_Tp dot (Quat< _Tp > q) const
 return the dot between quaternion \(q\) and this quaternion.
 
Quat< _Tpexp () const
 return the value of exponential value.
 
_Tp getAngle (QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const
 get the angle of quaternion, it returns the rotation angle.
 
Vec< _Tp, 3 > getAxis (QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const
 get the axis of quaternion, it returns a vector of length 3.
 
Quat< _Tpinv (QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const
 return \(q^{-1}\) which is an inverse of \(q\) satisfying \(q * q^{-1} = 1\).
 
bool isNormal (_Tp eps=CV_QUAT_EPS) const
 return true if this quaternion is a unit quaternion.
 
Quat< _Tplog (QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const
 return the value of logarithm function.
 
_Tp norm () const
 return the norm of quaternion.
 
Quat< _Tpnormalize () const
 return a normalized \(p\).
 
Quat< _Tpoperator* (const Quat< _Tp > &) const
 Multiplication operator of two quaternions q and p. Multiplies values on either side of the operator.
 
Quat< _Tp > & operator*= (const _Tp s)
 Multiplication assignment operator of a quaternions and a scalar. It multiplies right operand with the left operand and assign the result to left operand.
 
Quat< _Tp > & operator*= (const Quat< _Tp > &)
 Multiplication assignment operator of two quaternions q and p. It multiplies right operand with the left operand and assign the result to left operand.
 
Quat< _Tpoperator+ (const Quat< _Tp > &) const
 Addition operator of two quaternions p and q. It returns a new quaternion that each value is the sum of \(p_i\) and \(q_i\).
 
Quat< _Tp > & operator+= (const Quat< _Tp > &)
 Addition assignment operator of two quaternions p and q. It adds right operand to the left operand and assign the result to left operand.
 
Quat< _Tpoperator- () const
 Return opposite quaternion \(-p\) which satisfies \(p + (-p) = 0.\).
 
Quat< _Tpoperator- (const Quat< _Tp > &) const
 Subtraction operator of two quaternions p and q. It returns a new quaternion that each value is the sum of \(p_i\) and \(-q_i\).
 
Quat< _Tp > & operator-= (const Quat< _Tp > &)
 Subtraction assignment operator of two quaternions p and q. It subtracts right operand from the left operand and assign the result to left operand.
 
Quat< _Tpoperator/ (const _Tp s) const
 Division operator of a quaternions and a scalar. It divides left operand with the right operand and assign the result to left operand.
 
Quat< _Tpoperator/ (const Quat< _Tp > &) const
 Division operator of two quaternions p and q. Divides left hand operand by right hand operand.
 
Quat< _Tp > & operator/= (const _Tp s)
 Division assignment operator of a quaternions and a scalar. It divides left operand with the right operand and assign the result to left operand.
 
Quat< _Tp > & operator/= (const Quat< _Tp > &)
 Division assignment operator of two quaternions p and q; It divides left operand with the right operand and assign the result to left operand.
 
bool operator== (const Quat< _Tp > &) const
 return true if two quaternions p and q are nearly equal, i.e. when the absolute value of each \(p_i\) and \(q_i\) is less than CV_QUAT_EPS.
 
_Tpoperator[] (std::size_t n)
 
const _Tpoperator[] (std::size_t n) const
 
Quat< _Tppower (const _Tp x, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const
 return the value of power function with index \(x\).
 
Quat< _Tppower (const Quat< _Tp > &q, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const
 return the value of power function with quaternion \(q\).
 
Quat< _Tpsin () const
 return sin value of this quaternion, sin could be calculated as:
 
Quat< _Tpsinh () const
 return sinh value of this quaternion, sinh could be calculated as: \(\sinh(p) = \sin(w)\cos(||\boldsymbol{v}||) + \cosh(w)\frac{v}{||\boldsymbol{v}||}\sin||\boldsymbol{v}||\) where \(\boldsymbol{v} = [x, y, z].\)
 
Quat< _Tpsqrt (QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const
 return \(\sqrt{q}\).
 
Quat< _Tptan () const
 return tan value of this quaternion, tan could be calculated as:
 
Quat< _Tptanh () const
 return tanh value of this quaternion, tanh could be calculated as:
 
Vec< _Tp, 3 > toEulerAngles (QuatEnum::EulerAnglesType eulerAnglesType)
 Transform a quaternion q to Euler angles.
 
Matx< _Tp, 3, 3 > toRotMat3x3 (QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const
 transform a quaternion to a 3x3 rotation matrix.
 
Matx< _Tp, 4, 4 > toRotMat4x4 (QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const
 transform a quaternion to a 4x4 rotation matrix.
 
Vec< _Tp, 3 > toRotVec (QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const
 transform this quaternion to a Rotation vector.
 
Vec< _Tp, 4 > toVec () const
 transform the this quaternion to a Vec<T, 4>.
 

Static Public Member Functions

static Quat< _TpcreateFromAngleAxis (const _Tp angle, const Vec< _Tp, 3 > &axis)
 from an angle, axis. Axis will be normalized in this function. And it generates
 
static Quat< _TpcreateFromEulerAngles (const Vec< _Tp, 3 > &angles, QuatEnum::EulerAnglesType eulerAnglesType)
 from Euler angles
 
static Quat< _TpcreateFromRotMat (InputArray R)
 from a 3x3 rotation matrix.
 
static Quat< _TpcreateFromRvec (InputArray rvec)
 from a rotation vector \(r\) has the form \(\theta \cdot \boldsymbol{u}\), where \(\theta\) represents rotation angle and \(\boldsymbol{u}\) represents normalized rotation axis.
 
static Quat< _TpcreateFromXRot (const _Tp theta)
 get a quaternion from a rotation about the X-axis by \(\theta\) .
 
static Quat< _TpcreateFromYRot (const _Tp theta)
 get a quaternion from a rotation about the Y-axis by \(\theta\) .
 
static Quat< _TpcreateFromZRot (const _Tp theta)
 get a quaternion from a rotation about the Z-axis by \(\theta\).
 
static Quat< _TpinterPoint (const Quat< _Tp > &q0, const Quat< _Tp > &q1, const Quat< _Tp > &q2, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT)
 This is the part calculation of squad. To calculate the intermedia quaternion \(s_i\) between each three quaternion.
 
static Quat< _Tplerp (const Quat< _Tp > &q0, const Quat &q1, const _Tp t)
 To calculate the interpolation from \(q_0\) to \(q_1\) by Linear Interpolation(Nlerp) For two quaternions, this interpolation curve can be displayed as:
 
static Quat< _Tpnlerp (const Quat< _Tp > &q0, const Quat &q1, const _Tp t, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT)
 To calculate the interpolation from \(q_0\) to \(q_1\) by Normalized Linear Interpolation(Nlerp). it returns a normalized quaternion of Linear Interpolation(Lerp).
 
static Quat< _Tpslerp (const Quat< _Tp > &q0, const Quat &q1, const _Tp t, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT, bool directChange=true)
 To calculate the interpolation between \(q_0\) and \(q_1\) by Spherical Linear Interpolation(Slerp), which can be defined as:
 
static Quat< _Tpspline (const Quat< _Tp > &q0, const Quat< _Tp > &q1, const Quat< _Tp > &q2, const Quat< _Tp > &q3, const _Tp t, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT)
 to calculate a quaternion which is the result of a \(C^1\) continuous spline curve constructed by squad at the ratio t. Here, the interpolation values are between \(q_1\) and \(q_2\). \(q_0\) and \(q_2\) are used to ensure the \(C^1\) continuity. if t = 0, it returns \(q_1\), if t = 1, it returns \(q_2\).
 
static Quat< _Tpsquad (const Quat< _Tp > &q0, const Quat< _Tp > &s0, const Quat< _Tp > &s1, const Quat< _Tp > &q1, const _Tp t, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT, bool directChange=true)
 To calculate the interpolation between \(q_0\), \(q_1\), \(q_2\), \(q_3\) by Spherical and quadrangle(Squad). This could be defined as:
 

Public Attributes

_Tp w
 
_Tp x
 
_Tp y
 
_Tp z
 

Static Public Attributes

static constexpr _Tp CV_QUAT_CONVERT_THRESHOLD = (_Tp)1.e-6
 
static constexpr _Tp CV_QUAT_EPS = (_Tp)1.e-6
 

Friends

template<typename T >
Quat< T > acos (const Quat< T > &q)
 return arccos value of quaternion q, arccos could be calculated as:
 
template<typename T >
Quat< T > acosh (const Quat< T > &q)
 return arccosh value of quaternion q, arccosh could be calculated as:
 
template<typename T >
Quat< T > asin (const Quat< T > &q)
 return arcsin value of quaternion q, arcsin could be calculated as:
 
template<typename T >
Quat< T > asinh (const Quat< T > &q)
 return arcsinh value of quaternion q, arcsinh could be calculated as:
 
template<typename T >
Quat< T > atan (const Quat< T > &q)
 return arctan value of quaternion q, arctan could be calculated as:
 
template<typename T >
Quat< T > atanh (const Quat< T > &q)
 return arctanh value of quaternion q, arctanh could be calculated as:
 
template<typename T >
Quat< T > cos (const Quat< T > &q)
 return sin value of quaternion q, cos could be calculated as:
 
template<typename T >
Quat< T > cosh (const Quat< T > &q)
 return cosh value of quaternion q, cosh could be calculated as:
 
template<typename T >
Quat< T > crossProduct (const Quat< T > &p, const Quat< T > &q)
 return the crossProduct between \(p = (a, b, c, d) = (a, \boldsymbol{u})\) and \(q = (w, x, y, z) = (w, \boldsymbol{v})\).
 
template<typename T >
Quat< T > cv::operator* (const Quat< T > &, const T s)
 Multiplication operator of a quaternion and a scalar. It multiplies right operand with the left operand and assign the result to left operand.
 
template<typename T >
Quat< T > cv::operator* (const T s, const Quat< T > &)
 Multiplication operator of a scalar and a quaternions. It multiplies right operand with the left operand and assign the result to left operand.
 
template<typename T >
Quat< T > cv::operator+ (const Quat< T > &, const T s)
 Addition operator of a quaternions and a scalar. Adds right hand operand from left hand operand.
 
template<typename T >
Quat< T > cv::operator+ (const T s, const Quat< T > &)
 Addition operator of a quaternions and a scalar. Adds right hand operand from left hand operand.
 
template<typename T >
Quat< T > cv::operator- (const Quat< T > &, const T s)
 Subtraction operator of a quaternions and a scalar. Subtracts right hand operand from left hand operand.
 
template<typename T >
Quat< T > cv::operator- (const T s, const Quat< T > &)
 Subtraction operator of a scalar and a quaternions. Subtracts right hand operand from left hand operand.
 
template<typename S >
std::ostream & cv::operator<< (std::ostream &, const Quat< S > &)
 
template<typename T >
Quat< T > exp (const Quat< T > &q)
 return the value of exponential value.
 
template<typename T >
Quat< T > inv (const Quat< T > &q, QuatAssumeType assumeUnit)
 return \(q^{-1}\) which is an inverse of \(q\) which satisfies \(q * q^{-1} = 1\).
 
template<typename T >
Quat< T > log (const Quat< T > &q, QuatAssumeType assumeUnit)
 return the value of logarithm function.
 
template<typename T >
Quat< T > power (const Quat< T > &p, const Quat< T > &q, QuatAssumeType assumeUnit)
 return the value of power function with quaternion \(q\).
 
template<typename T >
Quat< T > power (const Quat< T > &q, const T x, QuatAssumeType assumeUnit)
 return the value of power function with index \(x\).
 
template<typename T >
Quat< T > sin (const Quat< T > &q)
 return tanh value of quaternion q, sin could be calculated as:
 
template<typename T >
Quat< T > sinh (const Quat< T > &q)
 return sinh value of quaternion q, sinh could be calculated as:
 
template<typename T >
Quat< T > sqrt (const Quat< T > &q, QuatAssumeType assumeUnit)
 return \(\sqrt{q}\).
 
template<typename T >
Quat< T > tan (const Quat< T > &q)
 return tan value of quaternion q, tan could be calculated as:
 
template<typename T >
Quat< T > tanh (const Quat< T > &q)
 return tanh value of quaternion q, tanh could be calculated as:
 

Detailed Description

template<typename _Tp>
class cv::Quat< _Tp >

Quaternion is a number system that extends the complex numbers. It can be expressed as a rotation in three-dimensional space. A quaternion is generally represented in the form:

\[q = w + x\boldsymbol{i} + y\boldsymbol{j} + z\boldsymbol{k}\]

\[q = [w, x, y, z]\]

\[q = [w, \boldsymbol{v}] \]

\[q = ||q||[\cos\psi, u_x\sin\psi,u_y\sin\psi, u_z\sin\psi].\]

\[q = ||q||[\cos\psi, \boldsymbol{u}\sin\psi]\]

where \(\psi = \frac{\theta}{2}\), \(\theta\) represents rotation angle, \(\boldsymbol{u} = [u_x, u_y, u_z]\) represents normalized rotation axis, and \(||q||\) represents the norm of \(q\).

A unit quaternion is usually represents rotation, which has the form:

\[q = [\cos\psi, u_x\sin\psi,u_y\sin\psi, u_z\sin\psi].\]

To create a quaternion representing the rotation around the axis \(\boldsymbol{u}\) with angle \(\theta\), you can use

using namespace cv;
double angle = CV_PI;
Vec3d axis = {0, 0, 1};
Definition quaternion.hpp:211
static Quat< _Tp > createFromAngleAxis(const _Tp angle, const Vec< _Tp, 3 > &axis)
from an angle, axis. Axis will be normalized in this function. And it generates
#define CV_PI
Definition cvdef.h:380
"black box" representation of the file storage associated with a file on disk.
Definition core.hpp:102

You can simply use four same type number to create a quaternion

Quatd q(1, 2, 3, 4);

Or use a Vec4d or Vec4f vector.

Vec4d vec{1, 2, 3, 4};
Quatd q(vec);
Vec4f vec{1, 2, 3, 4};
Quatf q(vec);

If you already have a 3x3 rotation matrix R, then you can use

static Quat< _Tp > createFromRotMat(InputArray R)
from a 3x3 rotation matrix.

If you already have a rotation vector rvec which has the form of angle * axis, then you can use

static Quat< _Tp > createFromRvec(InputArray rvec)
from a rotation vector has the form , where represents rotation angle and represents normalized ro...

To extract the rotation matrix from quaternion, see toRotMat3x3()

To extract the Vec4d or Vec4f, see toVec()

To extract the rotation vector, see toRotVec()

If there are two quaternions \(q_0, q_1\) are needed to interpolate, you can use nlerp(), slerp() or spline()

Quatd::nlerp(q0, q1, t)
Quatd::slerp(q0, q1, t)
Quatd::spline(q0, q0, q1, q1, t)
static Quat< _Tp > spline(const Quat< _Tp > &q0, const Quat< _Tp > &q1, const Quat< _Tp > &q2, const Quat< _Tp > &q3, const _Tp t, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT)
to calculate a quaternion which is the result of a continuous spline curve constructed by squad at t...
static Quat< _Tp > slerp(const Quat< _Tp > &q0, const Quat &q1, const _Tp t, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT, bool directChange=true)
To calculate the interpolation between and by Spherical Linear Interpolation(Slerp),...
static Quat< _Tp > nlerp(const Quat< _Tp > &q0, const Quat &q1, const _Tp t, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT)
To calculate the interpolation from to by Normalized Linear Interpolation(Nlerp)....

spline can smoothly connect rotations of multiple quaternions

Three ways to get an element in Quaternion

Quatf q(1,2,3,4);
std::cout << q.w << std::endl; // w=1, x=2, y=3, z=4
std::cout << q[0] << std::endl; // q[0]=1, q[1]=2, q[2]=3, q[3]=4
std::cout << q.at(0) << std::endl;
_Tp at(size_t index) const
a way to get element.
_Tp w
Definition quaternion.hpp:1618

Constructor & Destructor Documentation

◆ Quat() [1/3]

template<typename _Tp >
cv::Quat< _Tp >::Quat ( )

◆ Quat() [2/3]

template<typename _Tp >
cv::Quat< _Tp >::Quat ( const Vec< _Tp, 4 > &  coeff)
explicit

From Vec4d or Vec4f.

◆ Quat() [3/3]

template<typename _Tp >
cv::Quat< _Tp >::Quat ( _Tp  w,
_Tp  x,
_Tp  y,
_Tp  z 
)

from four numbers.

Member Function Documentation

◆ acos()

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::acos ( ) const

return arccos value of this quaternion, arccos could be calculated as:

\[\arccos(q) = -\frac{\boldsymbol{v}}{||\boldsymbol{v}||}arccosh(q)\]

where \(\boldsymbol{v} = [x, y, z].\)

For example

Quatd q(1,2,3,4);
q.acos();

◆ acosh()

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::acosh ( ) const

return arccosh value of this quaternion, arccosh could be calculated as:

\[arcosh(q) = \ln(q + \sqrt{q^2 - 1})\]

.

For example

Quatd q(1,2,3,4);
q.acosh();

◆ asin()

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::asin ( ) const

return arcsin value of this quaternion, arcsin could be calculated as:

\[\arcsin(q) = -\frac{\boldsymbol{v}}{||\boldsymbol{v}||}arcsinh(q\frac{\boldsymbol{v}}{||\boldsymbol{v}||})\]

where \(\boldsymbol{v} = [x, y, z].\)

For example

Quatd q(1,2,3,4);
q.asin();

◆ asinh()

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::asinh ( ) const

return arcsinh value of this quaternion, arcsinh could be calculated as:

\[arcsinh(q) = \ln(q + \sqrt{q^2 + 1})\]

.

For example

Quatd q(1,2,3,4);
q.asinh();

◆ assertNormal()

template<typename _Tp >
void cv::Quat< _Tp >::assertNormal ( _Tp  eps = CV_QUAT_EPS) const

to throw an error if this quaternion is not a unit quaternion.

Parameters
epstolerance scope of normalization.
See also
isNormal

◆ at()

template<typename _Tp >
_Tp cv::Quat< _Tp >::at ( size_t  index) const

a way to get element.

Parameters
indexover a range [0, 3].

A quaternion q

q.at(0) is equivalent to q.w,

q.at(1) is equivalent to q.x,

q.at(2) is equivalent to q.y,

q.at(3) is equivalent to q.z.

◆ atan()

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::atan ( ) const

return arctan value of this quaternion, arctan could be calculated as:

\[\arctan(q) = -\frac{\boldsymbol{v}}{||\boldsymbol{v}||}arctanh(q\frac{\boldsymbol{v}}{||\boldsymbol{v}||})\]

where \(\boldsymbol{v} = [x, y, z].\)

For example

Quatd q(1,2,3,4);
q.atan();

◆ atanh()

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::atanh ( ) const

return arctanh value of this quaternion, arctanh could be calculated as:

\[arcsinh(q) = \frac{\ln(q + 1) - \ln(1 - q)}{2}\]

.

For example

Quatd q(1,2,3,4);
q.atanh();

◆ conjugate()

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::conjugate ( ) const

return the conjugate of this quaternion.

\[q.conjugate() = (w, -x, -y, -z).\]

◆ cos()

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::cos ( ) const

return cos value of this quaternion, cos could be calculated as:

\[\cos(p) = \cos(w) * \cosh(||\boldsymbol{v}||) - \sin(w)\frac{\boldsymbol{v}}{||\boldsymbol{v}||}\sinh(||\boldsymbol{v}||)\]

where \(\boldsymbol{v} = [x, y, z].\)

For example

Quatd q(1,2,3,4);
q.cos();

◆ cosh()

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::cosh ( ) const

return cosh value of this quaternion, cosh could be calculated as:

\[\cosh(p) = \cosh(w) * \cos(||\boldsymbol{v}||) + \sinh(w)\frac{\boldsymbol{v}}{||\boldsymbol{v}||}sin(||\boldsymbol{v}||)\]

where \(\boldsymbol{v} = [x, y, z].\)

For example

Quatd q(1,2,3,4);
q.cosh();

◆ createFromAngleAxis()

template<typename _Tp >
static Quat< _Tp > cv::Quat< _Tp >::createFromAngleAxis ( const _Tp  angle,
const Vec< _Tp, 3 > &  axis 
)
static

from an angle, axis. Axis will be normalized in this function. And it generates

\[q = [\cos\psi, u_x\sin\psi,u_y\sin\psi, u_z\sin\psi].\]

where \(\psi = \frac{\theta}{2}\), \(\theta\) is the rotation angle.

◆ createFromEulerAngles()

template<typename _Tp >
static Quat< _Tp > cv::Quat< _Tp >::createFromEulerAngles ( const Vec< _Tp, 3 > &  angles,
QuatEnum::EulerAnglesType  eulerAnglesType 
)
static

from Euler angles

A quaternion can be generated from Euler angles by combining the quaternion representations of the Euler rotations.

For example, if we use intrinsic rotations in the order of X-Y-Z, \(\theta_1 \) is rotation around the X-axis, \(\theta_2 \) is rotation around the Y-axis, \(\theta_3 \) is rotation around the Z-axis. The final quaternion q can be calculated by

\[ {q} = q_{X, \theta_1} q_{Y, \theta_2} q_{Z, \theta_3}\]

where \( q_{X, \theta_1} \) is created from createFromXRot, \( q_{Y, \theta_2} \) is created from createFromYRot, \( q_{Z, \theta_3} \) is created from createFromZRot.

Parameters
anglesthe Euler angles in a vector of length 3
eulerAnglesTypethe convertion Euler angles type

◆ createFromRotMat()

template<typename _Tp >
static Quat< _Tp > cv::Quat< _Tp >::createFromRotMat ( InputArray  R)
static

from a 3x3 rotation matrix.

◆ createFromRvec()

template<typename _Tp >
static Quat< _Tp > cv::Quat< _Tp >::createFromRvec ( InputArray  rvec)
static

from a rotation vector \(r\) has the form \(\theta \cdot \boldsymbol{u}\), where \(\theta\) represents rotation angle and \(\boldsymbol{u}\) represents normalized rotation axis.

Angle and axis could be easily derived as:

\[ \begin{equation} \begin{split} \psi &= ||r||\\ \boldsymbol{u} &= \frac{r}{\theta} \end{split} \end{equation} \]

Then a quaternion can be calculated by

\[q = [\cos\psi, \boldsymbol{u}\sin\psi]\]

where \(\psi = \theta / 2 \)

◆ createFromXRot()

template<typename _Tp >
static Quat< _Tp > cv::Quat< _Tp >::createFromXRot ( const _Tp  theta)
static

get a quaternion from a rotation about the X-axis by \(\theta\) .

\[q = \cos(\theta/2)+sin(\theta/2) i +0 j +0 k \]

◆ createFromYRot()

template<typename _Tp >
static Quat< _Tp > cv::Quat< _Tp >::createFromYRot ( const _Tp  theta)
static

get a quaternion from a rotation about the Y-axis by \(\theta\) .

\[q = \cos(\theta/2)+0 i+ sin(\theta/2) j +0k \]

◆ createFromZRot()

template<typename _Tp >
static Quat< _Tp > cv::Quat< _Tp >::createFromZRot ( const _Tp  theta)
static

get a quaternion from a rotation about the Z-axis by \(\theta\).

\[q = \cos(\theta/2)+0 i +0 j +sin(\theta/2) k \]

◆ crossProduct()

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::crossProduct ( const Quat< _Tp > &  q) const

return the crossProduct between \(p = (a, b, c, d) = (a, \boldsymbol{u})\) and \(q = (w, x, y, z) = (w, \boldsymbol{v})\).

\[p \times q = \frac{pq- qp}{2}.\]

\[p \times q = \boldsymbol{u} \times \boldsymbol{v}.\]

\[p \times q = (cz-dy)i + (dx-bz)j + (by-xc)k. \]

For example

Quatd q{1,2,3,4};
Quatd p{5,6,7,8};
friend Quat< T > crossProduct(const Quat< T > &p, const Quat< T > &q)
return the crossProduct between and .

◆ dot()

template<typename _Tp >
_Tp cv::Quat< _Tp >::dot ( Quat< _Tp q) const

return the dot between quaternion \(q\) and this quaternion.

dot(p, q) is a good metric of how close the quaternions are. Indeed, consider the unit quaternion difference \(p^{-1} * q\), its real part is dot(p, q). At the same time its real part is equal to \(\cos(\beta/2)\) where \(\beta\) is an angle of rotation between p and q, i.e., Therefore, the closer dot(p, q) to 1, the smaller rotation between them.

\[p \cdot q = p.w \cdot q.w + p.x \cdot q.x + p.y \cdot q.y + p.z \cdot q.z\]

Parameters
qthe other quaternion.

For example

Quatd q(1,2,3,4);
Quatd p(5,6,7,8);
p.dot(q);

◆ exp()

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::exp ( ) const

return the value of exponential value.

\[\exp(q) = e^w (\cos||\boldsymbol{v}||+ \frac{v}{||\boldsymbol{v}||}\sin||\boldsymbol{v}||)\]

where \(\boldsymbol{v} = [x, y, z].\)

For example

Quatd q{1,2,3,4};
cout << q.exp() << endl;
friend Quat< T > exp(const Quat< T > &q)
return the value of exponential value.

◆ getAngle()

template<typename _Tp >
_Tp cv::Quat< _Tp >::getAngle ( QuatAssumeType  assumeUnit = QUAT_ASSUME_NOT_UNIT) const

get the angle of quaternion, it returns the rotation angle.

Parameters
assumeUnitif QUAT_ASSUME_UNIT, this quaternion assume to be a unit quaternion and this function will save some computations.

\[\psi = 2 *arccos(\frac{w}{||q||})\]

For example

Quatd q(1,2,3,4);
q.getAngle();
q.normalize().getAngle(assumeUnit);//same as q.getAngle().
QuatAssumeType
Unit quaternion flag.
Definition quaternion.hpp:39
@ QUAT_ASSUME_UNIT
Definition quaternion.hpp:52
Note
It always return the value between \([0, 2\pi]\).

◆ getAxis()

template<typename _Tp >
Vec< _Tp, 3 > cv::Quat< _Tp >::getAxis ( QuatAssumeType  assumeUnit = QUAT_ASSUME_NOT_UNIT) const

get the axis of quaternion, it returns a vector of length 3.

Parameters
assumeUnitif QUAT_ASSUME_UNIT, this quaternion assume to be a unit quaternion and this function will save some computations.

the unit axis \(\boldsymbol{u}\) is defined by

\[\begin{equation} \begin{split} \boldsymbol{v} &= \boldsymbol{u} ||\boldsymbol{v}||\\ &= \boldsymbol{u}||q||sin(\frac{\theta}{2}) \end{split} \end{equation}\]

where \(v=[x, y ,z]\) and \(\theta\) represents rotation angle.

For example

Quatd q(1,2,3,4);
q.getAxis();
q.normalize().getAxis(assumeUnit);//same as q.getAxis()

◆ interPoint()

template<typename _Tp >
static Quat< _Tp > cv::Quat< _Tp >::interPoint ( const Quat< _Tp > &  q0,
const Quat< _Tp > &  q1,
const Quat< _Tp > &  q2,
QuatAssumeType  assumeUnit = QUAT_ASSUME_NOT_UNIT 
)
static

This is the part calculation of squad. To calculate the intermedia quaternion \(s_i\) between each three quaternion.

\[s_i = q_i\exp(-\frac{\log(q^*_iq_{i+1}) + \log(q^*_iq_{i-1})}{4}).\]

Parameters
q0the first quaternion.
q1the second quaternion.
q2the third quaternion.
assumeUnitif QUAT_ASSUME_UNIT, all input quaternions assume to be unit quaternion. Otherwise, all input quaternions will be normalized inside the function.
See also
squad

◆ inv()

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::inv ( QuatAssumeType  assumeUnit = QUAT_ASSUME_NOT_UNIT) const

return \(q^{-1}\) which is an inverse of \(q\) satisfying \(q * q^{-1} = 1\).

Parameters
assumeUnitif QUAT_ASSUME_UNIT, quaternion q assume to be a unit quaternion and this function will save some computations.

For example

Quatd q(1,2,3,4);
q.inv();
q = q.normalize();
q.inv(assumeUnit); //assumeUnit means p is a unit quaternion

◆ isNormal()

template<typename _Tp >
bool cv::Quat< _Tp >::isNormal ( _Tp  eps = CV_QUAT_EPS) const

return true if this quaternion is a unit quaternion.

Parameters
epstolerance scope of normalization. The eps could be defined as

\[eps = |1 - dotValue|\]

where

\[dotValue = (this.w^2 + this.x^2 + this,y^2 + this.z^2).\]

And this function will consider it is normalized when the dotValue over a range \([1-eps, 1+eps]\).

◆ lerp()

template<typename _Tp >
static Quat< _Tp > cv::Quat< _Tp >::lerp ( const Quat< _Tp > &  q0,
const Quat< _Tp > &  q1,
const _Tp  t 
)
static

To calculate the interpolation from \(q_0\) to \(q_1\) by Linear Interpolation(Nlerp) For two quaternions, this interpolation curve can be displayed as:

\[Lerp(q_0, q_1, t) = (1 - t)q_0 + tq_1.\]

Obviously, the lerp will interpolate along a straight line if we think of \(q_0\) and \(q_1\) as a vector in a two-dimensional space. When \(t = 0\), it returns \(q_0\) and when \(t= 1\), it returns \(q_1\). \(t\) should to be ranged in \([0, 1]\) normally.

Parameters
q0a quaternion used in linear interpolation.
q1a quaternion used in linear interpolation.
tpercent of vector \(\overrightarrow{q_0q_1}\) over a range [0, 1].
Note
it returns a non-unit quaternion.

◆ log()

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::log ( QuatAssumeType  assumeUnit = QUAT_ASSUME_NOT_UNIT) const

return the value of logarithm function.

\[\ln(q) = \ln||q|| + \frac{\boldsymbol{v}}{||\boldsymbol{v}||}\arccos\frac{w}{||q||}\]

. where \(\boldsymbol{v} = [x, y, z].\)

Parameters
assumeUnitif QUAT_ASSUME_UNIT, this quaternion assume to be a unit quaternion and this function will save some computations.

For example

Quatd q(1,2,3,4);
q.log();
Quatd q1(1,2,3,4);
q1.normalize().log(assumeUnit);

◆ nlerp()

template<typename _Tp >
static Quat< _Tp > cv::Quat< _Tp >::nlerp ( const Quat< _Tp > &  q0,
const Quat< _Tp > &  q1,
const _Tp  t,
QuatAssumeType  assumeUnit = QUAT_ASSUME_NOT_UNIT 
)
static

To calculate the interpolation from \(q_0\) to \(q_1\) by Normalized Linear Interpolation(Nlerp). it returns a normalized quaternion of Linear Interpolation(Lerp).

\[ Nlerp(q_0, q_1, t) = \frac{(1 - t)q_0 + tq_1}{||(1 - t)q_0 + tq_1||}.\]

The interpolation will always choose the shortest path but the constant speed is not guaranteed.

Parameters
q0a quaternion used in normalized linear interpolation.
q1a quaternion used in normalized linear interpolation.
tpercent of vector \(\overrightarrow{q_0q_1}\) over a range [0, 1].
assumeUnitif QUAT_ASSUME_UNIT, all input quaternions assume to be unit quaternion. Otherwise, all inputs quaternion will be normalized inside the function.
See also
lerp

◆ norm()

template<typename _Tp >
_Tp cv::Quat< _Tp >::norm ( ) const

return the norm of quaternion.

\[||q|| = \sqrt{w^2 + x^2 + y^2 + z^2}.\]

◆ normalize()

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::normalize ( ) const

return a normalized \(p\).

\[p = \frac{q}{||q||}\]

where \(p\) satisfies \((p.x)^2 + (p.y)^2 + (p.z)^2 + (p.w)^2 = 1.\)

◆ operator*()

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::operator* ( const Quat< _Tp > &  ) const

Multiplication operator of two quaternions q and p. Multiplies values on either side of the operator.

Rule of quaternion multiplication:

\[ \begin{equation} \begin{split} p * q &= [p_0, \boldsymbol{u}]*[q_0, \boldsymbol{v}]\\ &=[p_0q_0 - \boldsymbol{u}\cdot \boldsymbol{v}, p_0\boldsymbol{v} + q_0\boldsymbol{u}+ \boldsymbol{u}\times \boldsymbol{v}]. \end{split} \end{equation} \]

where \(\cdot\) means dot product and \(\times \) means cross product.

For example

Quatd p{1, 2, 3, 4};
Quatd q{5, 6, 7, 8};
std::cout << p * q << std::endl; //[-60, 12, 30, 24]

◆ operator*=() [1/2]

template<typename _Tp >
Quat< _Tp > & cv::Quat< _Tp >::operator*= ( const _Tp  s)

Multiplication assignment operator of a quaternions and a scalar. It multiplies right operand with the left operand and assign the result to left operand.

Rule of quaternion multiplication with a scalar:

\[ \begin{equation} \begin{split} p * s &= [w, x, y, z] * s\\ &=[w * s, x * s, y * s, z * s]. \end{split} \end{equation} \]

For example

Quatd p{1, 2, 3, 4};
double s = 2.0;
p *= s; // equivalent to p = p * s
std::cout << p << std::endl; //[2.0, 4.0, 6.0, 8.0]
Note
the type of scalar should be equal to the quaternion.

◆ operator*=() [2/2]

template<typename _Tp >
Quat< _Tp > & cv::Quat< _Tp >::operator*= ( const Quat< _Tp > &  )

Multiplication assignment operator of two quaternions q and p. It multiplies right operand with the left operand and assign the result to left operand.

Rule of quaternion multiplication:

\[ \begin{equation} \begin{split} p * q &= [p_0, \boldsymbol{u}]*[q_0, \boldsymbol{v}]\\ &=[p_0q_0 - \boldsymbol{u}\cdot \boldsymbol{v}, p_0\boldsymbol{v} + q_0\boldsymbol{u}+ \boldsymbol{u}\times \boldsymbol{v}]. \end{split} \end{equation} \]

where \(\cdot\) means dot product and \(\times \) means cross product.

For example

Quatd p{1, 2, 3, 4};
Quatd q{5, 6, 7, 8};
p *= q; // equivalent to p = p * q
std::cout << p << std::endl; //[-60, 12, 30, 24]

◆ operator+()

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::operator+ ( const Quat< _Tp > &  ) const

Addition operator of two quaternions p and q. It returns a new quaternion that each value is the sum of \(p_i\) and \(q_i\).

For example

Quatd p{1, 2, 3, 4};
Quatd q{5, 6, 7, 8};
std::cout << p + q << std::endl; //[6, 8, 10, 12]

◆ operator+=()

template<typename _Tp >
Quat< _Tp > & cv::Quat< _Tp >::operator+= ( const Quat< _Tp > &  )

Addition assignment operator of two quaternions p and q. It adds right operand to the left operand and assign the result to left operand.

For example

Quatd p{1, 2, 3, 4};
Quatd q{5, 6, 7, 8};
p += q; // equivalent to p = p + q
std::cout << p << std::endl; //[6, 8, 10, 12]

◆ operator-() [1/2]

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::operator- ( ) const

Return opposite quaternion \(-p\) which satisfies \(p + (-p) = 0.\).

For example

Quatd q{1, 2, 3, 4};
std::cout << -q << std::endl; // [-1, -2, -3, -4]

◆ operator-() [2/2]

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::operator- ( const Quat< _Tp > &  ) const

Subtraction operator of two quaternions p and q. It returns a new quaternion that each value is the sum of \(p_i\) and \(-q_i\).

For example

Quatd p{1, 2, 3, 4};
Quatd q{5, 6, 7, 8};
std::cout << p - q << std::endl; //[-4, -4, -4, -4]

◆ operator-=()

template<typename _Tp >
Quat< _Tp > & cv::Quat< _Tp >::operator-= ( const Quat< _Tp > &  )

Subtraction assignment operator of two quaternions p and q. It subtracts right operand from the left operand and assign the result to left operand.

For example

Quatd p{1, 2, 3, 4};
Quatd q{5, 6, 7, 8};
p -= q; // equivalent to p = p - q
std::cout << p << std::endl; //[-4, -4, -4, -4]

◆ operator/() [1/2]

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::operator/ ( const _Tp  s) const

Division operator of a quaternions and a scalar. It divides left operand with the right operand and assign the result to left operand.

Rule of quaternion division with a scalar:

\[ \begin{equation} \begin{split} p / s &= [w, x, y, z] / s\\ &=[w/s, x/s, y/s, z/s]. \end{split} \end{equation} \]

For example

Quatd p{1, 2, 3, 4};
double s = 2.0;
p /= s; // equivalent to p = p / s
std::cout << p << std::endl; //[0.5, 1, 1.5, 2]
Note
the type of scalar should be equal to this quaternion.

◆ operator/() [2/2]

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::operator/ ( const Quat< _Tp > &  ) const

Division operator of two quaternions p and q. Divides left hand operand by right hand operand.

Rule of quaternion division with a scalar:

\[ \begin{equation} \begin{split} p / q &= p * q.inv()\\ \end{split} \end{equation} \]

For example

Quatd p{1, 2, 3, 4};
Quatd q{5, 6, 7, 8};
std::cout << p / q << std::endl; // equivalent to p * q.inv()

◆ operator/=() [1/2]

template<typename _Tp >
Quat< _Tp > & cv::Quat< _Tp >::operator/= ( const _Tp  s)

Division assignment operator of a quaternions and a scalar. It divides left operand with the right operand and assign the result to left operand.

Rule of quaternion division with a scalar:

\[ \begin{equation} \begin{split} p / s &= [w, x, y, z] / s\\ &=[w / s, x / s, y / s, z / s]. \end{split} \end{equation} \]

For example

Quatd p{1, 2, 3, 4};
double s = 2.0;;
p /= s; // equivalent to p = p / s
std::cout << p << std::endl; //[0.5, 1.0, 1.5, 2.0]
Note
the type of scalar should be equal to the quaternion.

◆ operator/=() [2/2]

template<typename _Tp >
Quat< _Tp > & cv::Quat< _Tp >::operator/= ( const Quat< _Tp > &  )

Division assignment operator of two quaternions p and q; It divides left operand with the right operand and assign the result to left operand.

Rule of quaternion division with a quaternion:

\[ \begin{equation} \begin{split} p / q&= p * q.inv()\\ \end{split} \end{equation} \]

For example

Quatd p{1, 2, 3, 4};
Quatd q{5, 6, 7, 8};
p /= q; // equivalent to p = p * q.inv()
std::cout << p << std::endl;

◆ operator==()

template<typename _Tp >
bool cv::Quat< _Tp >::operator== ( const Quat< _Tp > &  ) const

return true if two quaternions p and q are nearly equal, i.e. when the absolute value of each \(p_i\) and \(q_i\) is less than CV_QUAT_EPS.

◆ operator[]() [1/2]

template<typename _Tp >
_Tp & cv::Quat< _Tp >::operator[] ( std::size_t  n)

◆ operator[]() [2/2]

template<typename _Tp >
const _Tp & cv::Quat< _Tp >::operator[] ( std::size_t  n) const

◆ power() [1/2]

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::power ( const _Tp  x,
QuatAssumeType  assumeUnit = QUAT_ASSUME_NOT_UNIT 
) const

return the value of power function with index \(x\).

\[q^x = ||q||(\cos(x\theta) + \boldsymbol{u}\sin(x\theta))).\]

Parameters
xindex of exponentiation.
assumeUnitif QUAT_ASSUME_UNIT, this quaternion assume to be a unit quaternion and this function will save some computations.

For example

Quatd q(1,2,3,4);
q.power(2.0);
double angle = CV_PI;
Vec3d axis{0, 0, 1};
Quatd q1 = Quatd::createFromAngleAxis(angle, axis); //generate a unit quat by axis and angle
q1.power(2.0, assumeUnit); //This assumeUnt means q1 is a unit quaternion
friend Quat< T > power(const Quat< T > &q, const T x, QuatAssumeType assumeUnit)
return the value of power function with index .

◆ power() [2/2]

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::power ( const Quat< _Tp > &  q,
QuatAssumeType  assumeUnit = QUAT_ASSUME_NOT_UNIT 
) const

return the value of power function with quaternion \(q\).

\[p^q = e^{q\ln(p)}.\]

Parameters
qindex quaternion of power function.
assumeUnitif QUAT_ASSUME_UNIT, this quaternion assume to be a unit quaternion and this function will save some computations.

For example

Quatd p(1,2,3,4);
Quatd q(5,6,7,8);
p.power(q);
p = p.normalize();
p.power(q, assumeUnit); //This assumeUnit means p is a unit quaternion

◆ sin()

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::sin ( ) const

return sin value of this quaternion, sin could be calculated as:

\[\sin(p) = \sin(w) * \cosh(||\boldsymbol{v}||) + \cos(w)\frac{\boldsymbol{v}}{||\boldsymbol{v}||}\sinh(||\boldsymbol{v}||)\]

where \(\boldsymbol{v} = [x, y, z].\)

For example

Quatd q(1,2,3,4);
q.sin();

◆ sinh()

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::sinh ( ) const

return sinh value of this quaternion, sinh could be calculated as: \(\sinh(p) = \sin(w)\cos(||\boldsymbol{v}||) + \cosh(w)\frac{v}{||\boldsymbol{v}||}\sin||\boldsymbol{v}||\) where \(\boldsymbol{v} = [x, y, z].\)

For example

Quatd q(1,2,3,4);
q.sinh();

◆ slerp()

template<typename _Tp >
static Quat< _Tp > cv::Quat< _Tp >::slerp ( const Quat< _Tp > &  q0,
const Quat< _Tp > &  q1,
const _Tp  t,
QuatAssumeType  assumeUnit = QUAT_ASSUME_NOT_UNIT,
bool  directChange = true 
)
static

To calculate the interpolation between \(q_0\) and \(q_1\) by Spherical Linear Interpolation(Slerp), which can be defined as:

\[ Slerp(q_0, q_1, t) = \frac{\sin((1-t)\theta)}{\sin(\theta)}q_0 + \frac{\sin(t\theta)}{\sin(\theta)}q_1\]

where \(\theta\) can be calculated as:

\[\theta=cos^{-1}(q_0\cdot q_1)\]

resulting from the both of their norm is unit.

Parameters
q0a quaternion used in Slerp.
q1a quaternion used in Slerp.
tpercent of angle between \(q_0\) and \(q_1\) over a range [0, 1].
assumeUnitif QUAT_ASSUME_UNIT, all input quaternions assume to be unit quaternions. Otherwise, all input quaternions will be normalized inside the function.
directChangeif QUAT_ASSUME_UNIT, the interpolation will choose the nearest path.
Note
If the interpolation angle is small, the error between Nlerp and Slerp is not so large. To improve efficiency and avoid zero division error, we use Nlerp instead of Slerp.

◆ spline()

template<typename _Tp >
static Quat< _Tp > cv::Quat< _Tp >::spline ( const Quat< _Tp > &  q0,
const Quat< _Tp > &  q1,
const Quat< _Tp > &  q2,
const Quat< _Tp > &  q3,
const _Tp  t,
QuatAssumeType  assumeUnit = QUAT_ASSUME_NOT_UNIT 
)
static

to calculate a quaternion which is the result of a \(C^1\) continuous spline curve constructed by squad at the ratio t. Here, the interpolation values are between \(q_1\) and \(q_2\). \(q_0\) and \(q_2\) are used to ensure the \(C^1\) continuity. if t = 0, it returns \(q_1\), if t = 1, it returns \(q_2\).

Parameters
q0the first input quaternion to ensure \(C^1\) continuity.
q1the second input quaternion.
q2the third input quaternion.
q3the fourth input quaternion the same use of \(q1\).
tratio over a range [0, 1].
assumeUnitif QUAT_ASSUME_UNIT, \(q_0, q_1, q_2, q_3\) assume to be unit quaternion. Otherwise, all input quaternions will be normalized inside the function.

For example:

If there are three double quaternions \(v_0, v_1, v_2\) waiting to be interpolated.

Interpolation between \(v_0\) and \(v_1\) with a ratio \(t_0\) could be calculated as

Quatd::spline(v0, v0, v1, v2, t0);

Interpolation between \(v_1\) and \(v_2\) with a ratio \(t_0\) could be calculated as

Quatd::spline(v0, v1, v2, v2, t0);
See also
squad, slerp

◆ sqrt()

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::sqrt ( QuatAssumeType  assumeUnit = QUAT_ASSUME_NOT_UNIT) const

return \(\sqrt{q}\).

Parameters
assumeUnitif QUAT_ASSUME_UNIT, this quaternion assume to be a unit quaternion and this function will save some computations.

For example

Quatf q(1,2,3,4);
q.sqrt();
q = {1,0,0,0};
q.sqrt(assumeUnit); //This assumeUnit means q is a unit quaternion

◆ squad()

template<typename _Tp >
static Quat< _Tp > cv::Quat< _Tp >::squad ( const Quat< _Tp > &  q0,
const Quat< _Tp > &  s0,
const Quat< _Tp > &  s1,
const Quat< _Tp > &  q1,
const _Tp  t,
QuatAssumeType  assumeUnit = QUAT_ASSUME_NOT_UNIT,
bool  directChange = true 
)
static

To calculate the interpolation between \(q_0\), \(q_1\), \(q_2\), \(q_3\) by Spherical and quadrangle(Squad). This could be defined as:

\[Squad(q_i, s_i, s_{i+1}, q_{i+1}, t) = Slerp(Slerp(q_i, q_{i+1}, t), Slerp(s_i, s_{i+1}, t), 2t(1-t))\]

where

\[s_i = q_i\exp(-\frac{\log(q^*_iq_{i+1}) + \log(q^*_iq_{i-1})}{4})\]

The Squad expression is analogous to the \(B\acute{e}zier\) curve, but involves spherical linear interpolation instead of simple linear interpolation. Each \(s_i\) needs to be calculated by three quaternions.

Parameters
q0the first quaternion.
s0the second quaternion.
s1the third quaternion.
q1thr fourth quaternion.
tinterpolation parameter of quadratic and linear interpolation over a range \([0, 1]\).
assumeUnitif QUAT_ASSUME_UNIT, all input quaternions assume to be unit quaternion. Otherwise, all input quaternions will be normalized inside the function.
directChangeif QUAT_ASSUME_UNIT, squad will find the nearest path to interpolate.
See also
interPoint, spline

◆ tan()

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::tan ( ) const

return tan value of this quaternion, tan could be calculated as:

\[\tan(q) = \frac{\sin(q)}{\cos(q)}.\]

For example

Quatd q(1,2,3,4);
q.tan();

◆ tanh()

template<typename _Tp >
Quat< _Tp > cv::Quat< _Tp >::tanh ( ) const

return tanh value of this quaternion, tanh could be calculated as:

\[ \tanh(q) = \frac{\sinh(q)}{\cosh(q)}.\]

For example

Quatd q(1,2,3,4);
q.tanh();
See also
sinh, cosh

◆ toEulerAngles()

template<typename _Tp >
Vec< _Tp, 3 > cv::Quat< _Tp >::toEulerAngles ( QuatEnum::EulerAnglesType  eulerAnglesType)

Transform a quaternion q to Euler angles.

When transforming a quaternion \(q = w + x\boldsymbol{i} + y\boldsymbol{j} + z\boldsymbol{k}\) to Euler angles, rotation matrix M can be calculated by:

\[ \begin{aligned} {M} &={\begin{bmatrix}1-2(y^{2}+z^{2})&2(xy-zx)&2(xz+yw)\\2(xy+zw)&1-2(x^{2}+z^{2})&2(yz-xw)\\2(xz-yw)&2(yz+xw)&1-2(x^{2}+y^{2})\end{bmatrix}}\end{aligned}.\]

On the other hand, the rotation matrix can be obtained from Euler angles. Using intrinsic rotations with Euler angles type XYZ as an example, \(\theta_1 \), \(\theta_2 \), \(\theta_3 \) are three angles for Euler angles, the rotation matrix R can be calculated by:

\[R =X(\theta_1)Y(\theta_2)Z(\theta_3) ={\begin{bmatrix}\cos\theta_{2}\cos\theta_{3}&-\cos\theta_{2}\sin\theta_{3}&\sin\theta_{2}\\\cos\theta_{1}\sin\theta_{3}+\cos\theta_{3}\sin\theta_{1}\sin\theta_{2}&\cos\theta_{1}\cos\theta_{3}-\sin\theta_{1}\sin\theta_{2}\sin\theta_{3}&-\cos\theta_{2}\sin\theta_{1}\\\sin\theta_{1}\sin\theta_{3}-\cos\theta_{1}\cos\theta_{3}\sin\theta_{2}&\cos\theta_{3}\sin\theta_{1}+\cos\theta_{1}\sin\theta_{2}\sin\theta_{3}&\cos\theta_{1}\cos_{2}\end{bmatrix}}\]

Rotation matrix M and R are equal. As long as \( s_{2} \neq 1 \), by comparing each element of two matrices ,the solution is \(\begin{cases} \theta_1 = \arctan2(-m_{23},m_{33})\\\theta_2 = arcsin(m_{13}) \\\theta_3 = \arctan2(-m_{12},m_{11}) \end{cases}\).

When \( s_{2}=1\) or \( s_{2}=-1\), the gimbal lock occurs. The function will prompt "WARNING: Gimbal Lock will occur. Euler angles is non-unique. For intrinsic rotations, we set the third angle to 0, and for external rotation, we set the first angle to 0.".

When \( s_{2}=1\) , The rotation matrix R is \(R = {\begin{bmatrix}0&0&1\\\sin(\theta_1+\theta_3)&\cos(\theta_1+\theta_3)&0\\-\cos(\theta_1+\theta_3)&\sin(\theta_1+\theta_3)&0\end{bmatrix}}\).

The number of solutions is infinite with the condition \(\begin{cases} \theta_1+\theta_3 = \arctan2(m_{21},m_{22})\\ \theta_2=\pi/2 \end{cases}\ \).

We set \( \theta_3 = 0\), the solution is \(\begin{cases} \theta_1=\arctan2(m_{21},m_{22})\\ \theta_2=\pi/2\\ \theta_3=0 \end{cases}\).

When \( s_{2}=-1\), The rotation matrix R is \(X_{1}Y_{2}Z_{3}={\begin{bmatrix}0&0&-1\\-\sin(\theta_1-\theta_3)&\cos(\theta_1-\theta_3)&0\\\cos(\theta_1-\theta_3)&\sin(\theta_1-\theta_3)&0\end{bmatrix}}\).

The number of solutions is infinite with the condition \(\begin{cases} \theta_1+\theta_3 = \arctan2(m_{32},m_{22})\\ \theta_2=\pi/2 \end{cases}\ \).

We set \( \theta_3 = 0\), the solution is \( \begin{cases}\theta_1=\arctan2(m_{32},m_{22}) \\ \theta_2=-\pi/2\\ \theta_3=0\end{cases}\).

Since \( sin \theta\in [-1,1] \) and \( cos \theta \in [-1,1] \), the unnormalized quaternion will cause computational troubles. For this reason, this function will normalize the quaternion at first and QuatAssumeType is not needed.

When the gimbal lock occurs, we set \(\theta_3 = 0\) for intrinsic rotations or \(\theta_1 = 0\) for extrinsic rotations.

As a result, for every Euler angles type, we can get solution as shown in the following table.

EulerAnglesType Ordinary \(\theta_2 = π/2\) \(\theta_2 = -π/2\)
INT_XYZ \( \theta_1 = \arctan2(-m_{23},m_{33})\\\theta_2 = \arcsin(m_{13}) \\\theta_3= \arctan2(-m_{12},m_{11}) \) \( \theta_1=\arctan2(m_{21},m_{22})\\ \theta_2=\pi/2\\ \theta_3=0 \) \( \theta_1=\arctan2(m_{32},m_{22})\\ \theta_2=-\pi/2\\ \theta_3=0 \)
INT_XZY \( \theta_1 = \arctan2(m_{32},m_{22})\\\theta_2 = -\arcsin(m_{12}) \\\theta_3= \arctan2(m_{13},m_{11}) \) \( \theta_1=\arctan2(m_{31},m_{33})\\ \theta_2=\pi/2\\ \theta_3=0 \) \( \theta_1=\arctan2(-m_{23},m_{33})\\ \theta_2=-\pi/2\\ \theta_3=0 \)
INT_YXZ \( \theta_1 = \arctan2(m_{13},m_{33})\\\theta_2 = -\arcsin(m_{23}) \\\theta_3= \arctan2(m_{21},m_{22}) \) \( \theta_1=\arctan2(m_{12},m_{11})\\ \theta_2=\pi/2\\ \theta_3=0 \) \( \theta_1=\arctan2(-m_{12},m_{11})\\ \theta_2=-\pi/2\\ \theta_3=0 \)
INT_YZX \( \theta_1 = \arctan2(-m_{31},m_{11})\\\theta_2 = \arcsin(m_{21}) \\\theta_3= \arctan2(-m_{23},m_{22}) \) \( \theta_1=\arctan2(m_{13},m_{33})\\ \theta_2=\pi/2\\ \theta_3=0 \) \( \theta_1=\arctan2(m_{13},m_{12})\\ \theta_2=-\pi/2\\ \theta_3=0 \)
INT_ZXY \( \theta_1 = \arctan2(-m_{12},m_{22})\\\theta_2 = \arcsin(m_{32}) \\\theta_3= \arctan2(-m_{31},m_{33}) \) \( \theta_1=\arctan2(m_{21},m_{11})\\ \theta_2=\pi/2\\ \theta_3=0 \) \( \theta_1=\arctan2(m_{21},m_{11})\\ \theta_2=-\pi/2\\ \theta_3=0 \)
INT_ZYX \( \theta_1 = \arctan2(m_{21},m_{11})\\\theta_2 = \arcsin(-m_{31}) \\\theta_3= \arctan2(m_{32},m_{33}) \) \( \theta_1=\arctan2(m_{23},m_{22})\\ \theta_2=\pi/2\\ \theta_3=0 \) \( \theta_1=\arctan2(-m_{12},m_{22})\\ \theta_2=-\pi/2\\ \theta_3=0 \)
EXT_XYZ \( \theta_1 = \arctan2(m_{32},m_{33})\\\theta_2 = \arcsin(-m_{31}) \\\ \theta_3 = \arctan2(m_{21},m_{11})\) \( \theta_1= 0\\ \theta_2=\pi/2\\ \theta_3=\arctan2(m_{23},m_{22}) \) \( \theta_1=0\\ \theta_2=-\pi/2\\ \theta_3=\arctan2(-m_{12},m_{22}) \)
EXT_XZY \( \theta_1 = \arctan2(-m_{23},m_{22})\\\theta_2 = \arcsin(m_{21}) \\\theta_3= \arctan2(-m_{31},m_{11})\) \( \theta_1= 0\\ \theta_2=\pi/2\\ \theta_3=\arctan2(m_{13},m_{33}) \) \( \theta_1=0\\ \theta_2=-\pi/2\\ \theta_3=\arctan2(m_{13},m_{12}) \)
EXT_YXZ \( \theta_1 = \arctan2(-m_{31},m_{33}) \\\theta_2 = \arcsin(m_{32}) \\\theta_3= \arctan2(-m_{12},m_{22})\) \( \theta_1= 0\\ \theta_2=\pi/2\\ \theta_3=\arctan2(m_{21},m_{11}) \) \( \theta_1=0\\ \theta_2=-\pi/2\\ \theta_3=\arctan2(m_{21},m_{11}) \)
EXT_YZX \( \theta_1 = \arctan2(m_{13},m_{11})\\\theta_2 = -\arcsin(m_{12}) \\\theta_3= \arctan2(m_{32},m_{22})\) \( \theta_1= 0\\ \theta_2=\pi/2\\ \theta_3=\arctan2(m_{31},m_{33}) \) \( \theta_1=0\\ \theta_2=-\pi/2\\ \theta_3=\arctan2(-m_{23},m_{33}) \)
EXT_ZXY \( \theta_1 = \arctan2(m_{21},m_{22})\\\theta_2 = -\arcsin(m_{23}) \\\theta_3= \arctan2(m_{13},m_{33})\) \( \theta_1= 0\\ \theta_2=\pi/2\\ \theta_3=\arctan2(m_{12},m_{11}) \) \( \theta_1= 0\\ \theta_2=-\pi/2\\ \theta_3=\arctan2(-m_{12},m_{11}) \)
EXT_ZYX \( \theta_1 = \arctan2(-m_{12},m_{11})\\\theta_2 = \arcsin(m_{13}) \\\theta_3= \arctan2(-m_{23},m_{33})\) \( \theta_1=0\\ \theta_2=\pi/2\\ \theta_3=\arctan2(m_{21},m_{22}) \) \( \theta_1=0\\ \theta_2=-\pi/2\\ \theta_3=\arctan2(m_{32},m_{22}) \)
EulerAnglesType Ordinary \(\theta_2 = 0\) \(\theta_2 = π\)
INT_XYX \( \theta_1 = \arctan2(m_{21},-m_{31})\\\theta_2 =\arccos(m_{11}) \\\theta_3 = \arctan2(m_{12},m_{13}) \) \( \theta_1=\arctan2(m_{32},m_{33})\\ \theta_2=0\\ \theta_3=0 \) \( \theta_1=\arctan2(m_{23},m_{22})\\ \theta_2=\pi\\ \theta_3=0 \)
INT_XZX \( \theta_1 = \arctan2(m_{31},m_{21})\\\theta_2 = \arccos(m_{11}) \\\theta_3 = \arctan2(m_{13},-m_{12}) \) \( \theta_1=\arctan2(m_{32},m_{33})\\ \theta_2=0\\ \theta_3=0 \) \( \theta_1=\arctan2(-m_{32},m_{33})\\ \theta_2=\pi\\ \theta_3=0 \)
INT_YXY \( \theta_1 = \arctan2(m_{12},m_{32})\\\theta_2 = \arccos(m_{22}) \\\theta_3 = \arctan2(m_{21},-m_{23}) \) \( \theta_1=\arctan2(m_{13},m_{11})\\ \theta_2=0\\ \theta_3=0 \) \( \theta_1=\arctan2(-m_{31},m_{11})\\ \theta_2=\pi\\ \theta_3=0 \)
INT_YZY \( \theta_1 = \arctan2(m_{32},-m_{12})\\\theta_2 = \arccos(m_{22}) \\\theta_3 =\arctan2(m_{23},m_{21}) \) \( \theta_1=\arctan2(m_{13},m_{11})\\ \theta_2=0\\ \theta_3=0 \) \( \theta_1=\arctan2(m_{13},-m_{11})\\ \theta_2=\pi\\ \theta_3=0 \)
INT_ZXZ \( \theta_1 = \arctan2(-m_{13},m_{23})\\\theta_2 = \arccos(m_{33}) \\\theta_3 =\arctan2(m_{31},m_{32}) \) \( \theta_1=\arctan2(m_{21},m_{22})\\ \theta_2=0\\ \theta_3=0 \) \( \theta_1=\arctan2(m_{21},m_{11})\\ \theta_2=\pi\\ \theta_3=0 \)
INT_ZYZ \( \theta_1 = \arctan2(m_{23},m_{13})\\\theta_2 = \arccos(m_{33}) \\\theta_3 = \arctan2(m_{32},-m_{31}) \) \( \theta_1=\arctan2(m_{21},m_{11})\\ \theta_2=0\\ \theta_3=0 \) \( \theta_1=\arctan2(m_{21},m_{11})\\ \theta_2=\pi\\ \theta_3=0 \)
EXT_XYX \( \theta_1 = \arctan2(m_{12},m_{13}) \\\theta_2 = \arccos(m_{11}) \\\theta_3 = \arctan2(m_{21},-m_{31})\) \( \theta_1=0\\ \theta_2=0\\ \theta_3=\arctan2(m_{32},m_{33}) \) \( \theta_1= 0\\ \theta_2=\pi\\ \theta_3= \arctan2(m_{23},m_{22}) \)
EXT_XZX \( \theta_1 = \arctan2(m_{13},-m_{12})\\\theta_2 = \arccos(m_{11}) \\\theta_3 = \arctan2(m_{31},m_{21})\) \( \theta_1= 0\\ \theta_2=0\\ \theta_3=\arctan2(m_{32},m_{33}) \) \( \theta_1= 0\\ \theta_2=\pi\\ \theta_3=\arctan2(-m_{32},m_{33}) \)
EXT_YXY \( \theta_1 = \arctan2(m_{21},-m_{23})\\\theta_2 = \arccos(m_{22}) \\\theta_3 = \arctan2(m_{12},m_{32}) \) \( \theta_1= 0\\ \theta_2=0\\ \theta_3=\arctan2(m_{13},m_{11}) \) \( \theta_1= 0\\ \theta_2=\pi\\ \theta_3=\arctan2(-m_{31},m_{11}) \)
EXT_YZY \( \theta_1 = \arctan2(m_{23},m_{21}) \\\theta_2 = \arccos(m_{22}) \\\theta_3 = \arctan2(m_{32},-m_{12}) \) \( \theta_1= 0\\ \theta_2=0\\ \theta_3=\arctan2(m_{13},m_{11}) \) \( \theta_1=0\\ \theta_2=\pi\\ \theta_3=\arctan2(m_{13},-m_{11}) \)
EXT_ZXZ \( \theta_1 = \arctan2(m_{31},m_{32}) \\\theta_2 = \arccos(m_{33}) \\\theta_3 = \arctan2(-m_{13},m_{23})\) \( \theta_1=0\\ \theta_2=0\\ \theta_3=\arctan2(m_{21},m_{22}) \) \( \theta_1= 0\\ \theta_2=\pi\\ \theta_3=\arctan2(m_{21},m_{11}) \)
EXT_ZYZ \( \theta_1 = \arctan2(m_{32},-m_{31})\\\theta_2 = \arccos(m_{33}) \\\theta_3 = \arctan2(m_{23},m_{13}) \) \( \theta_1=0\\ \theta_2=0\\ \theta_3=\arctan2(m_{21},m_{11}) \) \( \theta_1= 0\\ \theta_2=\pi\\ \theta_3=\arctan2(m_{21},m_{11}) \)
Parameters
eulerAnglesTypethe convertion Euler angles type

◆ toRotMat3x3()

template<typename _Tp >
Matx< _Tp, 3, 3 > cv::Quat< _Tp >::toRotMat3x3 ( QuatAssumeType  assumeUnit = QUAT_ASSUME_NOT_UNIT) const

transform a quaternion to a 3x3 rotation matrix.

Parameters
assumeUnitif QUAT_ASSUME_UNIT, this quaternion assume to be a unit quaternion and this function will save some computations. Otherwise, this function will normalize this quaternion at first then do the transformation.
Note
Matrix A which is to be rotated should have the form

\[\begin{bmatrix} x_0& x_1& x_2&...&x_n\\ y_0& y_1& y_2&...&y_n\\ z_0& z_1& z_2&...&z_n \end{bmatrix}\]

where the same subscript represents a point. The shape of A assume to be [3, n] The points matrix A can be rotated by toRotMat3x3() * A. The result has 3 rows and n columns too.

For example

double angle = CV_PI;
Vec3d axis{0,0,1};
Quatd q_unit = Quatd::createFromAngleAxis(angle, axis); //quaternion could also be get by interpolation by two or more quaternions.
//assume there is two points (1,0,0) and (1,0,1) to be rotated
Mat pointsA = (Mat_<double>(2, 3) << 1,0,0,1,0,1);
//change the shape
pointsA = pointsA.t();
// rotate 180 degrees around the z axis
Mat new_point = q_unit.toRotMat3x3() * pointsA;
// print two points
cout << new_point << endl;
Template matrix class derived from Mat.
Definition mat.hpp:2230
n-dimensional dense array class
Definition mat.hpp:812
MatExpr t() const
Transposes a matrix.
Matx< _Tp, 3, 3 > toRotMat3x3(QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const
transform a quaternion to a 3x3 rotation matrix.

◆ toRotMat4x4()

template<typename _Tp >
Matx< _Tp, 4, 4 > cv::Quat< _Tp >::toRotMat4x4 ( QuatAssumeType  assumeUnit = QUAT_ASSUME_NOT_UNIT) const

transform a quaternion to a 4x4 rotation matrix.

Parameters
assumeUnitif QUAT_ASSUME_UNIT, this quaternion assume to be a unit quaternion and this function will save some computations. Otherwise, this function will normalize this quaternion at first then do the transformation.

The operations is similar as toRotMat3x3 except that the points matrix should have the form

\[\begin{bmatrix} x_0& x_1& x_2&...&x_n\\ y_0& y_1& y_2&...&y_n\\ z_0& z_1& z_2&...&z_n\\ 0&0&0&...&0 \end{bmatrix}\]

See also
toRotMat3x3

◆ toRotVec()

template<typename _Tp >
Vec< _Tp, 3 > cv::Quat< _Tp >::toRotVec ( QuatAssumeType  assumeUnit = QUAT_ASSUME_NOT_UNIT) const

transform this quaternion to a Rotation vector.

Parameters
assumeUnitif QUAT_ASSUME_UNIT, this quaternion assume to be a unit quaternion and this function will save some computations. Rotation vector rVec is defined as:

\[ rVec = [\theta v_x, \theta v_y, \theta v_z]\]

where \(\theta\) represents rotation angle, and \(\boldsymbol{v}\) represents the normalized rotation axis.

For example

Quatd q(1,2,3,4);
q.toRotVec();
q.normalize().toRotVec(assumeUnit); //answer is same as q.toRotVec().

◆ toVec()

template<typename _Tp >
Vec< _Tp, 4 > cv::Quat< _Tp >::toVec ( ) const

transform the this quaternion to a Vec<T, 4>.

For example

Quatd q(1,2,3,4);
q.toVec();

Friends And Related Symbol Documentation

◆ acos

template<typename _Tp >
template<typename T >
Quat< T > acos ( const Quat< T > &  q)
friend

return arccos value of quaternion q, arccos could be calculated as:

\[\arccos(q) = -\frac{\boldsymbol{v}}{||\boldsymbol{v}||}arccosh(q)\]

where \(\boldsymbol{v} = [x, y, z].\)

Parameters
qa quaternion.

For example

Quatd q(1,2,3,4);
acos(q);
friend Quat< T > acos(const Quat< T > &q)
return arccos value of quaternion q, arccos could be calculated as:

◆ acosh

template<typename _Tp >
template<typename T >
Quat< T > acosh ( const Quat< T > &  q)
friend

return arccosh value of quaternion q, arccosh could be calculated as:

\[arccosh(q) = \ln(q + \sqrt{q^2 - 1})\]

.

Parameters
qa quaternion.

For example

Quatd q(1,2,3,4);
acosh(q);
friend Quat< T > acosh(const Quat< T > &q)
return arccosh value of quaternion q, arccosh could be calculated as:

◆ asin

template<typename _Tp >
template<typename T >
Quat< T > asin ( const Quat< T > &  q)
friend

return arcsin value of quaternion q, arcsin could be calculated as:

\[\arcsin(q) = -\frac{\boldsymbol{v}}{||\boldsymbol{v}||}arcsinh(q\frac{\boldsymbol{v}}{||\boldsymbol{v}||})\]

where \(\boldsymbol{v} = [x, y, z].\)

Parameters
qa quaternion.

For example

Quatd q(1,2,3,4);
asin(q);
friend Quat< T > asin(const Quat< T > &q)
return arcsin value of quaternion q, arcsin could be calculated as:

◆ asinh

template<typename _Tp >
template<typename T >
Quat< T > asinh ( const Quat< T > &  q)
friend

return arcsinh value of quaternion q, arcsinh could be calculated as:

\[arcsinh(q) = \ln(q + \sqrt{q^2 + 1})\]

.

Parameters
qa quaternion.

For example

Quatd q(1,2,3,4);
asinh(q);
friend Quat< T > asinh(const Quat< T > &q)
return arcsinh value of quaternion q, arcsinh could be calculated as:

◆ atan

template<typename _Tp >
template<typename T >
Quat< T > atan ( const Quat< T > &  q)
friend

return arctan value of quaternion q, arctan could be calculated as:

\[\arctan(q) = -\frac{\boldsymbol{v}}{||\boldsymbol{v}||}arctanh(q\frac{\boldsymbol{v}}{||\boldsymbol{v}||})\]

where \(\boldsymbol{v} = [x, y, z].\)

Parameters
qa quaternion.

For example

Quatd q(1,2,3,4);
atan(q);
friend Quat< T > atan(const Quat< T > &q)
return arctan value of quaternion q, arctan could be calculated as:

◆ atanh

template<typename _Tp >
template<typename T >
Quat< T > atanh ( const Quat< T > &  q)
friend

return arctanh value of quaternion q, arctanh could be calculated as:

\[arctanh(q) = \frac{\ln(q + 1) - \ln(1 - q)}{2}\]

.

Parameters
qa quaternion.

For example

Quatd q(1,2,3,4);
atanh(q);
friend Quat< T > atanh(const Quat< T > &q)
return arctanh value of quaternion q, arctanh could be calculated as:

◆ cos

template<typename _Tp >
template<typename T >
Quat< T > cos ( const Quat< T > &  q)
friend

return sin value of quaternion q, cos could be calculated as:

\[\cos(p) = \cos(w) * \cosh(||\boldsymbol{v}||) - \sin(w)\frac{\boldsymbol{v}}{||\boldsymbol{v}||}\sinh(||\boldsymbol{v}||)\]

where \(\boldsymbol{v} = [x, y, z].\)

Parameters
qa quaternion.

For example

Quatd q(1,2,3,4);
cos(q);
friend Quat< T > cos(const Quat< T > &q)
return sin value of quaternion q, cos could be calculated as:

◆ cosh

template<typename _Tp >
template<typename T >
Quat< T > cosh ( const Quat< T > &  q)
friend

return cosh value of quaternion q, cosh could be calculated as:

\[\cosh(p) = \cosh(w) * \cos(||\boldsymbol{v}||) + \sinh(w)\frac{\boldsymbol{v}}{||\boldsymbol{v}||}\sin(||\boldsymbol{v}||)\]

where \(\boldsymbol{v} = [x, y, z].\)

Parameters
qa quaternion.

For example

Quatd q(1,2,3,4);
cosh(q);
friend Quat< T > cosh(const Quat< T > &q)
return cosh value of quaternion q, cosh could be calculated as:

◆ crossProduct

template<typename _Tp >
template<typename T >
Quat< T > crossProduct ( const Quat< T > &  p,
const Quat< T > &  q 
)
friend

return the crossProduct between \(p = (a, b, c, d) = (a, \boldsymbol{u})\) and \(q = (w, x, y, z) = (w, \boldsymbol{v})\).

\[p \times q = \frac{pq- qp}{2}\]

\[p \times q = \boldsymbol{u} \times \boldsymbol{v}\]

\[p \times q = (cz-dy)i + (dx-bz)j + (by-xc)k \]

For example

Quatd q{1,2,3,4};
Quatd p{5,6,7,8};

◆ cv::operator* [1/2]

template<typename _Tp >
template<typename T >
Quat< T > cv::operator* ( const Quat< T > &  ,
const T  s 
)
friend

Multiplication operator of a quaternion and a scalar. It multiplies right operand with the left operand and assign the result to left operand.

Rule of quaternion multiplication with a scalar:

\[ \begin{equation} \begin{split} p * s &= [w, x, y, z] * s\\ &=[w * s, x * s, y * s, z * s]. \end{split} \end{equation} \]

For example

Quatd p{1, 2, 3, 4};
double s = 2.0;
std::cout << p * s << std::endl; //[2.0, 4.0, 6.0, 8.0]
Note
the type of scalar should be equal to the quaternion.

◆ cv::operator* [2/2]

template<typename _Tp >
template<typename T >
Quat< T > cv::operator* ( const T  s,
const Quat< T > &   
)
friend

Multiplication operator of a scalar and a quaternions. It multiplies right operand with the left operand and assign the result to left operand.

Rule of quaternion multiplication with a scalar:

\[ \begin{equation} \begin{split} p * s &= [w, x, y, z] * s\\ &=[w * s, x * s, y * s, z * s]. \end{split} \end{equation} \]

For example

Quatd p{1, 2, 3, 4};
double s = 2.0;
std::cout << s * p << std::endl; //[2.0, 4.0, 6.0, 8.0]
Note
the type of scalar should be equal to the quaternion.

◆ cv::operator+ [1/2]

template<typename _Tp >
template<typename T >
Quat< T > cv::operator+ ( const Quat< T > &  ,
const T  s 
)
friend

Addition operator of a quaternions and a scalar. Adds right hand operand from left hand operand.

For example

Quatd p{1, 2, 3, 4};
double scalar = 2.0;
std::cout << p + scalar << std::endl; //[3.0, 2, 3, 4]
Note
the type of scalar should be equal to the quaternion.

◆ cv::operator+ [2/2]

template<typename _Tp >
template<typename T >
Quat< T > cv::operator+ ( const T  s,
const Quat< T > &   
)
friend

Addition operator of a quaternions and a scalar. Adds right hand operand from left hand operand.

For example

Quatd p{1, 2, 3, 4};
double scalar = 2.0;
std::cout << scalar + p << std::endl; //[3.0, 2, 3, 4]
Note
the type of scalar should be equal to the quaternion.

◆ cv::operator- [1/2]

template<typename _Tp >
template<typename T >
Quat< T > cv::operator- ( const Quat< T > &  ,
const T  s 
)
friend

Subtraction operator of a quaternions and a scalar. Subtracts right hand operand from left hand operand.

For example

Quatd p{1, 2, 3, 4};
double scalar = 2.0;
std::cout << p - scalar << std::endl; //[-1.0, 2, 3, 4]
Note
the type of scalar should be equal to the quaternion.

◆ cv::operator- [2/2]

template<typename _Tp >
template<typename T >
Quat< T > cv::operator- ( const T  s,
const Quat< T > &   
)
friend

Subtraction operator of a scalar and a quaternions. Subtracts right hand operand from left hand operand.

For example

Quatd p{1, 2, 3, 4};
double scalar = 2.0;
std::cout << scalar - p << std::endl; //[1.0, -2, -3, -4]
Note
the type of scalar should be equal to the quaternion.

◆ cv::operator<<

template<typename _Tp >
template<typename S >
std::ostream & cv::operator<< ( std::ostream &  ,
const Quat< S > &   
)
friend

◆ exp

template<typename _Tp >
template<typename T >
Quat< T > exp ( const Quat< T > &  q)
friend

return the value of exponential value.

\[\exp(q) = e^w (\cos||\boldsymbol{v}||+ \frac{v}{||\boldsymbol{v}||})\sin||\boldsymbol{v}||\]

where \(\boldsymbol{v} = [x, y, z].\)

Parameters
qa quaternion.

For example:

Quatd q{1,2,3,4};
cout << exp(q) << endl;

◆ inv

template<typename _Tp >
template<typename T >
Quat< T > inv ( const Quat< T > &  q,
QuatAssumeType  assumeUnit 
)
friend

return \(q^{-1}\) which is an inverse of \(q\) which satisfies \(q * q^{-1} = 1\).

Parameters
qa quaternion.
assumeUnitif QUAT_ASSUME_UNIT, quaternion q assume to be a unit quaternion and this function will save some computations.

For example

Quatd q(1,2,3,4);
inv(q);
q = q.normalize();
inv(q, assumeUnit);//This assumeUnit means p is a unit quaternion
friend Quat< T > inv(const Quat< T > &q, QuatAssumeType assumeUnit)
return which is an inverse of which satisfies .

◆ log

template<typename _Tp >
template<typename T >
Quat< T > log ( const Quat< T > &  q,
QuatAssumeType  assumeUnit 
)
friend

return the value of logarithm function.

\[\ln(q) = \ln||q|| + \frac{\boldsymbol{v}}{||\boldsymbol{v}||}\arccos\frac{w}{||q||}.\]

where \(\boldsymbol{v} = [x, y, z].\)

Parameters
qa quaternion.
assumeUnitif QUAT_ASSUME_UNIT, q assume to be a unit quaternion and this function will save some computations.

For example

Quatd q1{1,2,3,4};
cout << log(q1) << endl;
friend Quat< T > log(const Quat< T > &q, QuatAssumeType assumeUnit)
return the value of logarithm function.

◆ power [1/2]

template<typename _Tp >
template<typename T >
Quat< T > power ( const Quat< T > &  p,
const Quat< T > &  q,
QuatAssumeType  assumeUnit 
)
friend

return the value of power function with quaternion \(q\).

\[p^q = e^{q\ln(p)}.\]

Parameters
pbase quaternion of power function.
qindex quaternion of power function.
assumeUnitif QUAT_ASSUME_UNIT, quaternion \(p\) assume to be a unit quaternion and this function will save some computations.

For example

Quatd p(1,2,3,4);
Quatd q(5,6,7,8);
power(p, q);
p = p.normalize();
power(p, q, assumeUnit); //This assumeUnit means p is a unit quaternion

◆ power [2/2]

template<typename _Tp >
template<typename T >
Quat< T > power ( const Quat< T > &  q,
const T  x,
QuatAssumeType  assumeUnit 
)
friend

return the value of power function with index \(x\).

\[q^x = ||q||(cos(x\theta) + \boldsymbol{u}sin(x\theta))).\]

Parameters
qa quaternion.
xindex of exponentiation.
assumeUnitif QUAT_ASSUME_UNIT, quaternion q assume to be a unit quaternion and this function will save some computations.

For example

Quatd q(1,2,3,4);
power(q, 2.0);
double angle = CV_PI;
Vec3d axis{0, 0, 1};
Quatd q1 = Quatd::createFromAngleAxis(angle, axis); //generate a unit quat by axis and angle
power(q1, 2.0, assumeUnit);//This assumeUnit means q1 is a unit quaternion.
Note
the type of the index should be the same as the quaternion.

◆ sin

template<typename _Tp >
template<typename T >
Quat< T > sin ( const Quat< T > &  q)
friend

return tanh value of quaternion q, sin could be calculated as:

\[\sin(p) = \sin(w) * \cosh(||\boldsymbol{v}||) + \cos(w)\frac{\boldsymbol{v}}{||\boldsymbol{v}||}\sinh(||\boldsymbol{v}||)\]

where \(\boldsymbol{v} = [x, y, z].\)

Parameters
qa quaternion.

For example

Quatd q(1,2,3,4);
sin(q);
friend Quat< T > sin(const Quat< T > &q)
return tanh value of quaternion q, sin could be calculated as:

◆ sinh

template<typename _Tp >
template<typename T >
Quat< T > sinh ( const Quat< T > &  q)
friend

return sinh value of quaternion q, sinh could be calculated as:

\[\sinh(p) = \sin(w)\cos(||\boldsymbol{v}||) + \cosh(w)\frac{v}{||\boldsymbol{v}||}\sin||\boldsymbol{v}||\]

where \(\boldsymbol{v} = [x, y, z].\)

Parameters
qa quaternion.

For example

Quatd q(1,2,3,4);
sinh(q);
friend Quat< T > sinh(const Quat< T > &q)
return sinh value of quaternion q, sinh could be calculated as:

◆ sqrt

template<typename _Tp >
template<typename T >
Quat< T > sqrt ( const Quat< T > &  q,
QuatAssumeType  assumeUnit 
)
friend

return \(\sqrt{q}\).

Parameters
qa quaternion.
assumeUnitif QUAT_ASSUME_UNIT, quaternion q assume to be a unit quaternion and this function will save some computations.

For example

Quatf q(1,2,3,4);
sqrt(q);
q = {1,0,0,0};
sqrt(q, assumeUnit); //This assumeUnit means q is a unit quaternion.
friend Quat< T > sqrt(const Quat< T > &q, QuatAssumeType assumeUnit)
return .

◆ tan

template<typename _Tp >
template<typename T >
Quat< T > tan ( const Quat< T > &  q)
friend

return tan value of quaternion q, tan could be calculated as:

\[\tan(q) = \frac{\sin(q)}{\cos(q)}.\]

Parameters
qa quaternion.

For example

Quatd q(1,2,3,4);
tan(q);
friend Quat< T > tan(const Quat< T > &q)
return tan value of quaternion q, tan could be calculated as:

◆ tanh

template<typename _Tp >
template<typename T >
Quat< T > tanh ( const Quat< T > &  q)
friend

return tanh value of quaternion q, tanh could be calculated as:

\[ \tanh(q) = \frac{\sinh(q)}{\cosh(q)}.\]

Parameters
qa quaternion.

For example

Quatd q(1,2,3,4);
tanh(q);
friend Quat< T > tanh(const Quat< T > &q)
return tanh value of quaternion q, tanh could be calculated as:
See also
sinh, cosh

Member Data Documentation

◆ CV_QUAT_CONVERT_THRESHOLD

template<typename _Tp >
constexpr _Tp cv::Quat< _Tp >::CV_QUAT_CONVERT_THRESHOLD = (_Tp)1.e-6
staticconstexpr

◆ CV_QUAT_EPS

template<typename _Tp >
constexpr _Tp cv::Quat< _Tp >::CV_QUAT_EPS = (_Tp)1.e-6
staticconstexpr

◆ w

template<typename _Tp >
_Tp cv::Quat< _Tp >::w

◆ x

template<typename _Tp >
_Tp cv::Quat< _Tp >::x

◆ y

template<typename _Tp >
_Tp cv::Quat< _Tp >::y

◆ z

template<typename _Tp >
_Tp cv::Quat< _Tp >::z

The documentation for this class was generated from the following file: