Skip to content

Instantly share code, notes, and snippets.

@marmakoide
Last active December 13, 2022 13:21
Show Gist options
  • Save marmakoide/bb11884220e259573f52ba0d88d4a0d4 to your computer and use it in GitHub Desktop.
Save marmakoide/bb11884220e259573f52ba0d88d4a0d4 to your computer and use it in GitHub Desktop.
Computes the rotation matrix equivalent to an axis & angle rotation
import numpy
def axis_angle_to_rotation_matrix(U, theta):
cos_theta, sin_theta = numpy.cos(theta, dtype = U.dtype), numpy.sin(theta, dtype = U.dtype)
U_x = numpy.array([[0, -U[2], U[1]], [U[2], 0, -U[0]], [-U[1], U[0], 0]], dtype = U.dtype)
return cos_theta * numpy.identity(3, dtype = U.dtype) + sin_theta * U_x + (1 - cos_theta) * numpy.outer(U, U)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment