MCPcopy Create free account
hub / github.com/MotrixLab/insactor / _axis_angle_rotation

Function _axis_angle_rotation

data/rotation_utils/conversions.py:168–195  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

166
167
168def _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
198def euler_angles_to_matrix(euler_angles: torch.Tensor, convention: str) -> torch.Tensor:

Callers 1

euler_angles_to_matrixFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected