It is not enough to look at half-spaces; you should also consider the point of the closest approach:
Adat Notation Borrowing:
Assuming a cube aligned along the axis and giving C1 and C2 opposite angles, S is the center of the sphere, R is the radius of the sphere, and that both objects are strong:
inline float squared(float v) { return v * v; } bool doesCubeIntersectSphere(vec3 C1, vec3 C2, vec3 S, float R) { float dist_squared = R * R; if (SX < C1.X) dist_squared -= squared(SX - C1.X); else if (SX > C2.X) dist_squared -= squared(SX - C2.X); if (SY < C1.Y) dist_squared -= squared(SY - C1.Y); else if (SY > C2.Y) dist_squared -= squared(SY - C2.Y); if (SZ < C1.Z) dist_squared -= squared(SZ - C1.Z); else if (SZ > C2.Z) dist_squared -= squared(SZ - C2.Z); return dist_squared > 0; }
source share