differt.geometry.rotation_matrix_along_axis

differt.geometry.rotation_matrix_along_axis#

rotation_matrix_along_axis(angle, axis)[source]#

Return a rotation matrix to rotate coordinates along a given axis.

Parameters:
Return type:

Float[Array, '3 3']

Returns:

The rotation matrix.

Examples

The following example shows how to rotate xyz coordinates along a given axis.

>>> from differt.geometry import (
...     normalize,
...     rotation_matrix_along_axis,
... )
>>>
>>> xyz = jnp.array([1.0, 1.0, 1.0])
>>> axis, _ = normalize(jnp.array([1.0, 1.0, 0.0]))
>>> rotation_matrix_along_axis(jnp.pi / 2, axis) @ xyz
Array([ 1.7071066,  0.2928931, -0.       ], dtype=float32)

In the following example, we show the importance of using a unit vector.

>>> from differt.geometry import (
...     rotation_matrix_along_axis,
... )
>>>
>>> xyz = jnp.array([1.0, 0.0, 1.0])
>>> axis = jnp.array([1.0, 0.0, 0.0])
>>> rotation_matrix_along_axis(jnp.pi, axis) @ xyz
Array([ 1.       ,  0.0000001, -1.       ], dtype=float32)
>>> axis = jnp.array([2.0, 0.0, 0.0])
>>> rotation_matrix_along_axis(jnp.pi, axis) @ xyz
Array([ 7.       ,  0.0000002, -1.       ], dtype=float32)