What exactly is a tesseract ?

A tesseract is just a four-dimensional cube. We can also generalize the cube in nn dimensions, in which case it is simply called a nn-hypercube. But how exactly do we generalize this idea of a cube? Let's start with dimension 00, a point. To transition to dimension 11, you transform the point into a continuum of points to get a line. To go to dimension 22, we transform this line into a continuum of lines to get a square. And to get the cube, we repeat the operation with a continuum of planes. You may have noticed that here, we were always extruding the next shape from the previous one in an orthogonal manner. So how are we supposed to extrude the cube into a tesseract ? Well, we simply need another dimension which is orthogonal to the three firsts, a fourth one. However, we live in a 3D world, so we can't really visualize what it is supposed to look like, but what we can do is project it in our 3D world in a way that show its important features and connections. For our projection, we are going to define the tesseract of size 22 by its corners:

line={1,1}square={(1,1),(1,1),(s,1),(s,1)}={1,1}×{1,1}={1,1}2cube={1,1}×{1,1}×{1,1}={1,1}3tesseract={1,1}4\begin{aligned} line &= \{-1, 1\}\\ square &= \{(-1, -1), (-1, 1), (s, -1), (s, 1)\} = \{-1, 1\} \times \{-1, 1\} = \{-1, 1\}^2\\ cube &= \{-1, 1\} \times \{-1, 1\} \times \{-1, 1\} = \{-1, 1\}^3\\ tesseract &= \{-1, 1\}^4 \end{aligned}

Here, ×\times represents the Cartesian product.

Once we have our points, we need to determine which points we connect. To do this, we only have to check the number of dimensions where 2 points' coordinates differ, if it is 1 then, it means the 2 points are connected.

Projecting the tesseract

We are going to use the following projection:

π:R4R3(x,y,z,w)λ(w)(x,y,z)λ(w)=ddw with d>max(w)\begin{aligned} \pi : \mathbb{R}^4 &\rightarrow \mathbb{R}^3\\ (x, y, z, w) &\rightarrow \lambda(w)*(x, y, z)\\ \lambda(w) = \frac{d}{d - w} &\text{ with } d > \max(w) \end{aligned}

This is actually a stereographic projection onto the canonical 3D space. Basically in this case, it just scales a point given its 4th coordonate. If a point is in the space w=0w = 0, it stays the same. If w<0w < 0, it is going to scale down. And if w>0w > 0, it is gonna scale up and approach an infinite scaling as ww approaches dd. Here, dd is a parameter of our projection, you need to take it large enough that no point's 4th coordinate would get too close to it.

Rotating the tesseract

Okay, now we have a tesseract and a way to project it into our 3D space. But it is not moving yet, for this we need to rotate it and not in our 3D space, otherwise we would just have a static projection rotating on itself.
A rotation matrix in nn-dimension is a matrix which inversed is its transposed self and have a determinant of 1. This group is called the special orthogonal group of rank n : SO(n)={M:MTM=MMT=I and M=1}SO(n) = \{M : M^TM = MM^T = I \text{ and } |M| = 1\}. Here is the matrix we are going to use:

R(α,β,t)=(Rαt0202Rβt)\begin{aligned} R(\alpha, \beta, t) = \begin{pmatrix} R_{\alpha t} & 0_2 \\ 0_2 & R_{\beta t} \end{pmatrix} \end{aligned}

Using the already known results for 2D rotations we can verify that RSO(4)R \in SO(4) given that RαtSO(2)R_{\alpha t} \in SO(2) and RβtSO(2)R_{\beta t} \in SO(2):

RT=(RαtT0202RβtT)=(Rαt0202Rβt)So, RRT=RTR=(R00202R0)=(I20202I2)\begin{aligned} R^T &= \begin{pmatrix} R_{\alpha t}^T & 0_2 \\ 0_2 & R_{\beta t}^T \end{pmatrix} = \begin{pmatrix} R_{-\alpha t} & 0_2 \\ 0_2 & R_{-\beta t} \end{pmatrix}\\ \text{So, } RR^T &= R^TR = \begin{pmatrix} R_{0} & 0_2 \\ 0_2 & R_{0} \end{pmatrix} = \begin{pmatrix} I_2 & 0_2 \\ 0_2 & I_2 \end{pmatrix} \end{aligned}

Also, R=RαtRβt=1|R| = |R_{\alpha t}||R_{\beta t}| = 1
α\alpha and β\beta represent, respectively, the rotation speeds for the XYXY plane and the ZWZW plane. You can also change those parameters' values with the sliders.

Final notes

You can find the (not so long) full code here.