(quat, default_axis=VECTOR3_Z, direction_axis=None)
return axis, angle
Calculates axis and angle of rotation performed by a quaternion.

  Calculates the axis and angle of the rotation performed by the quaternion.
  The quaternion should have four values and be normalized.

  Args:
    quat: Unit quaternion in a numpy array.
    default_axis: 3D vector axis used if the rotation is near to zero. Without
      this default, small rotations would result in an exception.  It is
      reasonable to use a default axis for tiny rotations, because zero angle
      rotations about any axis are equivalent.
    direction_axis: Used to disambiguate rotation directions.  If the
      direction_axis is specified, the axis of the rotation will be chosen such
      that its inner product with the direction_axis is non-negative.

  Raises:
    ValueError: If quat is not a normalized quaternion.

  Returns:
    axis: Axis of rotation.
    angle: Angle in radians.
Calculates axis and angle of rotation performed by a quaternion.
Calculates axis and angle of rotation performed by a quaternion .
def QuaternionToAxisAngle(quat, default_axis=VECTOR3_Z, direction_axis=None):
  """Calculates axis and angle of rotation performed by a quaternion.

  Calculates the axis and angle of the rotation performed by the quaternion.
  The quaternion should have four values and be normalized.

  Args:
    quat: Unit quaternion in a numpy array.
    default_axis: 3D vector axis used if the rotation is near to zero. Without
      this default, small rotations would result in an exception.  It is
      reasonable to use a default axis for tiny rotations, because zero angle
      rotations about any axis are equivalent.
    direction_axis: Used to disambiguate rotation directions.  If the
      direction_axis is specified, the axis of the rotation will be chosen such
      that its inner product with the direction_axis is non-negative.

  Raises:
    ValueError: If quat is not a normalized quaternion.

  Returns:
    axis: Axis of rotation.
    angle: Angle in radians.
  """
  if len(quat) != 4:
    raise ValueError(
        'Quaternion should have four components [x, y, z, w]: %s' % quat)
  if not np.isclose(1.0, np.linalg.norm(quat)):
    raise ValueError('Quaternion should have unit length: |q| = %f, q = %s' %
                     (np.linalg.norm(quat), quat))
  axis = quat[:3].copy()
  axis_norm = np.linalg.norm(axis)
  min_axis_norm = 1e-8
  if axis_norm < min_axis_norm:
    axis = default_axis
    if len(default_axis) != 3:
      raise ValueError('Axis vector should have three components: %s' % axis)
    if not np.isclose(np.linalg.norm(axis), 1.0):
      raise ValueError('Axis vector should have unit length: |v| = %f, v = %s' %
                       (np.linalg.norm(axis), axis))
  else:
    axis /= axis_norm
  sin_half_angle = axis_norm
  if direction_axis is not None and np.inner(axis, direction_axis) < 0:
    sin_half_angle = -sin_half_angle
    axis = -axis
  cos_half_angle = quat[3]
  half_angle = math.atan2(sin_half_angle, cos_half_angle)
  angle = half_angle * 2
  return axis, angle
def QuaternionToAxisAngle ( quat , default_axis = VECTOR3_Z , direction_axis = None ) : if len ( quat ) != 4 : raise ValueError ( 'Quaternion should have four components [x, y, z, w]: %s' % quat ) if not np . isclose ( 1.0 , np . linalg . norm ( quat ) ) : raise ValueError ( 'Quaternion should have unit length: |q| = %f, q = %s' % ( np . linalg . norm ( quat ) , quat ) ) axis = quat [ : 3 ] . copy ( ) axis_norm = np . linalg . norm ( axis ) min_axis_norm = 1e-8 if axis_norm < min_axis_norm : axis = default_axis if len ( default_axis ) != 3 : raise ValueError ( 'Axis vector should have three components: %s' % axis ) if not np . isclose ( np . linalg . norm ( axis ) , 1.0 ) : raise ValueError ( 'Axis vector should have unit length: |v| = %f, v = %s' % ( np . linalg . norm ( axis ) , axis ) ) else : axis /= axis_norm sin_half_angle = axis_norm if direction_axis is not None and np . inner ( axis , direction_axis ) < 0 : sin_half_angle = - sin_half_angle axis = - axis cos_half_angle = quat [ 3 ] half_angle = math . atan2 ( sin_half_angle , cos_half_angle ) angle = half_angle * 2 return axis , angle