fastdev.xform.warp_rotation =========================== .. py:module:: fastdev.xform.warp_rotation Module Contents --------------- .. py:function:: axis_angle_to_matrix(axis: jaxtyping.Float[torch.Tensor, ... 3], angle: jaxtyping.Float[torch.Tensor, ...]) -> jaxtyping.Float[torch.Tensor, ... 3 3] Converts axis angles to rotation matrices using Rodrigues formula. :param axis: axis, the shape could be [..., 3]. :type axis: torch.Tensor :param angle: angle, the shape could be [...]. :type angle: torch.Tensor :returns: Rotation matrices [..., 3, 3]. :rtype: torch.Tensor .. rubric:: Example >>> axis = torch.tensor([1.0, 0.0, 0.0]) >>> angle = torch.tensor(0.5) >>> axis_angle_to_matrix(axis, angle) tensor([[ 1.0000, 0.0000, 0.0000], [ 0.0000, 0.8776, -0.4794], [ 0.0000, 0.4794, 0.8776]]) .. py:function:: euler_angles_to_matrix(euler_angles: jaxtyping.Float[torch.Tensor, ... 3], axes: _AXES = 'sxyz') -> jaxtyping.Float[torch.Tensor, ... 3 3] Converts Euler angles to rotation matrices. :param euler_angles: Tensor of Euler angles with shape [..., 3]. :type euler_angles: torch.Tensor :param axes: Axis specification string, one of 24 possible sequences (e.g., "sxyz"). If only 3 characters are provided, "s" will be prefixed. :type axes: str :returns: Rotation matrices with shape [..., 3, 3]. :rtype: torch.Tensor .. rubric:: Example >>> euler_angles = torch.tensor([1.0, 0.5, 2.0]) >>> euler_angles_to_matrix(euler_angles, axes="sxyz") tensor([[-0.3652, -0.6592, 0.6574], [ 0.7980, 0.1420, 0.5857], [-0.4794, 0.7385, 0.4742]]) >>> euler_angles_to_matrix(euler_angles, axes="rxyz") tensor([[-0.3652, -0.7980, 0.4794], [ 0.3234, -0.5917, -0.7385], [ 0.8729, -0.1146, 0.4742]]) .. py:function:: matrix_to_quaternion(rot_mat: jaxtyping.Float[torch.Tensor, ... 3 3], scalar_first: bool = True, canonical: bool = True) -> jaxtyping.Float[torch.Tensor, ... 4] Converts rotation matrices to quaternions. :param rot_mat: Rotation matrices with shape [..., 3, 3]. :type rot_mat: torch.Tensor :returns: Quaternions with shape [..., 4]. :rtype: torch.Tensor .. rubric:: Example >>> rot_mat = torch.tensor([[-0.2533, -0.6075, 0.7529], ... [ 0.8445, -0.5185, -0.1343], ... [ 0.4720, 0.6017, 0.6443]]) >>> matrix_to_quaternion(rot_mat) tensor([0.4671, 0.3940, 0.1503, 0.7772]) .. note:: The gradient of this function differs from the pytorch3d implementation, but it should be okay for most use cases. Ref_ .. _Ref: https://github.com/facebookresearch/pytorch3d/issues/503#issuecomment-755493515 .. py:function:: matrix_to_quaternion_numpy(rot_mat: jaxtyping.Float[numpy.ndarray, ... 3 3], scalar_first: bool = True, canonical: bool = True) -> jaxtyping.Float[numpy.ndarray, ... 4] Converts rotation matrices to quaternions. :param rot_mat: Rotation matrices with shape [..., 3, 3]. :type rot_mat: np.ndarray :returns: Quaternions with shape [..., 4]. :rtype: np.ndarray .. rubric:: Example >>> rot_mat = np.array([[ 0.45930517, -0.11985919, -0.88015485], ... [-0.4041326 , 0.85417026, -0.32721555], ... [ 0.7910219 , 0.50599104, 0.3438858 ]]) >>> matrix_to_quaternion_numpy(rot_mat) array([ 0.8150708 , 0.25556272, -0.5125865 , -0.08719288], dtype=float32)