q0 : tensor of quaternions t: tensor of powers
(q0, t, dtype=torch.float)
| 342 | |
| 343 | |
| 344 | def qpow(q0, t, dtype=torch.float): |
| 345 | ''' q0 : tensor of quaternions |
| 346 | t: tensor of powers |
| 347 | ''' |
| 348 | q0 = qnormalize(q0) |
| 349 | theta0 = torch.acos(q0[..., 0]) |
| 350 | |
| 351 | ## if theta0 is close to zero, add epsilon to avoid NaNs |
| 352 | mask = (theta0 <= 10e-10) * (theta0 >= -10e-10) |
| 353 | theta0 = (1 - mask) * theta0 + mask * 10e-10 |
| 354 | v0 = q0[..., 1:] / torch.sin(theta0).view(-1, 1) |
| 355 | |
| 356 | if isinstance(t, torch.Tensor): |
| 357 | q = torch.zeros(t.shape + q0.shape) |
| 358 | theta = t.view(-1, 1) * theta0.view(1, -1) |
| 359 | else: ## if t is a number |
| 360 | q = torch.zeros(q0.shape) |
| 361 | theta = t * theta0 |
| 362 | |
| 363 | q[..., 0] = torch.cos(theta) |
| 364 | q[..., 1:] = v0 * torch.sin(theta).unsqueeze(-1) |
| 365 | |
| 366 | return q.to(dtype) |
| 367 | |
| 368 | |
| 369 | def qslerp(q0, q1, t): |
no test coverage detected