pyquaternion
pyquaternion copied to clipboard
Matrix to quaternion
I found a possible conversion bug that caused by this line.
Should the w(real) be M[0, 2]-M[2, 0]
?
I use this website for verification.
[ -0.4285714, 0.2857143, 0.8571429;
0.8571429, 0.4285714, 0.2857143;
-0.2857143, 0.8571429, -0.4285714 ]
w[ 0.3780]
x [ 0.3780]
y [ 0.7559]
z [ 0.3780]
Matlab rotm2quat
gave the same answer. (positive w)
If I use M[2, 0]-M[0, 2]
, the w(real) term will be negative.
Hi HTLife
Thanks for the feedback. I can't reproduce this behaviour with pyquaternion. The matrix you provide above is not quite precise enough to satisfy pyquaternion's requirements for orthogonality, but using a very similar one derived from your desired output, I have the following:
R
array([[-0.42848504, 0.28568188, 0.85719685],
[ 0.85719685, 0.42848504, 0.28568188],
[-0.28568188, 0.85719685, -0.42848504]])
>>> q = pq.Quaternion(matrix=R)
>>> q
Quaternion(0.377993043102062, 0.377993043102062, 0.75588608804457313, 0.377993043102062)
>>> R2 = q.rotation_matrix
>>> R2
array([[-0.42848504, 0.28568188, 0.85719685],
[ 0.85719685, 0.42848504, 0.28568188],
[-0.28568188, 0.85719685, -0.42848504]])
>>> q.real
0.377993043102062
>>> q.imaginary
array([ 0.37799304, 0.75588609, 0.37799304])
>>>
Note that q
is in the form [w, x, y, z]
I get a positive w
in my output. This seems to match the output of the links you provided when run on the same matrix R
.
Could you please provide some more concrete input or the exact matrix you used that will allow me to reproduce this?
Thanks
Hi, I am also having an issue with the matrix to quaternion method, it looks the values it produces has the sign flipped for the i, j, k components.
I have verified this against quaternions produced by the Maya python 2.0 API, and the Code example on Euclidean space: http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/
for example this 4x4 matrix (columns first): [0.056706403022355786, 0.00266710458741429, 0.9983872097054282, 0.0, -0.9903460785750324, 0.12683943299448722, 0.05591084229349291, 0.0, -0.12648577086793414, -0.9919195438539943, 0.009833966390741607, 0.0, 49.89087677001953, 40.20277786254883, 99.87789154052734, 1.0]
produces this with pyquaternion: i,j,k,w = (-0.4795916919681297, 0.51485406716052, -0.4545018725888551, 0.5462096214841845) maya produces this: i,j,k,w =[0.4795917496422797, -0.5148541248130897, 0.454501952810933, 0.5462096289237796] euclidean space code produces this: i,j,k,w =(0.4795916919681298, -0.5148540671605201, 0.4545018725888552, 0.5462096214841845)
Hi,
Just wondering if there is any update on this issue? THanks.