Advertisement
rasmit

Rotation generator

Feb 12th, 2024
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. from numpy import cos, sin, array
  2. from math import pi
  3.  
  4. # polar angle (down from z-axis)
  5. theta = pi/2
  6. # azimuthal angle (off the x axis)
  7. phi = pi/2
  8.  
  9. # step 1: to get the desired theta, rotate about the y-axis by theta (not sure if this is exactly what the want. if not, just use Rx)
  10. Ry = array([
  11.     [cos(theta), 0, sin(theta)],
  12.     [0, 1, 0],
  13.     [-sin(theta), 0, cos(theta)]
  14. ])
  15. # Rx = array([
  16. #     [1, 0, 0],
  17. #     [0, cos(theta), -sin(theta)],
  18. #     [0, sin(theta), cos(theta)]
  19. # ]).T
  20.  
  21. # step 2: to get the desired phi, rotate about the z-axis by phi
  22. Rz = array([
  23.     [cos(phi), -sin(phi), 0],
  24.     [sin(phi), cos(phi), 0],
  25.     [0, 0, 1],
  26. ])
  27.  
  28. # start with a vector along the positive z direction
  29. vec = array([0,0,1])
  30.  
  31. print(Rz.dot(Ry.dot(vec)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement