code: def quat2mat(quaternion):
      
      q = np.array(quaternion, dtype=np.float32, copy=True)[[3, 0, 1, 2]]
      n = np.dot(q, q)
      if n < EPS:
          return np.identity(3)
      q *= math.sqrt(2.0 / n)
      q = np.outer(q, q)
      return np.array(
          [
              [1.0 - q[2, 2] - q[3, 3], q[1, 2] - q[3, 0], q[1, 3] + q[2, 0]],
              [q[1, 2] + q[3, 0], 1.0 - q[1, 1] - q[3, 3], q[2, 3] - q[1, 0]],
              [q[1, 3] - q[2, 0], q[2, 3] + q[1, 0], 1.0 - q[1, 1] - q[2, 2]],
          ]
      )
docs: Converts given quaternion (x, y, z, w) to matrix.
  
      Args:
          quaternion: vec4 float angles
  
      Returns:
          3x3 rotation matrix