Last active
March 30, 2021 01:51
-
-
Save zactodd/d54941a526bcd02dfa54164bde989434 to your computer and use it in GitHub Desktop.
3d rotaion numpy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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