What\'s the easiest way of doing this? I fail at math, and i found pretty complicate formulaes over the internet... im hoping if theres some simpler one?
I just need
// Assume clampTo is a new value. Obviously, don't move the sphere
closestPointBox = sphere.center.clampTo(box)
isIntersecting = sphere.center.distanceTo(closestPointBox) < sphere.radius
Everything else is just optimization.
Wow, -2. Tough crowd. Ok, here's the three.js implementation that basically says the same thing word for word. https://github.com/mrdoob/three.js/blob/dev/src/math/Box3.js
intersectsSphere: ( function () {
var closestPoint;
return function intersectsSphere( sphere ) {
if ( closestPoint === undefined ) closestPoint = new Vector3();
// Find the point on the AABB closest to the sphere center.
this.clampPoint( sphere.center, closestPoint );
// If that point is inside the sphere, the AABB and sphere intersect.
return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
};
} )(),