[ 
https://issues.apache.org/jira/browse/MATH-1400?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15813323#comment-15813323
 ] 

Gilles commented on MATH-1400:
------------------------------

Thanks for the thorough report.

Unfortunately, the Commons Math project is in dire need of maintainers.
For a few months, we've been (very slowly) moving some of the functionality 
over to new, smaller, components ("random number generation" was completed, 
"complex" is under way).
The "geometry" package (from the "master" branch in the source code repository) 
is another very good candidate, as it is almost self-contained (few 
dependencies on other parts of the library).

Help is most welcome.
Please join the "dev" ML of the "Commons" project for more information.

> 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
>
> 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.4#6332)

Reply via email to