Skip to content

Instantly share code, notes, and snippets.

@zactodd
Last active March 30, 2021 01:51
Show Gist options
  • Save zactodd/d54941a526bcd02dfa54164bde989434 to your computer and use it in GitHub Desktop.
Save zactodd/d54941a526bcd02dfa54164bde989434 to your computer and use it in GitHub Desktop.
3d rotaion numpy
import numpy as np
def rotation_matrix(axis, theta):
axis = np.asarray(axis)
axis = axis / np.sqrt(np.dot(axis, axis))
a = np.cos(theta / 2.0)
b, c, d = -axis * np.sin(theta / 2.0)
aa, bb, cc, dd = a * a, b * b, c * c, d * d
bc, ad, ac, ab, bd, cd = b * c, a * d, a * c, a * b, b * d, c * d
return np.array([[aa + bb - cc - dd, 2 * (bc + ad), 2 * (bd - ac)],
[2 * (bc - ad), aa + cc - bb - dd, 2 * (cd + ab)],
[2 * (bd + ac), 2 * (cd - ab), aa + dd - bb - cc]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment