Class cv::DualQuat#
#include <opencv2/core/dualquaternion.hpp>Collaboration diagram for cv::DualQuat:
Friends#
Return |
Name |
Description |
|---|---|---|
|
return the conjugate of a dual quaternion. |
|
|
Multiplication operator of a dual quaternions 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 dual quaternions. It multiplies right operand with the left operand and assign the result to left operand. |
|
|
Addition operator of a dual quaternions and a scalar. Adds right hand operand from left hand operand. |
|
|
Addition operator of a scalar and a dual quaternions. Adds right hand operand from left hand operand. |
|
|
Subtraction operator of a dual quaternion and a scalar. Subtracts right hand operand from left hand operand. |
|
|
Subtraction operator of a scalar and a dual quaternions. Subtracts right hand operand from left hand operand. |
|
|
||
|
return the value of exponential function value |
|
|
if \(\sigma = p + \epsilon q\) is a dual quaternion, p is not zero, the inverse dual quaternion is |
|
|
return the value of logarithm function value |
|
|
|
return the value of \(p^t\) where p is a dual quaternion. This could be calculated as: |
|
|
return the value of \(p^q\) where p and q are dual quaternions. This could be calculated as: |
Detailed Description#
Dual quaternions were introduced to describe rotation together with translation while ordinary quaternions can only describe rotation. It can be used for shortest path pose interpolation, local pose optimization or volumetric deformation. More details can be found
A unit dual quaternion can be classically represented as:
A general dual quaternions which consist of two quaternions is usually represented in form of:
Alternatively, dual quaternions can also be interpreted as four components which are all dual numbers:
If you want to create a dual quaternion, you can use:
using namespace cv;
double angle = CV_PI;
// create from eight number
DualQuatd dq1(1, 2, 3, 4, 5, 6, 7, 8); //p = [1,2,3,4]. q=[5,6,7,8]
// create from Vec
Vec<double, 8> v{1,2,3,4,5,6,7,8};
DualQuatd dq_v{v};
// create from two quaternion
Quatd p(1, 2, 3, 4);
Quatd q(5, 6, 7, 8);
DualQuatd dq2 = DualQuatd::createFromQuat(p, q);
// create from an angle, an axis and a translation
Vec3d axis{0, 0, 1};
Vec3d trans{3, 4, 5};
DualQuatd dq3 = DualQuatd::createFromAngleAxisTrans(angle, axis, trans);
// If you already have an instance of class Affine3, then you can use
Affine3d R = dq3.toAffine3();
DualQuatd dq4 = DualQuatd::createFromAffine3(R);
// or create directly by affine transformation matrix Rt
// see createFromMat() in detail for the form of Rt
Matx44d Rt = dq3.toMat();
DualQuatd dq5 = DualQuatd::createFromMat(Rt);
// Any rotation + translation movement can
// be expressed as a rotation + translation around the same line in space (expressed by Plucker
// coords), and here's a way to represent it this way.
Vec3d axis{1, 1, 1}; // axis will be normalized in createFromPitch
Vec3d trans{3, 4 ,5};
axis = axis / std::sqrt(axis.dot(axis));// The formula for computing moment that I use below requires a normalized axis
Vec3d moment = 1.0 / 2 * (trans.cross(axis) + axis.cross(trans.cross(axis)) *
std::cos(rotation_angle / 2) / std::sin(rotation_angle / 2));
double d = trans.dot(qaxis);
DualQuatd dq6 = DualQuatd::createFromPitch(angle, d, axis, moment);
A point \(v=(x, y, z)\) in form of dual quaternion is \([1+\epsilon v]=[1,0,0,0,0,x,y,z]\). The transformation of a point \(v_1\) to another point \(v_2\) under the dual quaternion \(\sigma\) is
A line in the \(Pl\ddot{u}cker\) coordinates \((\hat{l}, m)\) defined by the dual quaternion \(l=\hat{l}+\epsilon m\). To transform a line,
To extract the Vec<double, 8> or Vec<float, 8>, see toVec();
To extract the affine transformation matrix, see toMat();
To extract the instance of Affine3, see toAffine3();
If two quaternions \(q_0, q_1\) are needed to be interpolated, you can use sclerp()
DualQuatd::sclerp(q0, q1, t)
DualQuatd::dqblend(q0, q1, t)
Member Typedef Documentation#
value_type#
typedef _Tp cv::DualQuat::value_type
Constructor & Destructor Documentation#
DualQuat()#
DualQuat()#
cv::DualQuat::DualQuat(
const _Tp w,
const _Tp x,
const _Tp y,
const _Tp z,
const Tp w,
const Tp x,
const Tp y,
const Tp z )
create from eight same type numbers.
DualQuat()#
cv::DualQuat::DualQuat(const Vec< _Tp, 8 > & q)
create from a double or float vector.
Member Function Documentation#
conjugate()#
DualQuat< _Tp > cv::DualQuat::conjugate()
return the conjugate of a dual quaternion.
dot()#
_Tp cv::DualQuat::dot(DualQuat< _Tp > p)
return the dot product of two dual quaternion.
Parameters
p— other dual quaternion.
exp()#
DualQuat< _Tp > cv::DualQuat::exp()
return the value of exponential function value
getDualPart()#
Quat< _Tp > cv::DualQuat::getDualPart()
return a quaternion which represent the dual part of dual quaternion. The definition of dual part is in createFromQuat().
See also
getRealPart()#
Quat< _Tp > cv::DualQuat::getRealPart()
return a quaternion which represent the real part of dual quaternion. The definition of real part is in createFromQuat().
See also
getRotation()#
Quat< _Tp > cv::DualQuat::getRotation(QuatAssumeType assumeUnit = QUAT_ASSUME_NOT_UNIT)
return the rotation in quaternion form.
getTranslation()#
Vec< _Tp, 3 > cv::DualQuat::getTranslation(QuatAssumeType assumeUnit = QUAT_ASSUME_NOT_UNIT)
return the translation vector. The rotation \(r\) in this dual quaternion \(\sigma\) is applied before translation \(t\). The dual quaternion \(\sigma\) is defined as
Thus, the translation can be obtained as follows
Note
This dual quaternion’s translation is applied after the rotation.
Parameters
assumeUnit— if QUAT_ASSUME_UNIT, this dual quaternion assume to be a unit dual quaternion and this function will save some computations.
inv()#
DualQuat< _Tp > cv::DualQuat::inv(QuatAssumeType assumeUnit = QUAT_ASSUME_NOT_UNIT)
if \(\sigma = p + \epsilon q\) is a dual quaternion, p is not zero, the inverse dual quaternion is
or equivalentlly,
Parameters
assumeUnit— if QUAT_ASSUME_UNIT, this dual quaternion assume to be a unit dual quaternion and this function will save some computations.
log()#
DualQuat< _Tp > cv::DualQuat::log(QuatAssumeType assumeUnit = QUAT_ASSUME_NOT_UNIT)
return the value of logarithm function value
Parameters
assumeUnit— if QUAT_ASSUME_UNIT, this dual quaternion assume to be a unit dual quaternion and this function will save some computations.
norm()#
DualQuat< _Tp > cv::DualQuat::norm()
return the norm \(||\sigma||\) of dual quaternion \(\sigma = p + \epsilon q\).
Generally speaking, the norm of a not unit dual quaternion is a dual number. For convenience, we return it in the form of a dual quaternion , i.e.
Note
The data type of dual number is dual quaternion.
normalize()#
DualQuat< _Tp > cv::DualQuat::normalize()
return a normalized dual quaternion. A dual quaternion can be expressed as
where \(r, t\) represents the rotation (ordinary quaternion) and translation (pure ordinary quaternion) respectively, and \(||\sigma||\) is the norm of dual quaternion(a dual number). A dual quaternion is unit if and only if
where \(\cdot\) means dot product. The process of normalization is
Next, we simply proof \(\sigma_u\) is a unit dual quaternion:
As expected, the real part is a rotation and dual part is a pure quaternion.
operator*()#
DualQuat< _Tp > cv::DualQuat::operator*(const DualQuat< _Tp > &)
Multiplication operator of two dual quaternions q and p. Multiplies values on either side of the operator.
Rule of dual quaternion multiplication: The dual quaternion can be written as an ordered pair of quaternions [A, B]. Thus
For example
operator*=()#
DualQuat< _Tp > cv::DualQuat::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 dual quaternion multiplication with a scalar:
For example
DualQuatd p{1, 2, 3, 4, 5, 6, 7, 8};
double s = 2.0;
p *= s;
std::cout << p << std::endl; //[2, 4, 6, 8, 10, 12, 14, 16]
Note
the type of scalar should be equal to the dual quaternion.
operator*=()#
DualQuat< _Tp > & cv::DualQuat::operator*=(const DualQuat< _Tp > &)
Multiplication assignment operator of two quaternions. It multiplies right operand with the left operand and assign the result to left operand.
Rule of dual quaternion multiplication: The dual quaternion can be written as an ordered pair of quaternions [A, B]. Thus
For example
operator+()#
DualQuat< _Tp > cv::DualQuat::operator+(const DualQuat< _Tp > &)
Addition operator of two dual quaternions p and q. It returns a new dual quaternion that each value is the sum of \(p_i\) and \(q_i\).
For example
operator+=()#
DualQuat< _Tp > & cv::DualQuat::operator+=(const DualQuat< _Tp > &)
Addition assignment operator of two dual quaternions p and q. It adds right operand to the left operand and assign the result to left operand.
For example
operator-()#
DualQuat< _Tp > cv::DualQuat::operator-()
Return opposite dual quaternion \(-p\) which satisfies \(p + (-p) = 0.\).
For example
DualQuatd q{1, 2, 3, 4, 5, 6, 7, 8};
std::cout << -q << std::endl; // [-1, -2, -3, -4, -5, -6, -7, -8]
operator-()#
DualQuat< _Tp > cv::DualQuat::operator-(const DualQuat< _Tp > &)
Subtraction operator of two dual quaternions p and q. It returns a new dual quaternion that each value is the sum of \(p_i\) and \(-q_i\).
For example
operator-=()#
DualQuat< _Tp > & cv::DualQuat::operator-=(const DualQuat< _Tp > &)
Subtraction assignment operator of two dual quaternions p and q. It subtracts right operand from the left operand and assign the result to left operand.
For example
operator/()#
DualQuat< _Tp > cv::DualQuat::operator/(const _Tp s)
Division operator of a dual quaternions and a scalar. It divides left operand with the right operand and assign the result to left operand.
Rule of dual quaternion division with a scalar:
For example
DualQuatd p{1, 2, 3, 4, 5, 6, 7, 8};
double s = 2.0;
p /= s; // equivalent to p = p / s
std::cout << p << std::endl; //[0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4]
Note
the type of scalar should be equal to this dual quaternion.
operator/()#
DualQuat< _Tp > cv::DualQuat::operator/(const DualQuat< _Tp > &)
Division operator of two dual quaternions p and q. Divides left hand operand by right hand operand.
Rule of dual quaternion division with a dual quaternion:
For example
operator/=()#
Quat< _Tp > & cv::DualQuat::operator/=(const _Tp s)
Division assignment operator of a dual quaternions and a scalar. It divides left operand with the right operand and assign the result to left operand.
Rule of dual quaternion division with a scalar:
For example
DualQuatd p{1, 2, 3, 4, 5, 6, 7, 8};
double s = 2.0;;
p /= s; // equivalent to p = p / s
std::cout << p << std::endl; //[0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0]
Note
the type of scalar should be equal to the dual quaternion.
operator/=()#
DualQuat< _Tp > & cv::DualQuat::operator/=(const DualQuat< _Tp > &)
Division assignment operator of two dual quaternions p and q; It divides left operand with the right operand and assign the result to left operand.
Rule of dual quaternion division with a quaternion:
For example
operator==()#
bool cv::DualQuat::operator==(const DualQuat< _Tp > &)
return true if two dual quaternions p and q are nearly equal, i.e. when the absolute value of each \(p_i\) and \(q_i\) is less than CV_DUAL_QUAT_EPS.
power()#
DualQuat< _Tp > cv::DualQuat::power(
const _Tp t,
QuatAssumeType assumeUnit = QUAT_ASSUME_NOT_UNIT )
return the value of \(p^t\) where p is a dual quaternion. This could be calculated as:
Parameters
t— index of power function.assumeUnit— if QUAT_ASSUME_UNIT, this dual quaternion assume to be a unit dual quaternion and this function will save some computations.
power()#
DualQuat< _Tp > cv::DualQuat::power(
const DualQuat< _Tp > & q,
QuatAssumeType assumeUnit = QUAT_ASSUME_NOT_UNIT )
return the value of \(p^q\) where p and q are dual quaternions. This could be calculated as:
Parameters
q— a dual quaternionassumeUnit— if QUAT_ASSUME_UNIT, this dual quaternion assume to be a dual unit quaternion and this function will save some computations.
toAffine3()#
Affine3< _Tp > cv::DualQuat::toAffine3(QuatAssumeType assumeUnit = QUAT_ASSUME_NOT_UNIT)
Transform this dual quaternion to a instance of Affine3.
toMat()#
Matx< _Tp, 4, 4 > cv::DualQuat::toMat(QuatAssumeType assumeUnit = QUAT_ASSUME_NOT_UNIT)
Transform this dual quaternion to a affine transformation matrix the form of matrix, see createFromMat().
toVec()#
Vec< _Tp, 8 > cv::DualQuat::toVec()
Transform this dual quaternion to a vector.
createFromAffine3()#
static DualQuat< _Tp > cv::DualQuat::createFromAffine3(const Affine3< _Tp > & R)
create dual quaternion from an affine matrix. The definition of affine matrix can refer to createFromMat()
createFromAngleAxisTrans()#
static DualQuat< _Tp > cv::DualQuat::createFromAngleAxisTrans(
const _Tp angle,
const Vec< _Tp, 3 > & axis,
const Vec< _Tp, 3 > & translation )
create a dual quaternion from a rotation angle \(\theta\), a rotation axis \(\boldsymbol{u}\) and a translation \(\boldsymbol{t}\). It generates a dual quaternion \(\sigma\) in the form of
Note
Axis will be normalized in this function. And translation is applied after the rotation. Use createFromQuat(r, r * t / 2) to create a dual quaternion which translation is applied before rotation.
See also
Parameters
angle— rotation angle.axis— rotation axis.translation— a vector of length 3.
createFromMat()#
static DualQuat< _Tp > cv::DualQuat::createFromMat(InputArray _R)
Transform this dual quaternion to an affine transformation matrix \(M\). Dual quaternion consists of a rotation \(r=[a,b,c,d]\) and a translation \(t=[\Delta x,\Delta y,\Delta z]\). The affine transformation matrix \(M\) has the form.
if A is a matrix consisting of n points to be transformed, this could be achieved by
where A has the form
where the same subscript represent the same point. The size of A should be \([4,n]\). and the same size for matrix new_A.
Note
Translation is applied after the rotation. Use createFromQuat(r, r * t / 2) to create a dual quaternion which translation is applied before rotation.
Parameters
_R— 4x4 matrix that represents rotations and translation.
createFromPitch()#
static DualQuat< _Tp > cv::DualQuat::createFromPitch(
const _Tp angle,
const _Tp d,
const Vec< _Tp, 3 > & axis,
const Vec< _Tp, 3 > & moment )
A dual quaternion is a vector in form of.
where \(\hat{\theta}\) is dual angle and \(\overline{\hat{l}}\) is dual axis:
In this representation, \(\theta\) is rotation angle and \((\hat{l},m)\) is the screw axis, d is the translation distance along the axis.
Note
Translation is applied after the rotation. Use createFromQuat(r, r * t / 2) to create a dual quaternion which translation is applied before rotation.
Parameters
angle— rotation angle.d— translation along the rotation axis.axis— rotation axis represented by quaternion with w = 0.moment— the moment of line, and it should be orthogonal to axis.
createFromQuat()#
static DualQuat< _Tp > cv::DualQuat::createFromQuat(
const Quat< _Tp > & realPart,
const Quat< _Tp > & dualPart )
create Dual Quaternion from two same type quaternions p and q. A Dual Quaternion \(\sigma\) has the form:
where p and q are defined as follows:
The p and q are the real part and dual part respectively.
See also
Parameters
realPart— a quaternion, real part of dual quaternion.dualPart— a quaternion, dual part of dual quaternion.
dqblend()#
static DualQuat< _Tp > cv::DualQuat::dqblend(
const DualQuat< _Tp > & q1,
const DualQuat< _Tp > & q2,
const _Tp t,
QuatAssumeType assumeUnit = QUAT_ASSUME_NOT_UNIT )
The method of Dual Quaternion linear Blending(DQB) is to compute a transformation between dual quaternion \(q_1\) and \(q_2\) and can be defined as:
where \(q_1\) and \(q_2\) are unit dual quaternions representing the input transformations. If you want to use DQB that works for more than two rigid transformations, see gdqblend
See also
Parameters
q1— a unit dual quaternion representing the input transformations.q2— a unit dual quaternion representing the input transformations.t— parameter \(t\in[0,1]\).assumeUnit— if QUAT_ASSUME_UNIT, this dual quaternion assume to be a unit dual quaternion and this function will save some computations.
gdqblend()#
template<int cn>
static DualQuat< _Tp > cv::DualQuat::gdqblend(
const Vec< DualQuat< _Tp >, cn > & dualquat,
InputArray weights,
QuatAssumeType assumeUnit = QUAT_ASSUME_NOT_UNIT )
The generalized Dual Quaternion linear Blending works for more than two rigid transformations. If these transformations are expressed as unit dual quaternions \(q_1,...,q_n\) with convex weights \(w = (w_1,...,w_n)\), the generalized DQB is simply.
Note
the type of weights’ element should be the same as the date type of dual quaternion inside the dualquat.
Parameters
dualquat— vector of dual quaternionsweights— vector of weights, the size of weights should be the same as dualquat, and the weights should satisfy \(\sum_0^n w_{i} = 1\) and \(w_i>0\).assumeUnit— if QUAT_ASSUME_UNIT, these dual quaternions assume to be unit quaternions and this function will save some computations.
gdqblend()#
static DualQuat< _Tp > cv::DualQuat::gdqblend(
InputArray dualquat,
InputArray weights,
QuatAssumeType assumeUnit = QUAT_ASSUME_NOT_UNIT )
The generalized Dual Quaternion linear Blending works for more than two rigid transformations. If these transformations are expressed as unit dual quaternions \(q_1,...,q_n\) with convex weights \(w = (w_1,...,w_n)\), the generalized DQB is simply.
Note
the type of weights’ element should be the same as the date type of dual quaternion inside the dualquat.
Parameters
dualquat— The dual quaternions which have 8 channels and 1 row or 1 col.weights— vector of weights, the size of weights should be the same as dualquat, and the weights should satisfy \(\sum_0^n w_{i} = 1\) and \(w_i>0\).assumeUnit— if QUAT_ASSUME_UNIT, these dual quaternions assume to be unit quaternions and this function will save some computations.
sclerp()#
static DualQuat< _Tp > cv::DualQuat::sclerp(
const DualQuat< _Tp > & q1,
const DualQuat< _Tp > & q2,
const _Tp t,
bool directChange = true,
QuatAssumeType assumeUnit = QUAT_ASSUME_NOT_UNIT )
The screw linear interpolation(ScLERP) is an extension of spherical linear interpolation of dual quaternion. If \(\sigma_1\) and \(\sigma_2\) are two dual quaternions representing the initial and final pose. The interpolation of ScLERP function can be defined as:
For example
double angle1 = CV_PI / 2;
Vec3d axis{0, 0, 1};
Vec3d t(0, 0, 3);
DualQuatd initial = DualQuatd::createFromAngleAxisTrans(angle1, axis, t);
double angle2 = CV_PI;
DualQuatd final = DualQuatd::createFromAngleAxisTrans(angle2, axis, t);
DualQuatd inter = DualQuatd::sclerp(initial, final, 0.5);
Parameters
q1— a dual quaternion represents a initial pose.q2— a dual quaternion represents a final pose.t— interpolation parameterdirectChange— if true, it always return the shortest path.assumeUnit— if QUAT_ASSUME_UNIT, this dual quaternion assume to be a unit dual quaternion and this function will save some computations.
Member Data Documentation#
CV_DUAL_QUAT_EPS#
static _Tp cv::DualQuat::CV_DUAL_QUAT_EPS = (_Tp)1.e-6
w#
_Tp cv::DualQuat::w
w_#
Tp cv::DualQuat::w
x#
_Tp cv::DualQuat::x
x_#
Tp cv::DualQuat::x
y#
_Tp cv::DualQuat::y
y_#
Tp cv::DualQuat::y
z#
_Tp cv::DualQuat::z
z_#
Tp cv::DualQuat::z
Source file#
The documentation for this class was generated from the following file:
opencv2/core/dualquaternion.hpp