Introduction
A hypercube/tesseract is the 4 dimensional equivalent of a normal cube. It's made by taking a cube net, extending it to the 3rd dimension, then – using the 4th dimension – folding it into a hypercube. It's basically a cube, where each side is a cube.
To create a hypercube, you need 16 4d vectors (a vector with an x
, a y
, a z
and a w
component). These vectors are the following:
A(0, 0, 0, 0); B(1, 0, 0, 0); C(1, 0, 1, 0); D(0, 0, 1, 0); E(0, 1, 0, 0); F(1, 1, 0, 0); G(1, 1, 1, 0); H(0, 1, 1, 0);
I(0, 0, 0, 1); J(1, 0, 0, 1); K(1, 0, 1, 1); L(0, 0, 1, 1); M(0, 1, 0, 1); N(1, 1, 0, 1); O(1, 1, 1, 1); P(0, 1, 1, 1);
The hypercube has 24 faces. The following list contains all of them (every group marks a quad):
ABFE, CDHG, BCGF, DAEH, DCBA, FEHG
IJNM, KLPO, JKON, LIMP, LKJI, PMNO
ABJI, DCKL, BCKJ, DAIL, FEMN, GHPO, FGON, EHPM, EAIM, BFNJ, CGOK, HDLP
With all this information, you technically have a hypercube in code. To rotate this, you need 6 different matrices for each rotational plane, one for the YZ, XZ, XY, XW, YW and ZW planes. After you have every matrix, you need to multiply the cube's vertices with them.
The following images show the structure of each matrix:
For the rotation on the YZ plane:
For the rotation on the XZ plane:
For the rotation on the XY plane:
For the rotation on the XW plane:
For the rotation on the YW plane:
For the rotation on the ZW plane:
The rotations get applied in this order.
After all this, you have a rotated hypercube. Now you need to draw it. You should use an orthogonal projection combined with a perspective projection to send (x, y, z, w)
to (2x/(2+z), 2y/(2+z))
.
Input
Your input is 6 integers between 0 (inclusively) and 360 (exclusively). These represent the rotations in degrees on the different rotational planes of the hypercube.
Output
Your output should be a single image containing the hypercube. The display can be a rasterized image, a vector image or an ASCII art. The output image should be at least 100 * 100 pixels, and the cube needs to take up at least 50% of the screen. Any default image output format is allowed.
Test cases
0 0 0 0 0 0
0 0 0 0 0 30
30 0 0 0 0 30
0 0 0 30 30 30
45 45 45 0 0 0
45 45 45 45 45 45
Open the images in a new tab, to see them in full size.
Rules
- Default rules apply
- Standard loopholes are forbidden
- Shortest code in bytes wins