JOML-CI / JOML

A Java math library for OpenGL rendering calculations
MIT License
728 stars 104 forks source link

Intersectionf.intersectSphereSphere working ok? #304

Closed princec closed 2 years ago

princec commented 2 years ago

This code snippet illustrates something weird behind intersectSphereSphere in JOML1.10.1 (haven't checked other versions).

    @Test
    void test() {
        var a = new Vector3f(337, 1612, 71);
        var ar = 8.55963316971002f;
        var b = new Vector3f(328.10107f, 1608.3077f, 70.125f);
        var br = 4.0f;

        System.out.println(a.distance(b));

        var dest = new Vector4f();
        System.out.println(Intersectionf.intersectSphereSphere(a, ar * ar, b, br * br, dest));
    }

There are two spheres there, which are clearly colliding when we check a.distance(b), the result being 9.67 which is less than the combined radii of the two spheres of 12.56.

However, intersectSphereSphere returns false.

The neither sphere in this case is fully enveloping the other; it is a clear case of a straightforward intersection: image

httpdigest commented 2 years ago

Hey @princec, Thanks for the report! And sorry about that. There was indeed a small error in the code. I even mentioned the source of the implementation but failed to type it off correctly. :/ It is now fixed in 1.10.4-SNAPSHOT. Please use that if you can, for the time being.

princec commented 2 years ago

Thanks ever so much Kai!