commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rob Tompkins (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (MATH-1400) Rotation(double[][], double) constructs inverse quaternion due to bug in mat2quat
Date Wed, 12 Apr 2017 00:04:41 GMT

     [ https://issues.apache.org/jira/browse/MATH-1400?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Rob Tompkins updated MATH-1400:
-------------------------------
    Fix Version/s: 4.0

> Rotation(double[][], double) constructs inverse quaternion due to bug in mat2quat
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-1400
>                 URL: https://issues.apache.org/jira/browse/MATH-1400
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 3.6.1
>            Reporter: Robert Huitl
>             Fix For: 4.0
>
>
> Constructing a Rotation object from a rotation matrix and extracting the quaternion gives
the *inverse* of the expected quaternion.
> E.g. something like this:
> {code}
> Rotation rot = new Rotation(Array2DRowRealMatrix(matrixData).getData())
> Quaternion q = new Quaternion(rot.getQ0(), rot.getQ1(), rot.getQ2(), rot.getQ3());
> {code}
> 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):
> {code:title=Rotation.java}
> 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
> {code}
> {code:title=Quat4f.java}
> this.x = (m1.m21 - m1.m12) * ww;
> this.y = (m1.m02 - m1.m20) * ww;
> this.z = (m1.m10 - m1.m01) * ww; // <-- m10 - m01
> {code}
> 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):
> {noformat}
> [ 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)
> {noformat}
> The other constructor using mat2quat() is probably also affected although I did not verify
this.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message