nerfbaselines.math_utils

nerfbaselines.math_utils.quaternion_conjugate(q)[source]

Return quaternion-conjugate of quaternion q̄

nerfbaselines.math_utils.quaternion_multiply(q1, q2)[source]

Multiply two sets of quaternions.

nerfbaselines.math_utils.quaternion_to_rotation_matrix(r)[source]
nerfbaselines.math_utils.rotate_spherical_harmonics(R, y)[source]

Rotate spherical harmonics coefficients by a rotation matrix R.

nerfbaselines.math_utils.rotation_matrix_to_quaternion(R)[source]

Convert input 3x3 rotation matrix to unit quaternion.

Assuming an orthogonal 3x3 matrix ℛ rotates a vector v such that

v’ = ℛ * v,

we can also express this rotation in terms of a unit quaternion R such that

v’ = R * v * R⁻¹,

where v and v’ are now considered pure-vector quaternions. This function returns that quaternion. If rot is not orthogonal, the “closest” orthogonal matrix is used; see Notes below.

Parameters:

R ((...Nx3x3) float array) – Each 3x3 matrix represents a rotation by multiplying (from the left) a column vector to produce a rotated column vector. Note that this input may actually have ndims>3; it is just assumed that the last two dimensions have size 3, representing the matrix.

Returns:

q – Unit quaternions resulting in rotations corresponding to input rotations. Output shape is rot.shape[:-2].

Return type:

array of quaternions

Raises:

LinAlgError – If any of the eigenvalue solutions does not converge

Notes

This function uses Bar-Itzhack’s algorithm to allow for non-orthogonal matrices. [J. Guidance, Vol. 23, No. 6, p. 1085 <http://dx.doi.org/10.2514/2.4654>] This will almost certainly be quite a bit slower than simpler versions, though it will be more robust to numerical errors in the rotation matrix. Also note that the Bar-Itzhack paper uses some pretty weird conventions. The last component of the quaternion appears to represent the scalar, and the quaternion itself is conjugated relative to the convention used throughout the quaternionic module.

nerfbaselines.math_utils.wigner_D_matrix(R, ell_max: int)[source]

Build a Wigner matrix from a rotation matrix.

nerfbaselines.math_utils.winger_D_multiply_spherical_harmonics(D, y)[source]

Multiply a Wigner D matrix by a spherical harmonic coefficients.