Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. def rotate_van_dam(translation, obj, rotation_axis_dir, angle):
  2. #initial translation
  3. obj += translation
  4.  
  5. e = rotation_axis_dir/sqrt(rotation_axis_dir*rotation_axis_dir)
  6.  
  7. RxB = matrix([
  8. [1, 0, 0],
  9. [0, e[2], -e[1]/sqrt(e[1]^2 + e[2]^2)],
  10. [0, e[1], e[2]/sqrt(e[1]^2 + e[2]^2)]])
  11.  
  12. RxBn = RxB.transpose()
  13.  
  14. e_matrix = matrix([e[0], e[1], e[2]]).transpose()
  15. ee = RxB*e_matrix
  16. ee = vector([ee[0][0], ee[1][0], ee[2][0]])
  17.  
  18. RyY = matrix([
  19. [ee[2], 0, ee[0]/sqrt(ee[0]^2 + ee[2]^2)],
  20. [0, 1, 0],
  21. [-ee[0], 0, ee[2]/sqrt(ee[0]^2 + ee[2]^2)]])
  22.  
  23. RyYn = RyY.transpose()
  24.  
  25. RzA = matrix([
  26. [cos(angle), -sin(angle), 0],
  27. [sin(angle), cos(angle), 0],
  28. [0, 0, 1]])
  29.  
  30. M = matrix([obj[0], obj[1], obj[2]]).transpose()
  31.  
  32. RA = RxBn*RyY*RzA*RyYn*RxB
  33.  
  34. new_obj = RA*M
  35. new_obj = vector([new_obj[0][0], new_obj[1][0], new_obj[2][0]])
  36.  
  37. #end translation
  38. new_obj -= translation
  39.  
  40. return new_obj
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement