axis aligned solution 3D: maximum of chessboard distance transform
diagonal solution 3D: maximum of taxicab distance transform
largest inner sphere: maximum of Euclidean distance transform
*SciPy ndimage has them all^
Rotated cube:
Using the following facts:
The largest sphere that fits inside a cube has radius L/2.
The largest cube that fits inside a sphere has length r/sqrt(3).
Thresholding the distance transform of a cube returns a cube
The center of the cube must lie at least r/sqrt(3) away from any boundary. Thresholding the Euclidean distance transform EDT at this value will retain at most Volume(shrunk largest cube) = ([1-1/sqrt(3)]N)^3 = 0.0755..N^3. Updating the threshold new_max = (previous_max + current_max)/sqrt(3) and recompute the EDT. Iterate until convergence.