I really think the only way to do it is to test the width/height/depth at varying angles and find the one which results in the lowest volume, which is basically what Peter Scheutz said. That way should be fast enough.
How fast does it need to be?
How fast does it need to be?