You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the following code, if the centers are equal, distSquared will be 0 and h becomes either infinity, -infinity, or NaN depending on the radii. The infinity cases resolve on the next line when multiplied by 0, but the NaN case does not (when the two spheres are identical).
Workaround is to compare equality before running the test, but I'd prefer just being able to test any two spheres without worry.
public static boolean testSphereSphere(
double aX, double aY, double aZ, double radiusSquaredA,
double bX, double bY, double bZ, double radiusSquaredB) {
double dX = bX - aX, dY = bY - aY, dZ = bZ - aZ;
double distSquared = dX * dX + dY * dY + dZ * dZ;
double h = 0.5 + (radiusSquaredA - radiusSquaredB) / (2.0 * distSquared);
double r_i = radiusSquaredA - h * h * distSquared;
return r_i >= 0.0;
}
The text was updated successfully, but these errors were encountered:
In the following code, if the centers are equal, distSquared will be 0 and h becomes either infinity, -infinity, or NaN depending on the radii. The infinity cases resolve on the next line when multiplied by 0, but the NaN case does not (when the two spheres are identical).
Workaround is to compare equality before running the test, but I'd prefer just being able to test any two spheres without worry.
The text was updated successfully, but these errors were encountered: