Rotation Utilities

Conversion Functions

py123d.geometry.utils.rotation_utils.get_rotation_matrices_from_euler_array(euler_angles_array)[source]

Convert Euler angles to rotation matrices using Tait-Bryan ZYX convention (yaw-pitch-roll).

Parameters:

euler_angles_array (ndarray[tuple[Any, ...], dtype[float64]]) – Array of Euler angles of shape (…, 3), indexed by EulerAnglesIndex

Return type:

ndarray[tuple[Any, ...], dtype[float64]]

Returns:

Array of rotation matrices of shape (…, 3, 3)

py123d.geometry.utils.rotation_utils.get_rotation_matrix_from_euler_array(euler_angles)[source]

Convert Euler angles to rotation matrix using Tait-Bryan ZYX convention (yaw-pitch-roll).

Parameters:

euler_angles (ndarray[tuple[Any, ...], dtype[float64]]) – Euler angles of shape (3,), indexed by EulerAnglesIndex

Return type:

ndarray[tuple[Any, ...], dtype[float64]]

Returns:

Rotation matrix of shape (3, 3)

py123d.geometry.utils.rotation_utils.get_euler_array_from_rotation_matrices(rotation_matrices)[source]

Convert rotation matrices to Euler angles using Tait-Bryan ZYX convention (yaw-pitch-roll).

Parameters:

rotation_matrices (ndarray[tuple[Any, ...], dtype[float64]]) – Rotation matrices of shape (…, 3, 3)

Return type:

ndarray[tuple[Any, ...], dtype[float64]]

Returns:

Euler angles of shape (…, 3), indexed by EulerAnglesIndex

py123d.geometry.utils.rotation_utils.get_euler_array_from_rotation_matrix(rotation_matrix)[source]

Convert a rotation matrix to Euler angles using Tait-Bryan ZYX convention (yaw-pitch-roll).

Parameters:

rotation_matrix (ndarray[tuple[Any, ...], dtype[float64]]) – Rotation matrix of shape (3, 3)

Return type:

ndarray[tuple[Any, ...], dtype[float64]]

Returns:

Euler angles of shape (3,), indexed by EulerAnglesIndex

py123d.geometry.utils.rotation_utils.get_quaternion_array_from_rotation_matrices(rotation_matrices)[source]

Convert rotation matrices to quaternions.

Parameters:

rotation_matrices (ndarray[tuple[Any, ...], dtype[float64]]) – Rotation matrices of shape (…, 3, 3)

Return type:

ndarray[tuple[Any, ...], dtype[float64]]

Returns:

Quaternions of shape (…, 4), indexed by QuaternionIndex

py123d.geometry.utils.rotation_utils.get_quaternion_array_from_rotation_matrix(rotation_matrix)[source]

Convert a rotation matrix to a quaternion.

Parameters:

rotation_matrix (ndarray[tuple[Any, ...], dtype[float64]]) – Rotation matrix of shape (3, 3)

Return type:

ndarray[tuple[Any, ...], dtype[float64]]

Returns:

Quaternion of shape (4,), indexed by QuaternionIndex.

py123d.geometry.utils.rotation_utils.get_quaternion_array_from_euler_array(euler_angles)[source]

Converts array of euler angles to array of quaternions.

Parameters:

euler_angles (ndarray[tuple[Any, ...], dtype[float64]]) – Euler angles of shape (…, 3), indexed by EulerAnglesIndex

Return type:

ndarray[tuple[Any, ...], dtype[float64]]

Returns:

Quaternions of shape (…, 4), indexed by QuaternionIndex

py123d.geometry.utils.rotation_utils.get_rotation_matrices_from_quaternion_array(quaternion_array)[source]

Convert array of quaternions to array of rotation matrices.

Parameters:

quaternion_array (ndarray[tuple[Any, ...], dtype[float64]]) – Quaternions of shape (…, 4), indexed by QuaternionIndex

Return type:

ndarray[tuple[Any, ...], dtype[float64]]

Returns:

Rotation matrices of shape (…, 3, 3)

py123d.geometry.utils.rotation_utils.get_rotation_matrix_from_quaternion_array(quaternion_array)[source]

Convert a quaternion to a rotation matrix.

Parameters:

quaternion_array (ndarray[tuple[Any, ...], dtype[float64]]) – Quaternion of shape (4,), indexed by QuaternionIndex

Return type:

ndarray[tuple[Any, ...], dtype[float64]]

Returns:

Rotation matrix of shape (3, 3)

py123d.geometry.utils.rotation_utils.get_euler_array_from_quaternion_array(quaternion_array)[source]

Converts array of quaternions to array of euler angles.

Parameters:

quaternion_array (ndarray[tuple[Any, ...], dtype[float64]]) – Quaternions of shape (…, 4), indexed by QuaternionIndex

Return type:

ndarray[tuple[Any, ...], dtype[float64]]

Returns:

Euler angles of shape (…, 3), indexed by EulerAnglesIndex

Quaternion Operations

py123d.geometry.utils.rotation_utils.normalize_quaternion_array(quaternion_array)[source]

Normalizes an array of quaternions to unit length.

Parameters:

quaternion_array (ndarray[tuple[Any, ...], dtype[float64]]) – Quaternions of shape (…, 4), indexed by QuaternionIndex

Return type:

ndarray[tuple[Any, ...], dtype[float64]]

Returns:

Normalized quaternions of shape (…, 4), indexed by QuaternionIndex

py123d.geometry.utils.rotation_utils.conjugate_quaternion_array(quaternion_array)[source]

Computes the conjugate of an array of quaternions, i.e. negating the vector part.

Parameters:

quaternion_array (ndarray[tuple[Any, ...], dtype[float64]]) – Quaternions of shape (…, 4), indexed by QuaternionIndex

Return type:

ndarray[tuple[Any, ...], dtype[float64]]

Returns:

Conjugated quaternions of shape (…, 4), indexed by QuaternionIndex

py123d.geometry.utils.rotation_utils.invert_quaternion_array(quaternion_array)[source]

Computes the inverse of an array of quaternions, i.e. conjugate divided by norm squared.

Parameters:

quaternion_array (ndarray[tuple[Any, ...], dtype[float64]]) – Quaternions of shape (…, 4), indexed by QuaternionIndex

Return type:

ndarray[tuple[Any, ...], dtype[float64]]

Returns:

Inverted quaternions of shape (…, 4), indexed by QuaternionIndex

py123d.geometry.utils.rotation_utils.multiply_quaternion_arrays(q1, q2)[source]

Multiplies two arrays of quaternions.

Parameters:
Return type:

ndarray[tuple[Any, ...], dtype[float64]]

Returns:

Array of resulting quaternions after multiplication, indexed by QuaternionIndex in the last dim.

py123d.geometry.utils.rotation_utils.slerp_quaternion_arrays(q1, q2, t)[source]

Spherical linear interpolation (SLERP) between two arrays of quaternions.

Interpolates along the shortest path on the unit quaternion hypersphere with constant angular velocity.

Parameters:
Return type:

ndarray[tuple[Any, ...], dtype[float64]]

Returns:

Interpolated quaternions of shape (…, 4), indexed by QuaternionIndex.

py123d.geometry.utils.rotation_utils.nlerp_quaternion_arrays(q1, q2, t)[source]

Normalized linear interpolation (NLERP) between two arrays of quaternions.

Faster than SLERP but does not maintain constant angular velocity.

Parameters:
Return type:

ndarray[tuple[Any, ...], dtype[float64]]

Returns:

Interpolated quaternions of shape (…, 4), indexed by QuaternionIndex.

py123d.geometry.utils.rotation_utils.get_q_matrices(quaternion_array)[source]

Computes the Q matrices for an array of quaternions.

Parameters:

quaternion_array (ndarray[tuple[Any, ...], dtype[float64]]) – Quaternions of shape (…, 4), indexed by QuaternionIndex

Return type:

ndarray[tuple[Any, ...], dtype[float64]]

Returns:

Array of Q matrices of shape (…, 4, 4)

py123d.geometry.utils.rotation_utils.get_q_bar_matrices(quaternion_array)[source]

Computes the Q-bar matrices for an array of quaternions.

Parameters:

quaternion_array (ndarray[tuple[Any, ...], dtype[float64]]) – Quaternions of shape (…, 4), indexed by QuaternionIndex

Return type:

ndarray[tuple[Any, ...], dtype[float64]]

Returns:

Array of Q-bar matrices of shape (…, 4, 4)

General

py123d.geometry.utils.rotation_utils.batch_matmul(A, B)[source]

Batch matrix multiplication for arrays of matrices. # TODO: move somewhere else

Parameters:
Return type:

ndarray[tuple[Any, ...], dtype[float64]]

Returns:

Array of shape (…, M, P) resulting from batch matrix multiplication of A and B.

py123d.geometry.utils.rotation_utils.normalize_angle(angle)[source]

Normalizes an angle or array of angles to the range [-pi, pi].

Parameters:

angle (Union[float, ndarray[tuple[Any, ...], dtype[float64]]]) – Angle or array of angles in radians to normalize.

Return type:

Union[float, ndarray[tuple[Any, ...], dtype[float64]]]

Returns:

Normalized angle or array of angles.