Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Matrix4f#get(Quat4f), Matrix4d#get(Quat4f) and probably Matrix4d#get(Quat4d) #6

Open
wyztix opened this issue Nov 10, 2015 · 0 comments

Comments

@wyztix
Copy link

wyztix commented Nov 10, 2015

There is an issue where Matrix4f#get(Quat4f) will returns NaN as the quaternion. The issue is related to the ww calculation that can ends up with a negative value. This situation was taken care by the if statement using a ternary operator but not by the Math.sqrt juste below, where the code passes the ww value without consideration for possible negative values.

Simply replacing Math.sqrt(ww) by Math.sqrt(Math.abs(ww)) solved the issue. Even though the get didn't return exactly the same quaternion, it returned an equivalent such as applying both quaternion to the same vector will return the same transformed vector.

To test the issue:

import javax.vecmath.Matrix4d;
import javax.vecmath.Matrix4f;
import javax.vecmath.Quat4f;
import javax.vecmath.Vector3d;
import javax.vecmath.Vector3f;

public class Test {

    public static void main(String args[]) {
        testBogus(new Quat4f(0.6464f, -0.0189f, 0.76269996f, 0.0002f));
        testBogusDouble(new Quat4f(0.6464f, -0.0189f, 0.76269996f, 0.0002f));
    }

    public static void testBogus(Quat4f q) {
        Vector3f v = new Vector3f(1,0,0);
        Quat4f qt = new Quat4f();
        Quat4f n = new Quat4f(q);
        Matrix4f pose = new Matrix4f();

        n.normalize();
        pose.set(n);
        pose.transform(v);
        pose.get(qt);

        // pose.transform returns a vector but qt is now NaN
        System.out.println(qt + " " + v);
    }

    public static void testBogusDouble(Quat4f q) {
        Vector3d v = new Vector3d(1,0,0);
        Quat4f qt = new Quat4f();
        Quat4f n = new Quat4f(q);
        Matrix4d pose = new Matrix4d();

        n.normalize();
        pose.set(n);
        pose.transform(v);
        pose.get(qt);

        // pose.transform returns a vector but qt is now NaN
        System.out.println(qt + " " + v);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant