-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
I encountered an issue when performing intersection tests with triangles where small floating-point differences lead to unexpected errors.
Triangle values to reproduce the error:
// Case that causes intersection error
__t1.a.set(0, 50.000000000000014, 50);
__t1.b.set(0, 49.999999999999986, -50);
__t1.c.set(100, 50.000000000000014, 50);
__t2.a.set(17, 50, -24.543842315673828);
__t2.b.set(18, 50, -23.144481658935547);
__t2.c.set(18, 49, -23.595157623291016);
However, if I round the floating-point values to exact integers, the issue disappears:
// Case without error
__t1.a.set(0, 50, 50);
__t1.b.set(0, 50, -50);
__t1.c.set(100, 50, 50);
__t2.a.set(17, 50, -24.543842315673828);
__t2.b.set(18, 50, -23.144481658935547);
__t2.c.set(18, 49, -23.595157623291016);
Expected Behavior:
Small floating-point differences should not cause the intersection result to be wrong if the triangles are effectively the same in real-world positioning.
Potential solution:
in src/utils.ts, function orient3D(), line 40. Round the determinate to an integer.
const det = Math.round(_matrix4.determinant());
But I'd like to know if it is the best solution and if there are any potential issues.
Thank you!
Metadata
Metadata
Assignees
Labels
No labels