Introduction

I've been working on making some 3D boxes fully rotatable in SVG, and I wanted to calculate the dimensions of the viewbox so the box was never clipped but there was minimal unused space. In other words I needed to work out the maximum extent of the box as it rotated. To make matter more complex, I was using a perspective view, so the (x, y) coordinates of each vertex was a function of its z-coordinate.

Example of cylinders in a box.png

Without perspective

To get a handle on the situation I started with something simpler: a box centered at the origin, rotating only around the horizontal axis with no perspective applied.