discretize.utils.rotation_matrix_from_normals

discretize.utils.rotation_matrix_from_normals(v0, v1, tol=1e-20)[source]

Generate a 3x3 rotation matrix defining the rotation from vector v0 to v1.

This function uses Rodrigues’ rotation formula to generate the rotation matrix \(\mathbf{A}\) going from vector \(\mathbf{v_0}\) to vector \(\mathbf{v_1}\). Thus:

\[\mathbf{Av_0} = \mathbf{v_1}\]

For detailed desciption of the algorithm, see https://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula

Parameters
v0(3) numpy.ndarray

Starting orientation direction

v1(3) numpy.ndarray

Finishing orientation direction

tolfloat, optional

Numerical tolerance. If the length of the rotation axis is below this value, it is assumed to be no rotation, and an identity matrix is returned.

Returns
(3, 3) numpy.ndarray

The rotation matrix from v0 to v1.