Convert rotations given as Euler angles in radians to rotation matrices. Args: euler_angles: Euler angles in radians as tensor of shape (..., 3). convention: Convention string of three uppercase letters from {"X", "Y", and "Z"}. Returns: Rotation ma
(euler_angles: torch.Tensor, convention: str)
| 196 | |
| 197 | |
| 198 | def euler_angles_to_matrix(euler_angles: torch.Tensor, convention: str) -> torch.Tensor: |
| 199 | """ |
| 200 | Convert rotations given as Euler angles in radians to rotation matrices. |
| 201 | |
| 202 | Args: |
| 203 | euler_angles: Euler angles in radians as tensor of shape (..., 3). |
| 204 | convention: Convention string of three uppercase letters from |
| 205 | {"X", "Y", and "Z"}. |
| 206 | |
| 207 | Returns: |
| 208 | Rotation matrices as tensor of shape (..., 3, 3). |
| 209 | """ |
| 210 | if euler_angles.dim() == 0 or euler_angles.shape[-1] != 3: |
| 211 | raise ValueError("Invalid input euler angles.") |
| 212 | if len(convention) != 3: |
| 213 | raise ValueError("Convention must have 3 letters.") |
| 214 | if convention[1] in (convention[0], convention[2]): |
| 215 | raise ValueError(f"Invalid convention {convention}.") |
| 216 | for letter in convention: |
| 217 | if letter not in ("X", "Y", "Z"): |
| 218 | raise ValueError(f"Invalid letter {letter} in convention string.") |
| 219 | matrices = [ |
| 220 | _axis_angle_rotation(c, e) |
| 221 | for c, e in zip(convention, torch.unbind(euler_angles, -1)) |
| 222 | ] |
| 223 | # return functools.reduce(torch.matmul, matrices) |
| 224 | return torch.matmul(torch.matmul(matrices[0], matrices[1]), matrices[2]) |
| 225 | |
| 226 | |
| 227 |
no test coverage detected