Quaternion math #239
-
Hi, I've been studying the definitions of quaternion math, and I'm not sure where all came from. In particular, where did this definition of rotation come from? Is there a textbook/paper you people would suggest to understand this better? def rotate(vec: Vector3, quat: Quaternion):
"""Rotates a vector vec by a unit quaternion quat.
Args:
vec: (3,) a vector
quat: (4,) a quaternion
Returns:
ndarray(3) containing vec rotated by quat.
"""
if len(vec.shape) != 1:
raise AssertionError('vec must have no batch dimensions.')
s, u = quat[0], quat[1:]
r = 2 * (jp.dot(u, vec) * u) + (s * s - jp.dot(u, u)) * vec
r = r + 2 * s * jp.cross(u, vec)
return r |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This is a great question. I'm less familiar with textbooks in this space, maybe @cdfreeman-google can chime in. However I will say that I think transforms3d is a great repository for nicely documented, well commented code: https://matthew-brett.github.io/transforms3d/index.html For example, here is their implementation of the quaternion rotation op: https://github.com/matthew-brett/transforms3d/blob/main/transforms3d/quaternions.py#L421 |
Beta Was this translation helpful? Give feedback.
This is a great question. I'm less familiar with textbooks in this space, maybe @cdfreeman-google can chime in. However I will say that I think transforms3d is a great repository for nicely documented, well commented code:
https://matthew-brett.github.io/transforms3d/index.html
For example, here is their implementation of the quaternion rotation op:
https://github.com/matthew-brett/transforms3d/blob/main/transforms3d/quaternions.py#L421