Return the rotation matrices for one of the rotations about an axis of which Euler angles describe, for each value of the angle given. Args: axis: Axis label "X" or "Y or "Z". angle: any shape tensor of Euler angles in radians Returns: Rotation matrices as
(axis: str, angle: torch.Tensor)
| 166 | |
| 167 | |
| 168 | def _axis_angle_rotation(axis: str, angle: torch.Tensor) -> torch.Tensor: |
| 169 | """ |
| 170 | Return the rotation matrices for one of the rotations about an axis |
| 171 | of which Euler angles describe, for each value of the angle given. |
| 172 | |
| 173 | Args: |
| 174 | axis: Axis label "X" or "Y or "Z". |
| 175 | angle: any shape tensor of Euler angles in radians |
| 176 | |
| 177 | Returns: |
| 178 | Rotation matrices as tensor of shape (..., 3, 3). |
| 179 | """ |
| 180 | |
| 181 | cos = torch.cos(angle) |
| 182 | sin = torch.sin(angle) |
| 183 | one = torch.ones_like(angle) |
| 184 | zero = torch.zeros_like(angle) |
| 185 | |
| 186 | if axis == "X": |
| 187 | R_flat = (one, zero, zero, zero, cos, -sin, zero, sin, cos) |
| 188 | elif axis == "Y": |
| 189 | R_flat = (cos, zero, sin, zero, one, zero, -sin, zero, cos) |
| 190 | elif axis == "Z": |
| 191 | R_flat = (cos, -sin, zero, sin, cos, zero, zero, zero, one) |
| 192 | else: |
| 193 | raise ValueError("letter must be either X, Y or Z.") |
| 194 | |
| 195 | return torch.stack(R_flat, -1).reshape(angle.shape + (3, 3)) |
| 196 | |
| 197 | |
| 198 | def euler_angles_to_matrix(euler_angles: torch.Tensor, convention: str) -> torch.Tensor: |
no outgoing calls
no test coverage detected