def rotate_orthogonal_vector(basis, to_rotate, psi):
"""Uses Rodrigues' rotation formula to rotate the given vector v by psi around k.
If a matrix is given the operation will by applied on the last dimension.
This function assumes that the given two vectors (or matrix of vectors) are orthogonal for every voxel.
This assumption allows for some speedup in the rotation calculation.
Args:
basis: the unit vector defining the rotation axis (k)
to_rotate: the vector to rotate by the angle psi (v)
psi: the rotation angle (psi)
Returns:
vector: the rotated vector
"""
cross_product = np.cross(basis, to_rotate)
cos_psi = np.cos(psi)[..., None]
sin_psi = np.sin(psi)[..., None]
return to_rotate * cos_psi + cross_product * sin_psi
评论列表
文章目录