Last active
May 20, 2021 11:11
-
-
Save sergeyprokudin/1a0f96c1415f3133d2f8fa5f4be57af9 to your computer and use it in GitHub Desktop.
generate rotation matrices for each 3D axis given an angle
This file contains 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 get_rotation_mat(theta=np.pi, axis=0): | |
# https://en.wikipedia.org/wiki/Rotation_matrix | |
sin = np.sin(theta) | |
cos = np.cos(theta) | |
if axis==0: | |
R = np.asarray([[1, 0, 0], | |
[0, cos, -sin], | |
[0, sin, cos]]) | |
elif axis==1: | |
R = np.asarray([[cos, 0, sin], | |
[0, 1, 0], | |
[-sin, 0, cos]]) | |
elif axis==2: | |
R = np.asarray([[cos, -sin, 0], | |
[sin, cos, 0], | |
[0, 0, 1]]) | |
else: | |
raise ValueError("axis should be 0, 1 or 2!") | |
return R |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment