RotationMatrix¶
- class RotationMatrix(*args, **kwargs)¶
Bases:
ArrayDouble2D
Implementation of a rotation matrix and operations on such kind of matrices.
The vpRotationMatrix considers the particular case of a rotation matrix.
The vpRotationMatrix class is derived from vpArray2D<double> .
The code below shows how to create a rotation matrix, set the element values and access them:
#include <visp3/core/vpRotationMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpRotationMatrix R; R[0][0] = 0; R[0][1] = 0; R[0][2] = -1; R[1][0] = 0; R[1][1] = -1; R[1][2] = 0; R[2][0] = -1; R[2][1] = 0; R[2][2] = 0; std::cout << "R:" << std::endl; for (unsigned int i = 0; i < R.getRows(); ++i) { for (unsigned int j = 0; j < R.getCols(); ++j) { std::cout << R[i][j] << " "; } std::cout << std::endl; } }
Once build, this previous code produces the following output:
R: 0 0 -1 0 -1 0 -1 0 0
You can also use operator<< to initialize a rotation matrix as previously:
#include <visp3/core/vpRotationMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpRotationMatrix R; R << 0, 0, -1, 0, -1, 0, -1, 0, 0; std::cout << "R:\n" << R << std::endl; }
If ViSP is build with c++11 enabled, you can do the same using:
#include <visp3/code/vpRotationMatrix.h #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpRotationMatrix R{ 0, 0, -1, 0, -1, 0, -1, 0, 0 }; std::cout << "R:\n" << R << std::endl; }
Overloaded function.
__init__(self: visp._visp.core.RotationMatrix) -> None
Default constructor that initialise a 3-by-3 rotation matrix to identity.
__init__(self: visp._visp.core.RotationMatrix, R: visp._visp.core.RotationMatrix) -> None
Copy constructor that construct a 3-by-3 rotation matrix from another rotation matrix.
__init__(self: visp._visp.core.RotationMatrix, M: visp._visp.core.HomogeneousMatrix) -> None
__init__(self: visp._visp.core.RotationMatrix, r: visp._visp.core.ThetaUVector) -> None
__init__(self: visp._visp.core.RotationMatrix, p: visp._visp.core.PoseVector) -> None
__init__(self: visp._visp.core.RotationMatrix, r: visp._visp.core.RzyzVector) -> None
__init__(self: visp._visp.core.RotationMatrix, r: visp._visp.core.RxyzVector) -> None
__init__(self: visp._visp.core.RotationMatrix, r: visp._visp.core.RzyxVector) -> None
__init__(self: visp._visp.core.RotationMatrix, q: visp._visp.core.QuaternionVector) -> None
__init__(self: visp._visp.core.RotationMatrix, R: visp._visp.core.Matrix) -> None
__init__(self: visp._visp.core.RotationMatrix, tux: float, tuy: float, tuz: float) -> None
Construct a 3-by-3 rotation matrix from \(\theta {\bf u}=(\theta u_x, \theta u_y, \theta u_z)^T\) angle representation.
__init__(self: visp._visp.core.RotationMatrix, list: std::initializer_list<double>) -> None
__init__(self: visp._visp.core.RotationMatrix, np_array: numpy.ndarray[numpy.float64]) -> None
Construct a rotation matrix by copying a 2D numpy array. This numpy array should be of dimensions \(3 \times 3\) and be a valid rotation matrix. If it is not a rotation matrix, an exception will be raised.
- Parameters:
- np_array
The numpy 1D array to copy.
Methods
Overloaded function.
Overloaded function.
Initialize the rotation matrix as identity.
The following example shows how to use this function:
Return the \(\theta {\bf u}\) vector that corresponds to the rotation matrix.
Overloaded function.
Test if the rotation matrix is really a rotation matrix.
Overloaded function.
Numpy view of the underlying array data.
Perform rotation matrix orthogonalization.
Print to std::cout the rotation matrix as a \(\theta {\bf u}\) angle representation vector.
Overloaded function.
Overloaded function.
Inherited Methods
Return the array max value.
- param m:
Second matrix;
Overloaded function.
Insert array B in array A at the given position.
Return the number of rows of the 2D array.
Overloaded function.
Overloaded function.
Save an array in a YAML-formatted file.
Return the array min value.
Return the number of columns of the 2D array.
Return the number of elements of the 2D array.
Operators
__doc__
Overloaded function.
Operator that allows to multiply all the elements of a rotation matrix by a scalar.
Overloaded function.
__module__
Overloaded function.
Attributes
__annotations__
- __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.RotationMatrix, arg0: tuple[int, int]) -> float
__getitem__(self: visp._visp.core.RotationMatrix, arg0: int) -> numpy.ndarray[numpy.float64]
__getitem__(self: visp._visp.core.RotationMatrix, arg0: slice) -> numpy.ndarray[numpy.float64]
__getitem__(self: visp._visp.core.RotationMatrix, arg0: tuple) -> numpy.ndarray[numpy.float64]
- __imul__(self, x: float) visp._visp.core.RotationMatrix ¶
Operator that allows to multiply all the elements of a rotation matrix by a scalar.
- __init__(*args, **kwargs)¶
Overloaded function.
__init__(self: visp._visp.core.RotationMatrix) -> None
Default constructor that initialise a 3-by-3 rotation matrix to identity.
__init__(self: visp._visp.core.RotationMatrix, R: visp._visp.core.RotationMatrix) -> None
Copy constructor that construct a 3-by-3 rotation matrix from another rotation matrix.
__init__(self: visp._visp.core.RotationMatrix, M: visp._visp.core.HomogeneousMatrix) -> None
__init__(self: visp._visp.core.RotationMatrix, r: visp._visp.core.ThetaUVector) -> None
__init__(self: visp._visp.core.RotationMatrix, p: visp._visp.core.PoseVector) -> None
__init__(self: visp._visp.core.RotationMatrix, r: visp._visp.core.RzyzVector) -> None
__init__(self: visp._visp.core.RotationMatrix, r: visp._visp.core.RxyzVector) -> None
__init__(self: visp._visp.core.RotationMatrix, r: visp._visp.core.RzyxVector) -> None
__init__(self: visp._visp.core.RotationMatrix, q: visp._visp.core.QuaternionVector) -> None
__init__(self: visp._visp.core.RotationMatrix, R: visp._visp.core.Matrix) -> None
__init__(self: visp._visp.core.RotationMatrix, tux: float, tuy: float, tuz: float) -> None
Construct a 3-by-3 rotation matrix from \(\theta {\bf u}=(\theta u_x, \theta u_y, \theta u_z)^T\) angle representation.
__init__(self: visp._visp.core.RotationMatrix, list: std::initializer_list<double>) -> None
__init__(self: visp._visp.core.RotationMatrix, np_array: numpy.ndarray[numpy.float64]) -> None
Construct a rotation matrix by copying a 2D numpy array. This numpy array should be of dimensions \(3 \times 3\) and be a valid rotation matrix. If it is not a rotation matrix, an exception will be raised.
- Parameters:
- np_array
The numpy 1D array to copy.
- __mul__(*args, **kwargs)¶
Overloaded function.
__mul__(self: visp._visp.core.RotationMatrix, tv: visp._visp.core.TranslationVector) -> visp._visp.core.TranslationVector
Multiply a rotation matrix by a translation vector and return the resulting translation vector.
__mul__(self: visp._visp.core.RotationMatrix, R: visp._visp.core.RotationMatrix) -> visp._visp.core.RotationMatrix
Compute the product between two rotation matrices.
__mul__(self: visp._visp.core.RotationMatrix, M: visp._visp.core.HomogeneousMatrix) -> visp._visp.core.HomogeneousMatrix
Operator that allows to multiply a rotation matrix by a homogeneous matrix.
The following snippet shows how to use this method:
vpRotationMatrix c1_R_c2; vpHomogeneousMatrix c2_M_c3; vpHomogeneousMatrix c1_M_c3 = c1_R_c2 * c2_M_c3;
- Parameters:
- M
Homogeneous matrix.
- Returns:
The product between the rotation matrix and the homogeneous matrix M .
__mul__(self: visp._visp.core.RotationMatrix, M: visp._visp.core.Matrix) -> visp._visp.core.Matrix
Operator that allows to multiply a rotation matrix by a 3-by-3 matrix. Allows for example to multiply a rotation matrix by a skew matrix.
The following snippet shows how to use this method:
vpRotationMatrix R; vpTranslationVector t; vpMatrix M = t.skew(); vpMatrix RM = R * M;
- Parameters:
- M
3-by-3 matrix.
- Returns:
The product between the rotation matrix and the 3-by-3 matrix M .
__mul__(self: visp._visp.core.RotationMatrix, v: visp._visp.core.ColVector) -> visp._visp.core.ColVector
Operator that allows to multiply a rotation matrix by a 3 dimension column vector.
The code below shows how to use this operator.
#include <visp3/core/vpColVector.h> #include <visp3/core/vpRotationMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpColVector p1(3), p2(3); vpRotationMatrix R; p2 = R * p1; return 0; }
- Parameters:
- v
Three dimension column vector.
- Returns:
The product of the rotation matrix by the column vector
__mul__(self: visp._visp.core.RotationMatrix, x: float) -> visp._visp.core.RotationMatrix
Operator that allows to multiply all the elements of a rotation matrix by a scalar.
- __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.
- buildFrom(*args, **kwargs)¶
Overloaded function.
buildFrom(self: visp._visp.core.RotationMatrix, M: visp._visp.core.HomogeneousMatrix) -> visp._visp.core.RotationMatrix
Build a rotation matrix from an homogeneous matrix.
buildFrom(self: visp._visp.core.RotationMatrix, v: visp._visp.core.ThetaUVector) -> visp._visp.core.RotationMatrix
Transform a \(\theta {\bf u}\) angle representation into a rotation matrix.
The rotation is computed using :
\[R = \cos{ \theta} \; {I}_{3} + (1 - \cos{ \theta}) \; u u^{T} + \sin{ \theta} \; [u]_\times \]buildFrom(self: visp._visp.core.RotationMatrix, p: visp._visp.core.PoseVector) -> visp._visp.core.RotationMatrix
Build a rotation matrix from a pose vector.
Note
See buildFrom(const vpThetaUVector &)
buildFrom(self: visp._visp.core.RotationMatrix, v: visp._visp.core.RzyzVector) -> visp._visp.core.RotationMatrix
Transform a vector representing the Euler angle into a rotation matrix. Rzyz( \(\phi, \theta , \psi\) ) = Rot( \(z,\phi\) ) Rot( \(y,\theta\) ) Rot( \(z,\psi\) )
buildFrom(self: visp._visp.core.RotationMatrix, v: visp._visp.core.RxyzVector) -> visp._visp.core.RotationMatrix
Transform a vector representing the Rxyz angle into a rotation matrix. Rxyz( \(\phi,\theta, \psi\) ) = Rot( \(x, \psi\) ) Rot( \(y, \theta\) ) Rot( \(z,\phi\) )
buildFrom(self: visp._visp.core.RotationMatrix, v: visp._visp.core.RzyxVector) -> visp._visp.core.RotationMatrix
Transform a vector representing the Rzyx angle into a rotation matrix. Rxyz( \(\phi, \theta , \psi\) ) = Rot( \(z, \psi\) ) Rot( \(y, \theta\) )Rot( \(x, \phi\) )
buildFrom(self: visp._visp.core.RotationMatrix, q: visp._visp.core.QuaternionVector) -> visp._visp.core.RotationMatrix
Construct a 3-by-3 rotation matrix from a quaternion representation.
buildFrom(self: visp._visp.core.RotationMatrix, tux: float, tuy: float, tuz: float) -> visp._visp.core.RotationMatrix
Construct a 3-by-3 rotation matrix from \(\theta {\bf u}=(\theta u_x, \theta u_y, \theta u_z)^T\) angle representation.
- 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 0x7f122fb6a440>>
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 0x7f122fb8c0a0>>
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”.
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 0x7f122fb6a440>>
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 0x7f122fb8c0a0>>
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”.
- getCol(self, j: int) visp._visp.core.ColVector ¶
The following example shows how to use this function:
#include <visp3/core/vpColVector.h> #include <visp3/core/vpRotationMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpRotationMatrix R; vpColVector r = R.getCol(2); std::cout << "Last column: \n" << r << std::endl; }
It produces the following output:
Last column: 0 0 1
- getThetaUVector(self) visp._visp.core.ThetaUVector ¶
Return the \(\theta {\bf u}\) vector that corresponds to the rotation matrix.
- 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(*args, **kwargs)¶
Overloaded function.
inverse(self: visp._visp.core.RotationMatrix) -> visp._visp.core.RotationMatrix
Return the rotation matrix inverse which is also the transpose of the rotation matrix.
Note
See t()
inverse(self: visp._visp.core.RotationMatrix, R: visp._visp.core.RotationMatrix) -> None
Inverse the rotation matrix.
#include <visp3/core/vpRotationMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpRotationMatrix R, Rinv; // ... Update rotation matrix R // Compute the inverse in Rinv R.inverse(Rinv); }
- Parameters:
- R
(output): Inverted rotation matrix.
- isARotationMatrix(self, threshold: float = 1e-6) bool ¶
Test if the rotation matrix is really a rotation matrix.
- Returns:
true if the matrix is a rotation matrix, false otherwise.
- static mean(*args, **kwargs)¶
Overloaded function.
mean(vec_M: list[visp._visp.core.HomogeneousMatrix]) -> visp._visp.core.RotationMatrix
Compute the Euclidean mean of the rotation matrices extracted from a vector of homogeneous matrices following Moakher’s method (SIAM 2002).
Note
See vpTranslationVector::mean()
- Parameters:
- vec_M
Set of homogeneous matrices.
- Returns:
The Euclidean mean of the rotation matrices.
mean(vec_R: list[visp._visp.core.RotationMatrix]) -> visp._visp.core.RotationMatrix
Compute the Euclidean mean of the rotation matrices following Moakher’s method (SIAM 2002).
Note
See vpTranslationVector::mean()
- Parameters:
- vec_R
Set of rotation matrices.
- Returns:
The Euclidean mean of the rotation matrices.
- numpy(self) numpy.ndarray[numpy.float64] ¶
Numpy view of the underlying array data. This numpy view cannot be modified. If you try to modify the array, an exception will be raised.
- printVector(self) None ¶
Print to std::cout the rotation matrix as a \(\theta {\bf u}\) angle representation vector.
- resize(*args, **kwargs)¶
Overloaded function.
resize(self: visp._visp.core.RotationMatrix, nrows: int, ncols: int, flagNullify: bool = true) -> None
This function is not applicable to a rotation matrix that is always a 3-by-3 matrix.
resize(self: visp._visp.core.ArrayDouble2D, 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
number of rows.
- ncols
number of column.
- flagNullify
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_
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.
- t(*args, **kwargs)¶
Overloaded function.
t(self: visp._visp.core.RotationMatrix) -> visp._visp.core.RotationMatrix
Return the rotation matrix transpose which is also the inverse of the rotation matrix.
Note
See inverse()
t(self: visp._visp.core.ArrayDouble2D) -> visp._visp.core.ArrayDouble2D
Compute the transpose of the array.
- Returns:
vpArray2D<Type> C = A^T
-
__hash__ =
None
¶