From aa02d6808bdfb7b7f5570523bd8bf4e1283d1f31 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Thu, 13 Feb 2020 12:09:42 +0100 Subject: [PATCH] rogueviz:: impossible triangle viz --- rogueviz/triangle.cpp | 299 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 299 insertions(+) create mode 100644 rogueviz/triangle.cpp diff --git a/rogueviz/triangle.cpp b/rogueviz/triangle.cpp new file mode 100644 index 00000000..f1cb2fd4 --- /dev/null +++ b/rogueviz/triangle.cpp @@ -0,0 +1,299 @@ +#include "../hyper.h" + +// Impossible Triangle visualization + +// used in: https://www.youtube.com/watch?v=YmFDd49WsrY + +// settings: +// ./mymake rogueviz/triangle +// ./hyper -geo Nil -canvas x -tstep 8 -nilperiod 3 3 3 + +// also used in: https://youtu.be/RPL4-Ydviug + +// ./hyper -geo Nil -nilwidth .9 -canvas x -tstep 1 -nilperiod 1 10 1 -triset 32 31 992 + +namespace hr { + +// each color group (i.e., each face direction) is a different hpcshape +hpcshape ptriangle[6]; + +EX hyperpoint lerp(hyperpoint a0, hyperpoint a1, ld x) { + return a0 + (a1-a0) * x; + } + +hyperpoint operator+(hyperpoint x) { return x; } + +// do not change this +int shape = 1; + +// how many cubes to subdivide edges to +int how = 4; + +// how many cubes to draw (should be smaller than how because they are not really cubes and thus they get into each other) +int how1 = how - 1; + +// precision: number of substeps to simulate (best if divisible by how and how1) +int isteps = 4 * 1024; + +/* make the impossible triangle shape */ +void make_shape() { + + static bool done = false; + if(done) return; + done = true; + + // four main axes of the regular tetrahedron, rotated so that ds[3] points to (0,0,1) + + ld rest = sqrt(8/9.); + ld rex = sqrt(1 - 1/9. - pow(rest/2., 2)); + + hyperpoint ds[4]; + + ds[0] = point3(rex, -rest/2, -1/3.); + ds[1] = point3(0, rest, -1/3.); + ds[2] = point3(-rex, -rest/2, -1/3.); + ds[3] = point3(0, 0, +1); + + hyperpoint start = point31(0, 0, 0); + + double lastz; + + double lasta; + + double ca; + + // compute how to scale this in Nil so that everything fits + + for(ld a = 1e-5;; a+=1e-5) { + hyperpoint at = start; + for(int d=0; d<3; d++) { + for(int i=0; i 50000) break; + } + + for(int s=0; s<8; s++) + for(int t=0; t<3; t++) { + if((s & (1<