MCPcopy Index your code
hub / github.com/MotrixLab/MotionDiffuse / qrot

Function qrot

text2motion/utils/quaternion.py:54–73  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

52
53
54def 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
76def qeuler(q, order, epsilon=0, deg=True):

Callers 4

qrot_npFunction · 0.85
recover_root_rot_posFunction · 0.85
recover_from_ricFunction · 0.85
forward_kinematicsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected