py3dframe.matrix#
py3dframe.matrix
module is used to manage 3D matrices.
- py3dframe.matrix.O3_project(matrix: ndarray) ndarray [source]
Project a matrix to the orthogonal group \(O(3)\) using SVD and minimisation of the frobenius norm.
The orthogonal group O(3) is the set of 3x3 orthonormal matrices with determinant equal to 1 or -1.
To project a matrix to O(3), the SVD is computed and the orthogonal matrix is obtained by:
\[\mathbf{O} = \mathbf{U} \mathbf{V}^T\]where \(\mathbf{U}\) and \(\mathbf{V}\) are the left and right singular vectors of the matrix such as:
\[\mathbf{M} = \mathbf{U} \mathbf{\Sigma} \mathbf{V}^T\]See also
function
py3dframe.matrix.is_O3()
for the check of orthonormality.function
py3dframe.matrix.SO3_project()
for the projection of a matrix to the special orthogonal group \(SO(3)\).
- Parameters:
matrix (array_like) – A 3x3 matrix to be projected.
- Returns:
The O(3) projection of the matrix.
- Return type:
numpy.ndarray
- Raises:
ValueError – If the matrix is not 3x3.
Examples
>>> import numpy >>> from py3dframe import O3_project >>> e1 = numpy.array([1, 1, 0]) >>> e2 = numpy.array([-1, 1, 0]) >>> e3 = numpy.array([0, 0, 1]) >>> matrix = numpy.column_stack((e1, e2, e3)) >>> print(O3_project(matrix)) [[ 0.70710678 -0.70710678 0. ] [ 0.70710678 0.70710678 0. ] [ 0. 0. 1. ]]
- py3dframe.matrix.SO3_project(matrix: ndarray) ndarray [source]
Project a matrix to the special orthogonal group \(SO(3)\) using SVD and minimisation of the frobenius norm.
The orthogonal group SO(3) is the set of 3x3 orthonormal matrices with determinant equal to 1.
To project a matrix to SO(3), the SVD is computed and the orthogonal matrix is obtained by:
\[\mathbf{O} = \mathbf{U} \mathbf{V}^T\]If the determinant of the orthogonal matrix is -1, the last column of the component \(\mathbf{U}\) is multiplied by -1.
where \(\mathbf{U}\) and \(\mathbf{V}\) are the left and right singular vectors of the matrix such as:
\[\mathbf{M} = \mathbf{U} \mathbf{\Sigma} \mathbf{V}^T\]See also
function
py3dframe.matrix.is_SO3()
for the check of special orthogonality.function
py3dframe.matrix.O3_project()
for the projection of a matrix to the orthogonal group \(O(3)\).
- Parameters:
matrix (array_like) – A 3x3 matrix to be projected.
- Returns:
The SO(3) projection of the matrix.
- Return type:
numpy.ndarray
- Raises:
ValueError – If the matrix is not 3x3.
Examples
>>> import numpy >>> from py3dframe import SO3_project >>> e1 = numpy.array([1, 1, 0]) >>> e2 = numpy.array([-1, 1, 0]) >>> e3 = numpy.array([0, 0, 1]) >>> matrix = numpy.column_stack((e1, e2, e3)) >>> print(SO3_project(matrix)) [[ 0.70710678 -0.70710678 0. ] [ 0.70710678 0.70710678 0. ] [ 0. 0. 1. ]]
- py3dframe.matrix.is_O3(matrix: ndarray, tolerance: float = 1e-06) bool [source]
Check if the given matrix is orthonormal (include on the orthogonal group \(O(3)\)).
A matrix is orthonormal if its transpose is equal to its inverse.
\[M^T = M^{-1}\]See also
function
py3dframe.matrix.is_SO3()
for the check of special orthogonality.function
py3dframe.matrix.O3_project()
for the projection of a matrix to the orthogonal group \(O(3)\).
- Parameters:
matrix (array_like) – The matrix with shape (3, 3).
tolerance (float, optional) – The tolerance for the comparison of the matrix with the identity matrix. Default is 1e-6.
- Returns:
True if the matrix is in the orthogonal group, False otherwise.
- Return type:
bool
- Raises:
ValueError – If the matrix is not 3x3.
Examples
>>> import numpy >>> from py3dframe.matrix import is_O3 >>> e1 = numpy.array([1, 1, 0]) >>> e2 = numpy.array([-1, 1, 0]) >>> e3 = numpy.array([0, 0, 1]) >>> matrix = numpy.column_stack((e1, e2, e3)) >>> print(is_O3(matrix)) False
>>> import numpy >>> from py3dframe.matrix import is_O3 >>> e1 = numpy.array([1, 1, 0]) / numpy.sqrt(2) >>> e2 = numpy.array([-1, 1, 0]) / numpy.sqrt(2) >>> e3 = numpy.array([0, 0, 1]) >>> matrix = numpy.column_stack((e1, e2, e3)) >>> print(is_O3(matrix)) True
>>> import numpy >>> from py3dframe.matrix import is_O3 >>> e1 = numpy.array([-1, 1, 0]) / numpy.sqrt(2) >>> e2 = numpy.array([1, 1, 0]) / numpy.sqrt(2) >>> e3 = numpy.array([0, 0, 1]) >>> matrix = numpy.column_stack((e1, e2, e3)) >>> print(is_O3(matrix)) True
>>> import numpy >>> from py3dframe.matrix import is_O3 >>> e1 = numpy.array([1, 1, 1]) / numpy.sqrt(3) >>> e2 = numpy.array([-1, 1, 0]) / numpy.sqrt(2) >>> e3 = numpy.array([0, 0, 1]) >>> matrix = numpy.column_stack((e1, e2, e3)) >>> print(is_O3(matrix)) False
- py3dframe.matrix.is_SO3(matrix: ndarray, tolerance: float = 1e-06) bool [source]
Check if the given matrix is orthonormal with determinant equal to 1 (include on the special orthogonal group \(SO(3)\)).
A matrix is orthonormal if its transpose is equal to its inverse.
\[M^T = M^{-1}\]See also
function
py3dframe.matrix.is_O3()
for the check of orthogonality.function
py3dframe.matrix.SO3_project()
for the projection of a matrix to the special orthogonal group \(SO(3)\).
- Parameters:
matrix (array_like) – The matrix with shape (3, 3).
tolerance (float, optional) – The tolerance for the comparison of the matrix with the identity matrix. Default is 1e-6.
- Returns:
True if the matrix is in the special orthogonal group, False otherwise.
- Return type:
bool
- Raises:
ValueError – If the matrix is not 3x3.
Examples
>>> import numpy >>> from py3dframe.matrix import is_O3 >>> e1 = numpy.array([1, 1, 0]) >>> e2 = numpy.array([-1, 1, 0]) >>> e3 = numpy.array([0, 0, 1]) >>> matrix = numpy.column_stack((e1, e2, e3)) >>> print(is_O3(matrix)) False
>>> import numpy >>> from py3dframe.matrix import is_O3 >>> e1 = numpy.array([1, 1, 0]) / numpy.sqrt(2) >>> e2 = numpy.array([-1, 1, 0]) / numpy.sqrt(2) >>> e3 = numpy.array([0, 0, 1]) >>> matrix = numpy.column_stack((e1, e2, e3)) >>> print(is_O3(matrix)) True
>>> import numpy >>> from py3dframe.matrix import is_O3 >>> e1 = numpy.array([-1, 1, 0]) / numpy.sqrt(2) >>> e2 = numpy.array([1, 1, 0]) / numpy.sqrt(2) >>> e3 = numpy.array([0, 0, 1]) >>> matrix = numpy.column_stack((e1, e2, e3)) >>> print(is_O3(matrix)) True
>>> import numpy >>> from py3dframe.matrix import is_O3 >>> e1 = numpy.array([1, 1, 1]) / numpy.sqrt(3) >>> e2 = numpy.array([-1, 1, 0]) / numpy.sqrt(2) >>> e3 = numpy.array([0, 0, 1]) >>> matrix = numpy.column_stack((e1, e2, e3)) >>> print(is_O3(matrix)) False