sphereOverlapsAabb function Physics

bool sphereOverlapsAabb(
  1. Vector3 center,
  2. double radius,
  3. Aabb3 box
)

Whether the closed ball at center of radius overlaps the AABB box.

Implementation

bool sphereOverlapsAabb(Vector3 center, double radius, Aabb3 box) {
  final cx = _clamp(center.x, box.min.x, box.max.x);
  final cy = _clamp(center.y, box.min.y, box.max.y);
  final cz = _clamp(center.z, box.min.z, box.max.z);
  final dx = center.x - cx;
  final dy = center.y - cy;
  final dz = center.z - cz;
  return dx * dx + dy * dy + dz * dz <= radius * radius;
}