def angle_axis(self):
    """ Returns the axis and angle of a quaternion.

    The output format is np.array([x, y, z, angle]).
    """
    # If there is no rotation return rotation about x-axis with zero angle.
    if np.isclose(self.w, 1., atol=1.e-12):
      return(np.array([1., 0., 0., 0.]))

    angle = 2. * np.arccos(self.w)
    x = self.x / np.sqrt(1. - self.w * self.w)
    y = self.y / np.sqrt(1. - self.w * self.w)
    z = self.z / np.sqrt(1. - self.w * self.w)
    return np.array([x, y, z, angle])
 Returns the axis and angle of a quaternion.

    The output format is np.array([x, y, z, angle]).
    
hand_eye_calibration/python/hand_eye_calibration/quaternion.py