fastdev.xform.warp_rotation¶
Module Contents¶
- fastdev.xform.warp_rotation.axis_angle_to_matrix(axis: jaxtyping.Float[torch.Tensor, ... 3], angle: jaxtyping.Float[torch.Tensor, ...]) jaxtyping.Float[torch.Tensor, ... 3 3] [source]¶
Converts axis angles to rotation matrices using Rodrigues formula.
- Parameters:
axis (torch.Tensor) – axis, the shape could be […, 3].
angle (torch.Tensor) – angle, the shape could be […].
- Returns:
Rotation matrices […, 3, 3].
- Return type:
torch.Tensor
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]])
- fastdev.xform.warp_rotation.euler_angles_to_matrix(euler_angles: jaxtyping.Float[torch.Tensor, ... 3], axes: _AXES = 'sxyz') jaxtyping.Float[torch.Tensor, ... 3 3] [source]¶
Converts Euler angles to rotation matrices.
- Parameters:
euler_angles (torch.Tensor) – Tensor of Euler angles with shape […, 3].
axes (str) – Axis specification string, one of 24 possible sequences (e.g., “sxyz”). If only 3 characters are provided, “s” will be prefixed.
- Returns:
Rotation matrices with shape […, 3, 3].
- Return type:
torch.Tensor
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]])
- fastdev.xform.warp_rotation.matrix_to_quaternion(rot_mat: jaxtyping.Float[torch.Tensor, ... 3 3], scalar_first: bool = True, canonical: bool = True) jaxtyping.Float[torch.Tensor, ... 4] [source]¶
Converts rotation matrices to quaternions.
- Parameters:
rot_mat (torch.Tensor) – Rotation matrices with shape […, 3, 3].
scalar_first (bool)
canonical (bool)
- Returns:
Quaternions with shape […, 4].
- Return type:
torch.Tensor
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
- fastdev.xform.warp_rotation.matrix_to_quaternion_numpy(rot_mat: jaxtyping.Float[numpy.ndarray, ... 3 3], scalar_first: bool = True, canonical: bool = True) jaxtyping.Float[numpy.ndarray, ... 4] [source]¶
Converts rotation matrices to quaternions.
- Parameters:
rot_mat (np.ndarray) – Rotation matrices with shape […, 3, 3].
scalar_first (bool)
canonical (bool)
- Returns:
Quaternions with shape […, 4].
- Return type:
np.ndarray
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)