KieranWynn / pyquaternion

A fully featured, pythonic library for representing and using quaternions
http://kieranwynn.github.io/pyquaternion/
MIT License
344 stars 72 forks source link

Numerical error when accessing the rotation angle in quaternion #78

Open shmpwk opened 2 years ago

shmpwk commented 2 years ago

pyquaternion version: 0.9.9, python3 version: 3.8.0

I create a quaternion object explicitly by rotation parameters. (explicitly-by-rotation-parameters). I access the rotation angle like here.

>>> import math
>>> from pyquaternion.quaternion import Quaternion 
>>> Quaternion(axis=[0.0,0.0,1.0], radians=4.0*np.pi).radians
4.440892098500626e-16

I expect that the example outcome is 0.0 (float type) but there seems to be numerical error. Is there any idea to eliminate the numerical error? Does rotation parameter have the range limit?

[Edited] This can be addressed by https://github.com/KieranWynn/pyquaternion/pull/79

shmpwk commented 2 years ago

Another example is when rotating object.

>>> Quaternion(axis=[0.0,0.0,1.0], radians=np.pi/2.0).rotate([0.5,0.5,0.0])
[-0.49999999999999983, 0.5, 0.0]

This is mainly caused by here, which multiply quaternions.