matthew-brett / transforms3d

3 dimensional spatial transformations
http://matthew-brett.github.io/transforms3d/
Other
467 stars 83 forks source link

quaternions.rotate_vector seems need normalized quaternion #16

Closed zhl355 closed 2 years ago

zhl355 commented 6 years ago

version: transforms3d-0.3.1

q = np.array([1 ,0 ,1, 0]) r = np.array([1,1,1])

R = trans3d.euler.quat2mat(q)

print(np.dot(R,r))

print('Using Trans3d library directly to rotate the vector') print(trans3d.quaternions.rotate_vector(r,q)) # this q is not normalized

print('Using Trans3d library directly to rotate the vector') print(trans3d.quaternions.rotate_vector(r,q/quat.norm(q))) # this q normalized

very good library

it would be better to having rotate_vector function works the same way when quaternion is not # normalized

matthew-brett commented 6 years ago

Thanks for the question. One option would be to follow Matlab, and normalize the quaternion before applying the rotation : https://uk.mathworks.com/help/aerotbx/ug/quatrotate.html . Of course, that would be less efficient for already-normalized quaternions. How about a keyword argument normalize=True, True by default, that would signal whether to apply normalization?

zhl355 commented 6 years ago

sounds great, thanks for your response!

On Mon, Nov 13, 2017 at 01:56 Matthew Brett notifications@github.com wrote:

Thanks for the question. One option would be to follow Matlab, and normalize the quaternion before applying the rotation : https://uk.mathworks.com/help/aerotbx/ug/quatrotate.html . Of course, that would be less efficient for already-normalized quaternions. How about a keyword argument normalize=True, True by default, that would signal whether to apply normalization?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/matthew-brett/transforms3d/issues/16#issuecomment-343868470, or mute the thread https://github.com/notifications/unsubscribe-auth/Ae8SOR4dv0qK2eg5lsTgFxU-ltD3UT_nks5s2BJogaJpZM4Qauzo .

matthew-brett commented 2 years ago

I added an is_normalized keyword to the function to at least point this out. Please reopen if you think this is the wrong option. I wanted to avoid changing people's output under them, by default.