r"""Returns a 4x4 rotation matrix that performs a rotation around axis by angle Parameters ---------- angle : float Angle to rotate by axis: np.ndarray Axis to rotate about Returns ------- torch.Tensor 3x3 rotation matrix
(angle: float, axis: np.ndarray)
| 3 | |
| 4 | |
| 5 | def angle_axis(angle: float, axis: np.ndarray): |
| 6 | r"""Returns a 4x4 rotation matrix that performs a rotation around axis by angle |
| 7 | |
| 8 | Parameters |
| 9 | ---------- |
| 10 | angle : float |
| 11 | Angle to rotate by |
| 12 | axis: np.ndarray |
| 13 | Axis to rotate about |
| 14 | |
| 15 | Returns |
| 16 | ------- |
| 17 | torch.Tensor |
| 18 | 3x3 rotation matrix |
| 19 | """ |
| 20 | u = axis / np.linalg.norm(axis) |
| 21 | cosval, sinval = np.cos(angle), np.sin(angle) |
| 22 | |
| 23 | # yapf: disable |
| 24 | cross_prod_mat = np.array([[0.0, -u[2], u[1]], |
| 25 | [u[2], 0.0, -u[0]], |
| 26 | [-u[1], u[0], 0.0]]) |
| 27 | |
| 28 | R = torch.from_numpy( |
| 29 | cosval * np.eye(3) |
| 30 | + sinval * cross_prod_mat |
| 31 | + (1.0 - cosval) * np.outer(u, u) |
| 32 | ) |
| 33 | # yapf: enable |
| 34 | return R.float() |
| 35 | |
| 36 | |
| 37 | class PointcloudScale(object): |