Rendering a 2D image of a 3D rectangular cuboid

70 Views Asked by At

I'm trying to make a 2D map from data used to build a 3D scene. No perspective, just a flat view. An arbitrary series of transforms are applied to shapes, so they can be translated/rotated/scaled on any axis. I have computed their 4x4 TRS (translate/rotate/scale) matrixes, and then I drop a row/column to get a 3x3 TRS describing my object in 2D. For simple shapes, like spheres and cuboids with little rotation, I was able to draw reasonable approximations with circles and quadrilaterals (by only considering one axis of rotation).

The cuboids I'm considering are defined by an origin $(x,y,z)$ and lengths $(l,w,h)$ along each axis in a local coordinate system, which then is transformed by a TRS matrix to my world view.

I know that when a plane intersects a cuboid, we can end up with a variety of shapes, from a hexagon down to a single point, if they intersect at all. What I'm hoping for is a top down view, which I believe means that I'm looking for the n-gon with the largest perimeter when my cuboid is sliced by some plane. I'm considering trying to first, use the TRS matrix to translate the origin, then rotate and scale the dimensions from their local space into my world space. Then I get equations for the 6 planes that define their cuboid, find the lines from the intersections of those planes and my viewplane as a function of $y$, come up with an equation for the perimeter in $(x,z)$ as a function of $y$, use calculus to find $y$ that yields the maximum perimeter, and then solve those equations again with that $y$ to get all of my $(x,z)$ coords.

I think that approach would be valid, but since it involves calculus, solving dozens of equations for each object, and I will be computing thousands of objects, I'm wondering if there is an easier way to compute a top-down image of my cuboids. For special cases, like those without rotation on some axes, I can simplify my calculations, but for the general case, is it that involved to find an accurate image? Is there another way to be thinking about this raw data to get an accurate projection of it in 2D?