def rotate_around_axis(coords, Q, origin='empty'):
'''Uses standard quaternion to rotate a vector. Q requires
a 4-dimensional vector. coords is the 3d location of the point.
coords can also be an N x 3 array of vectors. Happens to work
with Q as a tuple or a np array shape 4'''
if origin == 'empty':
vcV = np.cross(Q[1:], coords)
RV = np.nan_to_num(coords + vcV * (2*Q[0]) + np.cross(Q[1:],vcV)*2)
else:
coords -= origin
vcV = np.cross(Q[1:],coords)
RV = (np.nan_to_num(coords + vcV * (2*Q[0]) + np.cross(Q[1:],vcV)*2)) + origin
coords += origin #undo in-place offset
return RV
评论列表
文章目录