Class cv::Quat#
#include <opencv2/core/quaternion.hpp>Collaboration diagram for cv::Quat:
Friends#
Return |
Name |
Description |
|---|---|---|
|
return arccos value of quaternion q, arccos could be calculated as: |
|
|
return arccosh value of quaternion q, arccosh could be calculated as: |
|
|
return arcsin value of quaternion q, arcsin could be calculated as: |
|
|
return arcsinh value of quaternion q, arcsinh could be calculated as: |
|
|
return arctan value of quaternion q, arctan could be calculated as: |
|
|
return arctanh value of quaternion q, arctanh could be calculated as: |
|
|
return sin value of quaternion q, cos could be calculated as: |
|
|
return cosh value of quaternion q, cosh could be calculated as: |
|
|
return the crossProduct between \(p = (a, b, c, d) = (a, \boldsymbol{u})\) and \(q = (w, x, y, z) = (w, \boldsymbol{v})\). |
|
|
Multiplication operator of a quaternion and a scalar. It multiplies right operand with the left operand and assign the result to left operand. |
|
|
Multiplication operator of a scalar and a quaternions. It multiplies right operand with the left operand and assign the result to left operand. |
|
|
Addition operator of a quaternions and a scalar. Adds right hand operand from left hand operand. |
|
|
Addition operator of a quaternions and a scalar. Adds right hand operand from left hand operand. |
|
|
Subtraction operator of a quaternions and a scalar. Subtracts right hand operand from left hand operand. |
|
|
Subtraction operator of a scalar and a quaternions. Subtracts right hand operand from left hand operand. |
|
|
||
|
return the value of exponential value. |
|
|
|
return \(q^{-1}\) which is an inverse of \(q\) which satisfies \(q * q^{-1} = 1\). |
|
|
return the value of logarithm function. |
|
|
return the value of power function with quaternion \(q\). |
|
|
return the value of power function with index \(x\). |
|
return tanh value of quaternion q, sin could be calculated as: |
|
|
return sinh value of quaternion q, sinh could be calculated as: |
|
|
return \(\sqrt{q}\). |
|
|
return tan value of quaternion q, tan could be calculated as: |
|
|
return tanh value of quaternion q, tanh could be calculated as: |
Detailed Description#
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:
A unit quaternion is usually represents rotation, which has the form:
To create a quaternion representing the rotation around the axis \(\boldsymbol{u}\) with angle \(\theta\), you can use
You can simply use four same type number to create a quaternion
Quatd q(1, 2, 3, 4);
If you already have a 3x3 rotation matrix R, then you can use
If you already have a rotation vector rvec which has the form of angle * axis, then you can use
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()
spline can smoothly connect rotations of multiple quaternionsThree 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;
Member Typedef Documentation#
value_type#
typedef _Tp cv::Quat::value_type
Constructor & Destructor Documentation#
Quat()#
Quat()#
cv::Quat::Quat(
_Tp w,
_Tp x,
_Tp y,
_Tp z )
from four numbers.
Quat()#
cv::Quat::Quat(const Vec< _Tp, 4 > & coeff)
From Vec4d or Vec4f.
Member Function Documentation#
acos()#
return arccos value of this quaternion, arccos could be calculated as:
where \(\boldsymbol{v} = [x, y, z].\)
For example
Quatd q(1,2,3,4);
q.acos();
acosh()#
return arccosh value of this quaternion, arccosh could be calculated as:
.
For example
Quatd q(1,2,3,4);
q.acosh();
asin()#
return arcsin value of this quaternion, arcsin could be calculated as:
where \(\boldsymbol{v} = [x, y, z].\)
For example
Quatd q(1,2,3,4);
q.asin();
asinh()#
return arcsinh value of this quaternion, arcsinh could be calculated as:
.
For example
Quatd q(1,2,3,4);
q.asinh();
assertNormal()#
void cv::Quat::assertNormal(_Tp eps = CV_QUAT_EPS)
to throw an error if this quaternion is not a unit quaternion.
See also
Parameters
eps— tolerance scope of normalization.
at()#
_Tp cv::Quat::at(size_t index)
a way to get element.
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.
Parameters
index— over a range [0, 3].
atan()#
return arctan value of this quaternion, arctan could be calculated as:
where \(\boldsymbol{v} = [x, y, z].\)
For example
Quatd q(1,2,3,4);
q.atan();
atanh()#
return arctanh value of this quaternion, arctanh could be calculated as:
.
For example
Quatd q(1,2,3,4);
q.atanh();
conjugate()#
Quat< _Tp > cv::Quat::conjugate()
return the conjugate of this quaternion.
cos()#
return cos value of this quaternion, cos could be calculated as:
where \(\boldsymbol{v} = [x, y, z].\)
For example
Quatd q(1,2,3,4);
q.cos();
cosh()#
return cosh value of this quaternion, cosh could be calculated as:
where \(\boldsymbol{v} = [x, y, z].\)
For example
Quatd q(1,2,3,4);
q.cosh();
crossProduct()#
Quat< _Tp > cv::Quat::crossProduct(const Quat< _Tp > & q)
return the crossProduct between \(p = (a, b, c, d) = (a, \boldsymbol{u})\) and \(q = (w, x, y, z) = (w, \boldsymbol{v})\).
For example
dot()#
_Tp cv::Quat::dot(Quat< _Tp > q)
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.
For example
Parameters
q— the other quaternion.
exp()#
return the value of exponential value.
where \(\boldsymbol{v} = [x, y, z].\)
For example
Quatd q{1,2,3,4};
cout << q.exp() << endl;
getAngle()#
_Tp cv::Quat::getAngle(QuatAssumeType assumeUnit = QUAT_ASSUME_NOT_UNIT)
get the angle of quaternion, it returns the rotation angle.
For example
Quatd q(1,2,3,4);
q.getAngle();
QuatAssumeType assumeUnit = QUAT_ASSUME_UNIT;
q.normalize().getAngle(assumeUnit);//same as q.getAngle().
Note
It always return the value between \([0, 2\pi]\).
Parameters
assumeUnit— if QUAT_ASSUME_UNIT, this quaternion assume to be a unit quaternion and this function will save some computations.\[ \psi = 2 *arccos(\frac{w}{||q||}) \]
getAxis()#
Vec< _Tp, 3 > cv::Quat::getAxis(QuatAssumeType assumeUnit = QUAT_ASSUME_NOT_UNIT)
get the axis of quaternion, it returns a vector of length 3.
the unit axis \(\boldsymbol{u}\) is defined by
where \(v=[x, y ,z]\) and \(\theta\) represents rotation angle.
For example
Quatd q(1,2,3,4);
q.getAxis();
QuatAssumeType assumeUnit = QUAT_ASSUME_UNIT;
q.normalize().getAxis(assumeUnit);//same as q.getAxis()
Parameters
assumeUnit— if QUAT_ASSUME_UNIT, this quaternion assume to be a unit quaternion and this function will save some computations.
inv()#
Quat< _Tp > cv::Quat::inv(QuatAssumeType assumeUnit = QUAT_ASSUME_NOT_UNIT)
return \(q^{-1}\) which is an inverse of \(q\) satisfying \(q * q^{-1} = 1\).
For example
Quatd q(1,2,3,4);
q.inv();
QuatAssumeType assumeUnit = QUAT_ASSUME_UNIT;
q = q.normalize();
q.inv(assumeUnit); //assumeUnit means p is a unit quaternion
Parameters
assumeUnit— if QUAT_ASSUME_UNIT, quaternion q assume to be a unit quaternion and this function will save some computations.
isNormal()#
bool cv::Quat::isNormal(_Tp eps = CV_QUAT_EPS)
return true if this quaternion is a unit quaternion.
where
And this function will consider it is normalized when the dotValue over a range \([1-eps, 1+eps]\).
Parameters
eps— tolerance scope of normalization. The eps could be defined as
log()#
Quat< _Tp > cv::Quat::log(QuatAssumeType assumeUnit = QUAT_ASSUME_NOT_UNIT)
return the value of logarithm function.
. where \(\boldsymbol{v} = [x, y, z].\) For example
Quatd q(1,2,3,4);
q.log();
QuatAssumeType assumeUnit = QUAT_ASSUME_UNIT;
Quatd q1(1,2,3,4);
q1.normalize().log(assumeUnit);
Parameters
assumeUnit— if QUAT_ASSUME_UNIT, this quaternion assume to be a unit quaternion and this function will save some computations.
norm()#
_Tp cv::Quat::norm()
return the norm of quaternion.
normalize()#
Quat< _Tp > cv::Quat::normalize()
return a normalized \(p\).
where \(p\) satisfies \((p.x)^2 + (p.y)^2 + (p.z)^2 + (p.w)^2 = 1.\)
operator*()#
Quat< _Tp > cv::Quat::operator*(const Quat< _Tp > &)
Multiplication operator of two quaternions q and p. Multiplies values on either side of the operator.
Rule of quaternion multiplication:
where \(\cdot\) means dot product and \(\times \) means cross product.
For example
operator*=()#
Quat< _Tp > & cv::Quat::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:
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*=()#
Quat< _Tp > & cv::Quat::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:
where \(\cdot\) means dot product and \(\times \) means cross product.
For example
operator+()#
Quat< _Tp > cv::Quat::operator+(const Quat< _Tp > &)
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
operator+=()#
Quat< _Tp > & cv::Quat::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
operator-()#
Quat< _Tp > cv::Quat::operator-()
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-()#
Quat< _Tp > cv::Quat::operator-(const Quat< _Tp > &)
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
operator-=()#
Quat< _Tp > & cv::Quat::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
operator/()#
Quat< _Tp > cv::Quat::operator/(const _Tp s)
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:
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/()#
Quat< _Tp > cv::Quat::operator/(const Quat< _Tp > &)
Division operator of two quaternions p and q. Divides left hand operand by right hand operand.
Rule of quaternion division with a scalar:
For example
operator/=()#
Quat< _Tp > & cv::Quat::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:
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/=()#
Quat< _Tp > & cv::Quat::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:
For example
operator==()#
bool cv::Quat::operator==(const Quat< _Tp > &)
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#
_Tp & cv::Quat::operator[](std::size_t n)
operator#
const _Tp & cv::Quat::operator[](std::size_t n)
power()#
Quat< _Tp > cv::Quat::power(
const _Tp x,
QuatAssumeType assumeUnit = QUAT_ASSUME_NOT_UNIT )
return the value of power function with index \(x\).
For example
Quatd q(1,2,3,4);
q.power(2.0);
QuatAssumeType assumeUnit = QUAT_ASSUME_UNIT;
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
Parameters
x— index of exponentiation.assumeUnit— if QUAT_ASSUME_UNIT, this quaternion assume to be a unit quaternion and this function will save some computations.
power()#
Quat< _Tp > cv::Quat::power(
const Quat< _Tp > & q,
QuatAssumeType assumeUnit = QUAT_ASSUME_NOT_UNIT )
return the value of power function with quaternion \(q\).
For example
Quatd p(1,2,3,4);
Quatd q(5,6,7,8);
p.power(q);
QuatAssumeType assumeUnit = QUAT_ASSUME_UNIT;
p = p.normalize();
p.power(q, assumeUnit); //This assumeUnit means p is a unit quaternion
Parameters
q— index quaternion of power function.assumeUnit— if QUAT_ASSUME_UNIT, this quaternion assume to be a unit quaternion and this function will save some computations.
sin()#
return sin value of this quaternion, sin could be calculated as:
where \(\boldsymbol{v} = [x, y, z].\)
For example
Quatd q(1,2,3,4);
q.sin();
sinh()#
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();
sqrt()#
Quat< _Tp > cv::Quat::sqrt(QuatAssumeType assumeUnit = QUAT_ASSUME_NOT_UNIT)
return \(\sqrt{q}\).
For example
Quatf q(1,2,3,4);
q.sqrt();
QuatAssumeType assumeUnit = QUAT_ASSUME_UNIT;
q = {1,0,0,0};
q.sqrt(assumeUnit); //This assumeUnit means q is a unit quaternion
Parameters
assumeUnit— if QUAT_ASSUME_UNIT, this quaternion assume to be a unit quaternion and this function will save some computations.
tan()#
return tan value of this quaternion, tan could be calculated as:
For example
Quatd q(1,2,3,4);
q.tan();
tanh()#
return tanh value of this quaternion, tanh could be calculated as:
For example
Quatd q(1,2,3,4);
q.tanh();
toEulerAngles()#
Vec< _Tp, 3 > cv::Quat::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:
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:
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
eulerAnglesType— the conversion Euler angles type
toRotMat3x3()#
Matx< _Tp, 3, 3 > cv::Quat::toRotMat3x3(QuatAssumeType assumeUnit = QUAT_ASSUME_NOT_UNIT)
transform a quaternion to a 3x3 rotation matrix.
Note
Matrix A which is to be rotated should have the form
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;
Parameters
assumeUnit— if 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.
toRotMat4x4()#
Matx< _Tp, 4, 4 > cv::Quat::toRotMat4x4(QuatAssumeType assumeUnit = QUAT_ASSUME_NOT_UNIT)
transform a quaternion to a 4x4 rotation matrix.
The operations is similar as toRotMat3x3 except that the points matrix should have the form
See also
Parameters
assumeUnit— if 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.
toRotVec()#
Vec< _Tp, 3 > cv::Quat::toRotVec(QuatAssumeType assumeUnit = QUAT_ASSUME_NOT_UNIT)
transform this quaternion to a Rotation vector.
For example
Quatd q(1,2,3,4);
q.toRotVec();
QuatAssumeType assumeUnit = QUAT_ASSUME_UNIT;
q.normalize().toRotVec(assumeUnit); //answer is same as q.toRotVec().
Parameters
assumeUnit— if 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.
toVec()#
Vec< _Tp, 4 > cv::Quat::toVec()
transform the this quaternion to a Vec<T, 4>.
For example
Quatd q(1,2,3,4);
q.toVec();
createFromAngleAxis()#
static Quat< _Tp > cv::Quat::createFromAngleAxis(
const _Tp angle,
const Vec< _Tp, 3 > & axis )
from an angle, axis. Axis will be normalized in this function. And it generates
where \(\psi = \frac{\theta}{2}\), \(\theta\) is the rotation angle.
createFromEulerAngles()#
static Quat< _Tp > cv::Quat::createFromEulerAngles(
const Vec< _Tp, 3 > & angles,
QuatEnum::EulerAnglesType eulerAnglesType )
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
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
angles— the Euler angles in a vector of length 3eulerAnglesType— the conversion Euler angles type
createFromRotMat()#
static Quat< _Tp > cv::Quat::createFromRotMat(InputArray R)
from a 3x3 rotation matrix.
createFromRvec()#
static Quat< _Tp > cv::Quat::createFromRvec(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.
Angle and axis could be easily derived as:
Then a quaternion can be calculated by
where \(\psi = \theta / 2 \)
createFromXRot()#
static Quat< _Tp > cv::Quat::createFromXRot(const _Tp theta)
get a quaternion from a rotation about the X-axis by \(\theta\) .
createFromYRot()#
static Quat< _Tp > cv::Quat::createFromYRot(const _Tp theta)
get a quaternion from a rotation about the Y-axis by \(\theta\) .
createFromZRot()#
static Quat< _Tp > cv::Quat::createFromZRot(const _Tp theta)
get a quaternion from a rotation about the Z-axis by \(\theta\).
interPoint()#
static Quat< _Tp > cv::Quat::interPoint(
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.
See also
Parameters
q0— the first quaternion.q1— the second quaternion.q2— the third quaternion.assumeUnit— if QUAT_ASSUME_UNIT, all input quaternions assume to be unit quaternion. Otherwise, all input quaternions will be normalized inside the function.
lerp()#
static Quat< _Tp > cv::Quat::lerp(
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:
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.
Note
it returns a non-unit quaternion.
Parameters
q0— a quaternion used in linear interpolation.q1— a quaternion used in linear interpolation.t— percent of vector \(\overrightarrow{q_0q_1}\) over a range [0, 1].
nlerp()#
static Quat< _Tp > cv::Quat::nlerp(
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).
The interpolation will always choose the shortest path but the constant speed is not guaranteed.
See also
Parameters
q0— a quaternion used in normalized linear interpolation.q1— a quaternion used in normalized linear interpolation.t— percent of vector \(\overrightarrow{q_0q_1}\) over a range [0, 1].assumeUnit— if QUAT_ASSUME_UNIT, all input quaternions assume to be unit quaternion. Otherwise, all inputs quaternion will be normalized inside the function.
slerp()#
static Quat< _Tp > cv::Quat::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 \(q_0\) and \(q_1\) by Spherical Linear Interpolation(Slerp), which can be defined as:
where \(\theta\) can be calculated as:
resulting from the both of their norm is unit.
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.
Parameters
q0— a quaternion used in Slerp.q1— a quaternion used in Slerp.t— percent of angle between \(q_0\) and \(q_1\) over a range [0, 1].assumeUnit— if QUAT_ASSUME_UNIT, all input quaternions assume to be unit quaternions. Otherwise, all input quaternions will be normalized inside the function.directChange— if QUAT_ASSUME_UNIT, the interpolation will choose the nearest path.
spline()#
static Quat< _Tp > cv::Quat::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 \(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\).
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);
Parameters
q0— the first input quaternion to ensure \(C^1\) continuity.q1— the second input quaternion.q2— the third input quaternion.q3— the fourth input quaternion the same use of \(q1\).t— ratio over a range [0, 1].assumeUnit— if 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.
squad()#
static Quat< _Tp > cv::Quat::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 )
To calculate the interpolation between \(q_0\), \(q_1\), \(q_2\), \(q_3\) by Spherical and quadrangle(Squad). This could be defined as:
where
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.
See also
Parameters
q0— the first quaternion.s0— the second quaternion.s1— the third quaternion.q1— thr fourth quaternion.t— interpolation parameter of quadratic and linear interpolation over a range \([0, 1]\).assumeUnit— if QUAT_ASSUME_UNIT, all input quaternions assume to be unit quaternion. Otherwise, all input quaternions will be normalized inside the function.directChange— if QUAT_ASSUME_UNIT, squad will find the nearest path to interpolate.
Member Data Documentation#
CV_QUAT_CONVERT_THRESHOLD#
static _Tp cv::Quat::CV_QUAT_CONVERT_THRESHOLD = (_Tp)1.e-6
CV_QUAT_EPS#
static _Tp cv::Quat::CV_QUAT_EPS = (_Tp)1.e-6
w#
_Tp cv::Quat::w
x#
_Tp cv::Quat::x
y#
_Tp cv::Quat::y
z#
_Tp cv::Quat::z
Source file#
The documentation for this class was generated from the following file:
opencv2/core/quaternion.hpp