27
8
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
Why did you nuke the other post? – Rɪᴋᴇʀ – 2016-06-17T13:15:33.470
@EᴀsᴛᴇʀʟʏIʀᴋ I posted it in the chat for a last review – Bálint – 2016-06-17T13:17:25.813
@Bálint oh okay. – Rɪᴋᴇʀ – 2016-06-17T13:17:35.063
7As I've pointed out on two separate occasions in the sandbox, the description of projection for display is incomplete because it assumes that the object to be projected is 3-dimensional whereas it is in fact, obviously, 4-dimensional. – Peter Taylor – 2016-06-17T16:28:42.937
@PeterTaylor Maybe it's an orthogonal projection into 3 dimensions followed by a perspective projection into 2? :/ – beaker – 2016-06-17T17:48:03.940
@Blue The projection is not the main part of the challenge, you simply use the x and y positions of the vertex, to draw it on the screen. – Bálint – 2016-06-17T18:14:28.280
Trippy. I like the output when all the rotations are 45 degrees. – Patrick Roberts – 2016-06-17T19:54:00.943
If @Bálint confirms @beaker’s comment, I’ll vote to reopen – Lynn – 2016-06-17T22:20:32.780
@Lynn I confirm – Bálint – 2016-06-17T22:21:07.720
@Lynn & Bálint, I think it would be more challenging to require
([x,y]/z)/w
. – beaker – 2016-06-17T22:41:48.840@beaker The challenge is not about the projection – Bálint – 2016-06-17T22:43:47.497
The face
IJUM
on the second line, what'sU
? – luser droog – 2016-06-20T01:25:05.8402@luserdroog I think the 'U' must be 'N'. – beaker – 2016-06-20T02:34:40.907
Not a big deal, buf: the example XZ rotation matrix has a few lower-case thetas that look odd with all the capital ones around them. – luser droog – 2016-06-23T04:23:20.727
"basically a cube, where each side is a cube.", that describes a 3d shape. – Ashwin Gupta – 2016-06-23T15:29:57.963
@AshwinGupta no, the sides of a 3d cube are squares, i.e. 2d shapes, polygons. A cube the sides of which are cubes is an effort to somehow convey this inherently unimaginable object, relating a bit to common sense. At least you can imagine the topology by fusing cubes to the faces of a cube in 3d... – Andras Deak – 2016-06-23T16:48:44.397
@AndrasDeak ok I suppose I get what you are saying. It's just hard to conceptualize a shape since we can only understand up to 3D as humans. – Ashwin Gupta – 2016-06-23T17:04:17.453
2@Bálint Thanks for the challenge, I enjoyed it. Hopefully we'll get more answers and different approaches. :D – beaker – 2016-06-23T17:20:53.787
Okay, this may be sort of a dumb question, but what do Big-O and Theta stand for in the matrices? – R. Kap – 2016-06-24T08:27:23.210
@R.Kap the big "O" is the big theta, I just messed up the formatting where there's a small theta. They mean the angle on that plane. – Bálint – 2016-06-24T08:38:03.433
The list of faces includes
IJUM
but there is noU
vector. What is that supposed to be? – user1472751 – 2017-11-14T17:09:49.470@user1472751 fixed – Bálint – 2017-11-14T18:24:30.583