ISO Cube Plots

08 Jun 2021 ∞

A while back I bought a genuine Art Cube1 on a whim, as I'm wont to do. I knew I wanted to somehow plot on it, but didn't really have any concrete of ideas what to do with it. I wanted to do something in 3D, where the plot was continuous around the cube, however SwiftGraphics is a (mostly) 2D library, so plotting anything with continuous lines would require some cheating to make either make lines jump from one face on the net to the next or doing some complex cube projections.

While I was thinking about how I might even implement something like that I thought about other ways to visualize the cube in two dimensions. What came to mind was an isometric projection. Two isometric cubes would allow me to see both sides of the whole cube. However I didn't want to jump straight into 3D, and wanted to explore the isometric projection further, so I simplified a bit.

As with all things in SwiftGraphics I'm not just throwing lines on a canvas2, everything is driven by objects. So in this case I needed an isometric cube. Drawing the cube isn't difficult, making it smart, on the other hand, took more time. There are lots of shapes, but they're limited. A cube is made up of many faces, each defined by four vertices and a big part of being able to draw anything on the cube is knowing what cube and what face a point is on.

This is, luckily, a well trodden area and there are several options for determining whether a point is inside an arbitrary polygon. I opted for the winding number method by Dan Sunday. By far the most complex part was ensuing that a line would only draw in valid directions for a given face, and when moving to a new face would change direction correctly. I was initially going to reuse some of my ray tracing logic, unfortunately it wasn't quite compatible with what I wanted to do, for instance having lines change directions on a face, not just at boundaries.

Eventually I got the bugs worked out well enough to produce some nice looking plots. The debug view on this plot is particularly nice looking, to the point I considered just leaving it in, but eventually realized it would be too busy. I made a bunch of variations with different cube sizes and configurations. All of them are over in their gallery and for sale in the shop.

  1. It's just a wooden cube, but from an art supply store.

  2. I mean, I am.

art generative swiftgraphics swift