Spiria logo.

Animating a 4D rotating cube

October 30, 2015.

Let’s draw a 4D cube! I created the above animation using Houdini, my favorite 3D modelling package. Interestingly, Houdini does not provide any particular support for 4D models, so I had to improvise. This post explains how I did it.

Let's draw a 4D cube!

I created the above animation using Houdini, my favorite 3D modelling package. Interestingly, Houdini does not provide any particular support for 4D models, so I had to improvise. This post explains how I did it.

Modelling

A 3D cube has 2^3=8 vertices, a 4D cube has 2^4=16. So in order to create all the vertices we need, we simply need to create two cubes:

decorative

In a 3D cube, the standard way to represent how far the vertices are on the Z axis is to use perspective, that is, to take the points which are far away in the Z axis and to scale them down so they are closer to the 2D center of the screen. For a 4D cube, we can use a similar trick: to represent how far the vertices are on the 4th axis (let's call it F), take the points which are far away in the F axis and scale them down so they are closer to the 3D center of the scene. That's why I made the second 3D cube smaller in the above picture.

Now, in that picture I scaled the second cube down by some arbitrary amount, but in order to make a correct animation I need to scale it down in proportion to how far the points are along the F axis. The first step will be to give a precise 4D coordinate to each point. In Houdini, it is easy to attach extra attributes to every vertex, via an AttributeCreate node. For now, let's arbitrarily assign F=+0.5 to one cube and F=-0.5 to the other. After the rotation is complete, I'll translate the cube from around F=0.0 to around F=10.0 so that the entire cube is in front of the camera's F axis, and then I'll divide each vertex's X, Y and Z coordinate by its F coordinate in order to obtain a proper 3D point.

Next, I would like to rotate the cube in the fourth dimension. But what does "rotation" even mean, when the space has four dimentions? We're used to think of rotating around an axis, because in three dimensions, that axis is perpendicular to exactly one plane. But in 2D, rotation is well-defined even though there is no axis to rotate around, so it's clear that a generalized rotation is not going to be around a line in n-D space. Instead, rotation is really about modifying the coordinates along two perpendicular axes, and to leave all the other perpendicular axes alone. In 4D, we'll want to rotate along 2 of the 4 axes and leave the other 2 alone. Let's pick the XF plane.

Although it was easy to tell Houdini about our extra attribute F, Houdini interprets those extra attributes as data, not as extra dimensions of space. As a result, the XForm node can only be told to rotate in the XY, XZ, or YZ planes. So here's the trick: first, swap the F and Y coordinates. Then, perform the rotation in the XY plane. Finally, swap the F and Y coordinates back. Since the axes Z and F (temporarily holding the Y coordinates) were left alone by the rotation, the Z and Y coordinates will be untouched after the entire operation, exactly as would have happened with a genuine rotation in the XF plane.

Tada! With a few extra faces and bit of transparent blue paint, we now have a hypercube rotating in 4D.