py3dframe.switch_RT_convention#
- py3dframe.switch_RT_convention(rotation: Rotation, translation: ndarray, input_convention: int | str = 0, output_convention: int | str = 0) Tuple[Rotation, ndarray] [source]#
Lets consider two frames of reference \(E\) and \(F\). Lets consider a point \(X\) whose coordinates in the frame \(E\) are \(X_E\) and in the frame \(F\) are \(X_F\). The transformation from the frame \(E\) to the frame \(F\) is defined by a rotation matrix \(R\) and a translation vector \(T\).
It exists 8 principal conventions to define the transformation between the two frames of reference.
Index
Formula
0
\(\mathbf{X}_E = \mathbf{R} \mathbf{X}_F + \mathbf{T}\)
1
\(\mathbf{X}_E = \mathbf{R} \mathbf{X}_F - \mathbf{T}\)
2
\(\mathbf{X}_E = \mathbf{R} (\mathbf{X}_F + \mathbf{T})\)
3
\(\mathbf{X}_E = \mathbf{R} (\mathbf{X}_F - \mathbf{T})\)
4
\(\mathbf{X}_F = \mathbf{R} \mathbf{X}_E + \mathbf{T}\)
5
\(\mathbf{X}_F = \mathbf{R} \mathbf{X}_E - \mathbf{T}\)
6
\(\mathbf{X}_F = \mathbf{R} (\mathbf{X}_E + \mathbf{T})\)
7
\(\mathbf{X}_F = \mathbf{R} (\mathbf{X}_E - \mathbf{T})\)
This function allows to switch between the 8 conventions.
Note
In the convention 0, the columns of the rotation matrix are the coordinates of the frame \(F\) in the frame \(E\) and the translation vector is the origin of the frame \(F\) in the frame \(E\) coordinates.
If the axes of the frame \(F\) are noted \(\vec{i}\), \(\vec{j}\) and \(\vec{k}\). In the convention 0, the rotation matrix is \(\begin{bmatrix} \vec{i} & \vec{j} & \vec{k} \end{bmatrix}\).
import numpy from py3dframe import Rotation vec_i = numpy.array([1, 1, 0]) vec_j = numpy.array([-1, 1, 0]) vec_k = numpy.array([0, 0, 1]) matrix = numpy.column_stack((vec_i, vec_j, vec_k)) R = Rotation.from_matrix(matrix)
Warning
The points \(X_E\) and \(X_F\) are 3 elements vectors with shape (3, 1) such as \(X_E = R X_F + T\) is valid. To use this point out of the package, the operation can be processed using as follows:
X_E = R.as_matrix() @ X_F + T # The shape are compatible X_E = R.apply(X_F.T).T + T # Use the transpose to get the shape (1, 3) numpy-array convention.
- Parameters:
rotation (Rotation) – The rotation of the transformation. It must be a scipy.spatial.transform.Rotation.
translation (numpy.ndarray) – The translation vector of the transformation. It must be a 3 elements vector with shape (3, 1).
input_convention (Union[int, str], optional) – The convention of the input transformation. It can be an integer between 0 and 7 or a string corresponding to the conventions. Default is 0.
output_convention (Union[int, str], optional) – The convention of the output transformation. It can be an integer between 0 and 7 or a string corresponding to the conventions. Default is 0.
- Returns:
R_out (Rotation) – The rotation of the output transformation.
T_out (numpy.ndarray) – The translation vector of the output transformation with shape (3, 1).
- Raises:
TypeError – If the input_convention or the output_convention is not an integer. If the rotation is not a scipy.spatial.transform.Rotation. If the translation vector is not a 3 elements vector.
ValueError – If the input_convention or the output_convention is not between 0 and 7. If the translation vector is not a 3 elements vector.
Examples
>>> import numpy as np >>> from py3dframe import Rotation, switch_RT_convention >>> R = numpy.array([[1, 1, 0], [-1, 1, 0], [0, 0, 1]]) >>> R = R / numpy.linalg.norm(R, axis=0) # Normalize the columns to get an orthonormal matrix >>> R = Rotation.from_matrix(R) >>> T = [3, 2, 1] >>> R_out, T_out = switch_RT_convention(R, T, 0, 2) >>> R_out.as_matrix() array([[0.70710678, 0.70710678, 0. ], [-0.70710678, 0.70710678, 0. ], [0. , 0. , 1. ]]) >>> T_out array([[3.53553391], [-0.70710678], [1. ]])