Rotate vector(s) v about the rotation described by quaternion(s) q. Expects a tensor of shape (*, 4) for q and a tensor of shape (*, 3) for v, where * denotes any number of dimensions. Returns a tensor of shape (*, 3).
(q, v)
| 52 | |
| 53 | |
| 54 | def qrot(q, v): |
| 55 | """ |
| 56 | Rotate vector(s) v about the rotation described by quaternion(s) q. |
| 57 | Expects a tensor of shape (*, 4) for q and a tensor of shape (*, 3) for v, |
| 58 | where * denotes any number of dimensions. |
| 59 | Returns a tensor of shape (*, 3). |
| 60 | """ |
| 61 | assert q.shape[-1] == 4 |
| 62 | assert v.shape[-1] == 3 |
| 63 | assert q.shape[:-1] == v.shape[:-1] |
| 64 | |
| 65 | original_shape = list(v.shape) |
| 66 | # print(q.shape) |
| 67 | q = q.contiguous().view(-1, 4) |
| 68 | v = v.contiguous().view(-1, 3) |
| 69 | |
| 70 | qvec = q[:, 1:] |
| 71 | uv = torch.cross(qvec, v, dim=1) |
| 72 | uuv = torch.cross(qvec, uv, dim=1) |
| 73 | return (v + 2 * (q[:, :1] * uv + uuv)).view(original_shape) |
| 74 | |
| 75 | |
| 76 | def qeuler(q, order, epsilon=0, deg=True): |
no outgoing calls
no test coverage detected