Created
September 21, 2011 00:19
-
-
Save grodtron/1230806 to your computer and use it in GitHub Desktop.
set of functions to rotate a vector in space. main() rotates so that vector is fully along Z axis
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
#!/usr/bin/python | |
from sympy import Matrix | |
from math import sin, cos, pi, atan, sqrt | |
def degToRad(t): | |
"""docstring for degToRad""" | |
return t * (pi/180) | |
def rotateAroundX(v, theta): | |
theta = degToRad(theta) | |
r = Matrix(( | |
(1, 0, 0), | |
(0, cos(theta), -sin(theta)), | |
(0, sin(theta), cos(theta)) | |
)) | |
return r * v | |
def rotateAroundY(v, theta): | |
theta = degToRad(theta) | |
r = Matrix(( | |
(cos(theta), 0, -sin(theta)), | |
(0, 1, 0), | |
(sin(theta), 0, cos(theta)) | |
)) | |
return r * v | |
def rotateAroundZ(v, theta): | |
theta = degToRad(theta) | |
r = Matrix(( | |
(cos(theta), -sin(theta), 0), | |
(sin(theta), cos(theta), 0), | |
(0, 0, 1) | |
)) | |
return r * v | |
def main(): | |
v = Matrix((1,1,1)) | |
v = rotateAroundX(v,45) | |
print v | |
print " " | |
v = rotateAroundY(v, atan( 1.0/sqrt(2) )*180/pi ) | |
print atan( 1.0/sqrt(2) ) | |
print v | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment