Skip to content

Instantly share code, notes, and snippets.

@tacaswell
Created October 29, 2012 01:35
Show Gist options
  • Save tacaswell/3970893 to your computer and use it in GitHub Desktop.
Save tacaswell/3970893 to your computer and use it in GitHub Desktop.
A simple function that implements rotation by Euler angles.
import numpy as np
def euler_rot(XYZ,phi,theta,psi):
'''Returns the points XYZ rotated by the given euler angles'''
ERot = np.array([[np.cos(theta)*np.cos(psi),
-np.cos(phi)*np.sin(psi) + np.sin(phi)*np.sin(theta)*np.cos(psi),
np.sin(phi)*np.sin(psi) + np.cos(phi)*np.sin(theta)*np.cos(psi)],
[np.cos(theta)*np.sin(psi),
np.cos(phi)*np.cos(psi) + np.sin(phi)*np.sin(theta)*np.sin(psi),
-np.sin(phi)*np.cos(psi) + np.cos(phi)*np.sin(theta)*np.sin(psi)],
[-np.sin(theta),
np.sin(phi)*np.cos(theta),
np.cos(phi)*np.cos(theta)]])
return ERot.dot(XYZ)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment