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

Function expmap_to_quaternion

text2motion/utils/quaternion.py:214–230  ·  view source on GitHub ↗

Convert axis-angle rotations (aka exponential maps) to quaternions. Stable formula from "Practical Parameterization of Rotations Using the Exponential Map". Expects a tensor of shape (*, 3), where * denotes any number of dimensions. Returns a tensor of shape (*, 4).

(e)

Source from the content-addressed store, hash-verified

212
213
214def expmap_to_quaternion(e):
215 """
216 Convert axis-angle rotations (aka exponential maps) to quaternions.
217 Stable formula from "Practical Parameterization of Rotations Using the Exponential Map".
218 Expects a tensor of shape (*, 3), where * denotes any number of dimensions.
219 Returns a tensor of shape (*, 4).
220 """
221 assert e.shape[-1] == 3
222
223 original_shape = list(e.shape)
224 original_shape[-1] = 4
225 e = e.reshape(-1, 3)
226
227 theta = np.linalg.norm(e, axis=1).reshape(-1, 1)
228 w = np.cos(0.5 * theta).reshape(-1, 1)
229 xyz = 0.5 * np.sinc(0.5 * theta / np.pi) * e
230 return np.concatenate((w, xyz), axis=1).reshape(original_shape)
231
232
233def euler_to_quaternion(e, order):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected