
Type: Bug

Status: Resolved

Priority: Major

Resolution: Won't Fix

Affects Version/s: 3.6.1

Fix Version/s: 4.0

Labels:None
Constructing a Rotation object from a rotation matrix and extracting the quaternion gives the inverse of the expected quaternion.
E.g. something like this:
Rotation rot = new Rotation(Array2DRowRealMatrix(matrixData).getData()) Quaternion q = new Quaternion(rot.getQ0(), rot.getQ1(), rot.getQ2(), rot.getQ3());
results in q being the inverse of what is expected.
I tracked this down to Rotation#mat2quat(final double[][]) which seems to access the matrix elements as if they were stored transposed. E.g. compare with Quat4f#set(Matrix3f):
quat[1] = inv * (ort[1][2]  ort[2][1]);
quat[2] = inv * (ort[2][0]  ort[0][2]);
quat[3] = inv * (ort[0][1]  ort[1][0]); // < m01  m10
this.x = (m1.m21  m1.m12) * ww; this.y = (m1.m02  m1.m20) * ww; this.z = (m1.m10  m1.m01) * ww; // < m10  m01
I compared the result from Commons Math with JavaFX, JavaX Vecmath and NumPy + http://www.lfd.uci.edu/~gohlke/code/transformations.py.html. All but Commons Math agree on the result.
You can find my test program here: http://pastebin.com/jxwFi9mt
It prints the following output (Python results added manually):
[ 0.7 0.0 0.0 0.7] (Commons Math) [ 0.7 0.0 0.0 0.7] (JavaFX) [ 0.7 0.0 0.0 0.7] (JavaX Vecmath) [ 0.7 0.0 0.0 0.7] (NumPy + transformations.py) [0.2 1.0 0.0 0.0] (Commons Math) [ 0.2 1.0 0.0 0.0] (JavaFX) [ 0.2 1.0 0.0 0.0] (JavaX Vecmath) [ 0.2 1.0 0.0 0.0] (NumPy + transformations.py) [ 0.2 0.0 1.0 0.0] (Commons Math) [ 0.2 0.0 1.0 0.0] (JavaFX) [ 0.2 0.0 1.0 0.0] (JavaX Vecmath) [0.2 0.0 1.0 0.0] (NumPy + transformations.py) [0.2 0.0 0.0 1.0] (Commons Math) [ 0.2 0.0 0.0 1.0] (JavaFX) [ 0.2 0.0 0.0 1.0] (JavaX Vecmath) [ 0.2 0.0 0.0 1.0] (NumPy + transformations.py)
The other constructor using mat2quat() is probably also affected although I did not verify this.
 is related to

NUMBERS19 MATH1400
 Closed