AMLab-Amsterdam / lie_learn

Computations involving Lie groups and harmonic analysis
MIT License
190 stars 47 forks source link

Changing Coordinates between Q -> MAT -> Q returns error off by a factor of -1 #23

Closed joeybose closed 1 year ago

joeybose commented 1 year ago

Hi,

I've noticed a peculiar error when trying to convert some quaternions to rotation matrices and then back to quaternions. Note that this doesn't always happen for all quaternions but here is an example where it does.

For example consider the following code: quat = np.asarray([-0.6677, -0.31122, -0.44055, 0.5129])

rot = change_coordinates(quat, p_from='Q', p_to='MAT') new_quat = change_coordinates(rot, p_from='MAT', p_to='Q')

The output when printed of quat and new_quat is: [-0.6677, -0.31122, -0.44055, 0.5129] ### Quat printed

[ 0.66775613, 0.31124616, 0.44058703, -0.51294312] ### New Quat printed

The arrays would be equivalent if we multiplied new_quat with a -1 factor.

tscohen commented 1 year ago

Hi Joey,

This is actually expected behaviour. The the unit quaternion q and -q both encode the same rotation. The map from quaternions to matrices maps both q and -q to the same matrix, and so the sign cannot be recovered if you go back. If you search for "quaternion double cover" you'll find more information.

joeybose commented 1 year ago

Ah I see, this makes sense. I'll close the issue.