MCPcopy Create free account
hub / github.com/MotrixLab/MotionDiffuse / qpow

Function qpow

text2motion/utils/quaternion.py:344–366  ·  view source on GitHub ↗

q0 : tensor of quaternions t: tensor of powers

(q0, t, dtype=torch.float)

Source from the content-addressed store, hash-verified

342
343
344def 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
369def qslerp(q0, q1, t):

Callers 1

qslerpFunction · 0.85

Calls 2

qnormalizeFunction · 0.85
toMethod · 0.80

Tested by

no test coverage detected