DeaD_EyE

rotation_matrix

Nov 4th, 2019
117
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import numpy as np
  2.  
  3.  
  4. def rotation_matrix(rx, ry, rz):
  5.     """
  6.    Not sure if the calculation is right.
  7.    """
  8.     rx, ry, rz = map(np.radians, (rx, ry, rz))
  9.     rxs, rys, rzs = np.sin((rx, ry, rz))
  10.     rxc, ryc, rzc = np.cos((rx, ry, rz))
  11.  
  12.     Rx = np.array([
  13.         (1, 0, 0),
  14.         (0, rxc, -rxs),
  15.         (0, rxs, rxc)
  16.     ])
  17.  
  18.     Ry = np.array([
  19.         (ryc, 0, rys),
  20.         (0, 1, 0),
  21.         (-rys, 0, ryc)
  22.     ])
  23.  
  24.     Rz = np.array([
  25.         (rzc, -rzs, 0),
  26.         (rzs, rzc, 0),
  27.         (0, 0, 1)
  28.     ])
  29.  
  30.     return Rz @ Ry @ Rx
  31.  
  32.  
  33. print(
  34.     np.round(
  35.         rotation_matrix(0, 0, 90),
  36.         1,
  37.     )
  38. )
RAW Paste Data