QuaternionVector¶
- class QuaternionVector(*args, **kwargs)¶
Bases:
RotationVector
Implementation of a rotation vector as quaternion angle minimal representation.
Defines a quaternion and its basic operations.
The vpQuaternionVector class is derived from vpRotationVector .
A quaternion is defined by four double values: \({\bf q} = (x, y, z, w)\) .
This class allows to compute a quaternion from a rotation matrix using either vpQuaternionVector(const vpRotationMatrix &) constructor or buildFrom() method.
It also defines common operations on a quaternion such as:
multiplication (scalar and quaternion)
addition
subtraction.
You can set values accessing each element:
vpQuaternionVector q; q[0] = x q[1] = y; q[2] = z; q[3] = w;
You can also initialize the vector using operator<<(double) :
tu << x, y, z, w;
Or you can also initialize the vector from a list of doubles if ViSP is build with c++11 enabled:
tu = {x, y, z, w};
To get the values use:
double x = q[0]; double y = q[1]; double z = q[2]; double w = q[3];
or use getter:
double x = q.x(); double y = q.y(); double z = q.z(); double w = q.w();
Overloaded function.
__init__(self: visp._visp.core.QuaternionVector) -> None
Default constructor that initialize all the 4 angles to zero.
__init__(self: visp._visp.core.QuaternionVector, q: visp._visp.core.QuaternionVector) -> None
Copy constructor.
__init__(self: visp._visp.core.QuaternionVector, qx: float, qy: float, qz: float, qw: float) -> None
Constructor from doubles.
__init__(self: visp._visp.core.QuaternionVector, R: visp._visp.core.RotationMatrix) -> None
Constructs a quaternion from a rotation matrix.
- Parameters:
- R
Matrix containing a rotation.
__init__(self: visp._visp.core.QuaternionVector, tu: visp._visp.core.ThetaUVector) -> None
Constructor that initialize \(R_{xyz}=(\varphi,\theta,\psi)\) Euler angles vector from a \(\theta {\bf u}\) vector.
- Parameters:
- tu
math:theta {bf u} representation of a rotation used here as input to initialize the Euler angles.
__init__(self: visp._visp.core.QuaternionVector, q: visp._visp.core.ColVector) -> None
Constructor from a 4-dimension vector of doubles.
__init__(self: visp._visp.core.QuaternionVector, q: list[float]) -> None
Constructor from a 4-dimension vector of doubles.
Methods
Overloaded function.
Overloaded function.
Quaternion conjugate.
Compute dot product between two quaternions.
Quaternion inverse.
Compute Quaternion Linear intERPolation (LERP).
Quaternion magnitude or norm.
Compute Quaternion Normalized Linear intERPolation (NLERP).
Normalize the quaternion.
Manually change values of a quaternion.
Compute Quaternion Spherical Linear intERPolation (SLERP).
Overloaded function.
Overloaded function.
Overloaded function.
Overloaded function.
Inherited Methods
Overloaded function.
Return the number of columns of the 2D array.
Insert array B in array A at the given position.
- return:
The corresponding std::vector<double>.
Overloaded function.
Return the number of rows of the 2D array.
Return the number of elements of the 2D array.
Return the array min value.
Return the sum square of all the elements \(r_{i}\) of the rotation vector r(m).
Return the array max value.
- param m:
Second matrix;
Save an array in a YAML-formatted file.
Overloaded function.
Overloaded function.
Numpy view of the underlying array data.
Set the size of the array and initialize all the values to zero.
Operators
Quaternion addition.
__doc__
Overloaded function.
__module__
Overloaded function.
Negate operator.
Quaternion subtraction.
Division by scalar.
Attributes
__annotations__
- __add__(self, q: visp._visp.core.QuaternionVector) visp._visp.core.QuaternionVector ¶
Quaternion addition.
Adds two quaternions. Addition is component-wise.
- Parameters:
- q: visp._visp.core.QuaternionVector¶
quaternion to add.
- __eq__(*args, **kwargs)¶
Overloaded function.
__eq__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool
Equal to comparison operator of a 2D array.
__eq__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool
Equal to comparison operator of a 2D array.
__eq__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool
Equal to comparison operator of a 2D array.
- __getitem__(*args, **kwargs)¶
Overloaded function.
__getitem__(self: visp._visp.core.ArrayDouble2D, arg0: tuple[int, int]) -> float
__getitem__(self: visp._visp.core.ArrayDouble2D, arg0: int) -> numpy.ndarray[numpy.float64]
__getitem__(self: visp._visp.core.ArrayDouble2D, arg0: slice) -> numpy.ndarray[numpy.float64]
__getitem__(self: visp._visp.core.ArrayDouble2D, arg0: tuple) -> numpy.ndarray[numpy.float64]
- __init__(*args, **kwargs)¶
Overloaded function.
__init__(self: visp._visp.core.QuaternionVector) -> None
Default constructor that initialize all the 4 angles to zero.
__init__(self: visp._visp.core.QuaternionVector, q: visp._visp.core.QuaternionVector) -> None
Copy constructor.
__init__(self: visp._visp.core.QuaternionVector, qx: float, qy: float, qz: float, qw: float) -> None
Constructor from doubles.
__init__(self: visp._visp.core.QuaternionVector, R: visp._visp.core.RotationMatrix) -> None
Constructs a quaternion from a rotation matrix.
- Parameters:
- R
Matrix containing a rotation.
__init__(self: visp._visp.core.QuaternionVector, tu: visp._visp.core.ThetaUVector) -> None
Constructor that initialize \(R_{xyz}=(\varphi,\theta,\psi)\) Euler angles vector from a \(\theta {\bf u}\) vector.
- Parameters:
- tu
math:theta {bf u} representation of a rotation used here as input to initialize the Euler angles.
__init__(self: visp._visp.core.QuaternionVector, q: visp._visp.core.ColVector) -> None
Constructor from a 4-dimension vector of doubles.
__init__(self: visp._visp.core.QuaternionVector, q: list[float]) -> None
Constructor from a 4-dimension vector of doubles.
- __mul__(*args, **kwargs)¶
Overloaded function.
__mul__(self: visp._visp.core.QuaternionVector, l: float) -> visp._visp.core.QuaternionVector
Multiplication by scalar. Returns a quaternion defined by (lx,ly,lz,lw).
__mul__(self: visp._visp.core.QuaternionVector, rq: visp._visp.core.QuaternionVector) -> visp._visp.core.QuaternionVector
Multiply two quaternions.
- __ne__(*args, **kwargs)¶
Overloaded function.
__ne__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool
Not equal to comparison operator of a 2D array.
__ne__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool
Not equal to comparison operator of a 2D array.
__ne__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool
Not equal to comparison operator of a 2D array.
- __neg__(self) visp._visp.core.QuaternionVector ¶
Negate operator. Returns a quaternion defined by (-x,-y,-z-,-w).
- __sub__(self, q: visp._visp.core.QuaternionVector) visp._visp.core.QuaternionVector ¶
Quaternion subtraction.
subtracts a quaternion from another. subtraction is component-wise.
- Parameters:
- q: visp._visp.core.QuaternionVector¶
quaternion to subtract.
- __truediv__(self, l: float) visp._visp.core.QuaternionVector ¶
Division by scalar. Returns a quaternion defined by (x/l,y/l,z/l,w/l).
- buildFrom(*args, **kwargs)¶
Overloaded function.
buildFrom(self: visp._visp.core.QuaternionVector, qx: float, qy: float, qz: float, qw: float) -> visp._visp.core.QuaternionVector
Manually change values of a quaternion.
Note
See set()
- Parameters:
- qx
x quaternion parameter.
- qy
y quaternion parameter.
- qz
z quaternion parameter.
- qw
w quaternion parameter.
buildFrom(self: visp._visp.core.QuaternionVector, R: visp._visp.core.RotationMatrix) -> visp._visp.core.QuaternionVector
Constructs a quaternion from a rotation matrix.
- Parameters:
- R
Rotation matrix.
buildFrom(self: visp._visp.core.QuaternionVector, tu: visp._visp.core.ThetaUVector) -> visp._visp.core.QuaternionVector
- Parameters:
- tu
math:theta {bf u} representation of a rotation used here as input.
- Returns:
Quaternion vector.
buildFrom(self: visp._visp.core.QuaternionVector, q: visp._visp.core.ColVector) -> visp._visp.core.QuaternionVector
Construct a quaternion vector from a 4-dim vector (x,y,z,w).
buildFrom(self: visp._visp.core.QuaternionVector, q: list[float]) -> visp._visp.core.QuaternionVector
Construct a quaternion vector from a 4-dim vector (x,y,z,w).
- conjugate(self) visp._visp.core.QuaternionVector ¶
Quaternion conjugate.
- Returns:
The conjugate quaternion.
- static conv2(*args, **kwargs)¶
Overloaded function.
conv2(M: visp._visp.core.ArrayDouble2D, kernel: visp._visp.core.ArrayDouble2D, mode: str) -> visp._visp.core.ArrayDouble2D
Perform a 2D convolution similar to Matlab conv2 function: \(M \star kernel\) .
<unparsed image <doxmlparser.compound.docImageType object at 0x7ff6a36292a0>>
Note
This is a very basic implementation that does not use FFT.
- Parameters:
- M
First matrix.
- kernel
Second matrix.
- mode
Convolution mode: “full” (default), “same”, “valid”.
conv2(M: visp._visp.core.ArrayDouble2D, kernel: visp._visp.core.ArrayDouble2D, res: visp._visp.core.ArrayDouble2D, mode: str) -> None
Perform a 2D convolution similar to Matlab conv2 function: \(M \star kernel\) .
<unparsed image <doxmlparser.compound.docImageType object at 0x7ff6a362aec0>>
Note
This is a very basic implementation that does not use FFT.
- Parameters:
- M
First array.
- kernel
Second array.
- res
Result.
- mode
Convolution mode: “full” (default), “same”, “valid”.
- static dot(q0: visp._visp.core.QuaternionVector, q1: visp._visp.core.QuaternionVector) float ¶
Compute dot product between two quaternions.
- Parameters:
- q0: visp._visp.core.QuaternionVector¶
First quaternion.
- q1: visp._visp.core.QuaternionVector¶
Second quaternion.
- Returns:
The dot product between q0 and q1.
- hadamard(self, m: visp._visp.core.ArrayDouble2D) visp._visp.core.ArrayDouble2D ¶
- Parameters:
- m: visp._visp.core.ArrayDouble2D¶
Second matrix;
- Returns:
m1.hadamard(m2) The Hadamard product : \(m1 \circ m2 = (m1 \circ m2)_{i,j} = (m1)_{i,j} (m2)_{i,j}\)
- insert(*args, **kwargs)¶
Overloaded function.
insert(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D, r: int, c: int) -> None
Insert array A at the given position in the current array.
Warning
Throw vpException::dimensionError if the dimensions of the matrices do not allow the operation.
- Parameters:
- A
The array to insert.
- r
The index of the row to begin to insert data.
- c
The index of the column to begin to insert data.
insert(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D, B: visp._visp.core.ArrayDouble2D, r: int, c: int) -> visp._visp.core.ArrayDouble2D
Insert array B in array A at the given position.
Warning
Throw exception if the sizes of the arrays do not allow the insertion.
- Parameters:
- A
Main array.
- B
Array to insert.
- r
Index of the row where to add the array.
- c
Index of the column where to add the array.
- Returns:
Array with B insert in A.
- static insertStatic(A: visp._visp.core.ArrayDouble2D, B: visp._visp.core.ArrayDouble2D, C: visp._visp.core.ArrayDouble2D, r: int, c: int) None ¶
Insert array B in array A at the given position.
Warning
Throw exception if the sizes of the arrays do not allow the insertion.
- Parameters:
- A: visp._visp.core.ArrayDouble2D¶
Main array.
- B: visp._visp.core.ArrayDouble2D¶
Array to insert.
- C: visp._visp.core.ArrayDouble2D¶
Result array.
- r: int¶
Index of the row where to insert array B.
- c: int¶
Index of the column where to insert array B.
- inverse(self) visp._visp.core.QuaternionVector ¶
Quaternion inverse.
- Returns:
The inverse quaternion.
- static lerp(q0: visp._visp.core.QuaternionVector, q1: visp._visp.core.QuaternionVector, t: float) visp._visp.core.QuaternionVector ¶
Compute Quaternion Linear intERPolation (LERP). See the following references:
- Parameters:
- q0: visp._visp.core.QuaternionVector¶
Start quaternion.
- q1: visp._visp.core.QuaternionVector¶
End quaternion.
- t: float¶
Interpolation value between [0, 1].
- Returns:
The interpolated quaternion using the LERP method.
- magnitude(self) float ¶
Quaternion magnitude or norm.
- Returns:
The magnitude or norm of the quaternion.
- static nlerp(q0: visp._visp.core.QuaternionVector, q1: visp._visp.core.QuaternionVector, t: float) visp._visp.core.QuaternionVector ¶
Compute Quaternion Normalized Linear intERPolation (NLERP). See the following references:
- Parameters:
- q0: visp._visp.core.QuaternionVector¶
Start quaternion.
- q1: visp._visp.core.QuaternionVector¶
End quaternion.
- t: float¶
Interpolation value between [0, 1].
- Returns:
The interpolated quaternion using the NLERP method.
- numpy(self) numpy.ndarray[numpy.float64] ¶
Numpy view of the underlying array data. This numpy view can be used to directly modify the array.
- resize(self, nrows: int, ncols: int, flagNullify: bool = true, recopy_: bool = true) None ¶
Set the size of the array and initialize all the values to zero.
- Parameters:
- nrows: int¶
number of rows.
- ncols: int¶
number of column.
- flagNullify: bool = true¶
if true, then the array is re-initialized to 0 after resize. If false, the initial values from the common part of the array (common part between old and new version of the array) are kept. Default value is true.
- recopy_: bool = true¶
if true, will perform an explicit recopy of the old data.
- static save(*args, **kwargs)¶
Overloaded function.
save(filename: str, A: visp._visp.core.ArrayDouble2D, binary: bool = false, header: str = ) -> bool
Save a matrix to a file.
Warning : If you save the matrix as in a text file the precision is less than if you save it in a binary file.
Note
See load()
- Parameters:
- filename
Absolute file name.
- A
Array to be saved.
- binary
If true the matrix is saved in a binary file, else a text file.
- header
Optional line that will be saved at the beginning of the file.
- Returns:
Returns true if success.
save(filename: str, A: visp._visp.core.ArrayDouble2D, binary: bool = false, header: str = ) -> bool
Save a matrix to a file.
Warning : If you save the matrix as in a text file the precision is less than if you save it in a binary file.
Note
See load()
- Parameters:
- filename
Absolute file name.
- A
Array to be saved.
- binary
If true the matrix is saved in a binary file, else a text file.
- header
Optional line that will be saved at the beginning of the file.
- Returns:
Returns true if success.
save(filename: str, A: visp._visp.core.ArrayDouble2D, binary: bool = false, header: str = ) -> bool
Save a matrix to a file.
Warning : If you save the matrix as in a text file the precision is less than if you save it in a binary file.
Note
See load()
- Parameters:
- filename
Absolute file name.
- A
Array to be saved.
- binary
If true the matrix is saved in a binary file, else a text file.
- header
Optional line that will be saved at the beginning of the file.
- Returns:
Returns true if success.
- static saveYAML(filename: str, A: visp._visp.core.ArrayDouble2D, header: str =) bool ¶
Save an array in a YAML-formatted file.
Here is an example of outputs.
vpArray2D<double> M(3,4); vpArray2D::saveYAML("matrix.yml", M, "example: a YAML-formatted header"); vpArray2D::saveYAML("matrixIndent.yml", M, "example:\n - a YAML-formatted \ header\n - with inner indentation");
Content of matrix.yml:
example: a YAML-formatted header rows: 3 cols: 4 data: - [0, 0, 0, 0] - [0, 0, 0, 0] - [0, 0, 0, 0]
Content of matrixIndent.yml:
example: - a YAML-formatted header - with inner indentation rows: 3 cols: 4 data: - [0, 0, 0, 0] - [0, 0, 0, 0] - [0, 0, 0, 0]
Note
See loadYAML()
- Parameters:
- filename
absolute file name.
- A
array to be saved in the file.
- header
optional lines that will be saved at the beginning of the file. Should be YAML-formatted and will adapt to the indentation if any.
- Returns:
Returns true if success.
- static slerp(q0: visp._visp.core.QuaternionVector, q1: visp._visp.core.QuaternionVector, t: float) visp._visp.core.QuaternionVector ¶
Compute Quaternion Spherical Linear intERPolation (SLERP). See the following references:
- Parameters:
- q0: visp._visp.core.QuaternionVector¶
Start quaternion.
- q1: visp._visp.core.QuaternionVector¶
End quaternion.
- t: float¶
Interpolation value between [0, 1].
- Returns:
The interpolated quaternion using the SLERP method.
- sumSquare(self) float ¶
Return the sum square of all the elements \(r_{i}\) of the rotation vector r(m).
- Returns:
The value
\[\sum{i=0}^{m} r_i^{2}\].
- t(*args, **kwargs)¶
Overloaded function.
t(self: visp._visp.core.RotationVector) -> visp._visp.core.RowVector
Return the transpose of the rotation vector.
t(self: visp._visp.core.ArrayDouble2D) -> visp._visp.core.ArrayDouble2D
Compute the transpose of the array.
- Returns:
vpArray2D<Type> C = A^T
- w(*args, **kwargs)¶
Overloaded function.
w(self: visp._visp.core.QuaternionVector) -> float
Returns the w-component of the quaternion.
w(self: visp._visp.core.QuaternionVector) -> float
Returns a reference to the w-component of the quaternion.
- x(*args, **kwargs)¶
Overloaded function.
x(self: visp._visp.core.QuaternionVector) -> float
Returns the x-component of the quaternion.
x(self: visp._visp.core.QuaternionVector) -> float
Returns a reference to the x-component of the quaternion.
- y(*args, **kwargs)¶
Overloaded function.
y(self: visp._visp.core.QuaternionVector) -> float
Returns the y-component of the quaternion.
y(self: visp._visp.core.QuaternionVector) -> float
Returns a reference to the y-component of the quaternion.
- z(*args, **kwargs)¶
Overloaded function.
z(self: visp._visp.core.QuaternionVector) -> float
Returns the z-component of the quaternion.
z(self: visp._visp.core.QuaternionVector) -> float
Returns a reference to the z-component of the quaternion.
-
__hash__ =
None
¶