From 886d9d1619dc839e317d3383ec2178428d1a0f12 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Mon, 9 Dec 2019 00:40:51 +0100 Subject: [PATCH] rug:: conformal tori --- hypgraph.cpp | 2 +- rug.cpp | 33 +++++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/hypgraph.cpp b/hypgraph.cpp index f2f1411e..fe26b334 100644 --- a/hypgraph.cpp +++ b/hypgraph.cpp @@ -39,7 +39,7 @@ EX bool non_spatial_model() { return pmodel && vid.consider_shader_projection && (get_shader_flags() & SF_DIRECT); } -hyperpoint perspective_to_space(hyperpoint h, ld alpha, eGeometryClass gc) { +EX hyperpoint perspective_to_space(hyperpoint h, ld alpha, eGeometryClass gc) { ld hx = h[0], hy = h[1]; if(gc == gcEuclid) diff --git a/rug.cpp b/rug.cpp index 38d3147d..99babb55 100644 --- a/rug.cpp +++ b/rug.cpp @@ -439,7 +439,7 @@ EX void buildTorusRug() { hyperpoint yh = euc::eumove(p2)*C0-C0; if(nonorientable) yh *= 2; - bool flipped = sqhypot_d(2, xh) < sqhypot_d(2, yh); + bool flipped = false; // sqhypot_d(2, xh) < sqhypot_d(2, yh); if(flipped) swap(xh, yh); @@ -461,6 +461,12 @@ EX void buildTorusRug() { map, rugpoint*> glues; + ld mx = 0; + for(int i=0; i<1000; i++) + mx = max(mx, hypot(xfactor, yfactor * sin(i)) / (1-yfactor * cos(i))); + + println(hlog, "mx = ", mx); + auto addToruspoint = [&] (hyperpoint h) { auto r = addRugpoint(C0, 0); hyperpoint onscreen; @@ -472,14 +478,25 @@ EX void buildTorusRug() { double alpha = -h[0] * 2 * M_PI; double beta = h[1] * 2 * M_PI; - if(gwhere == gSphere) { - ld ax = alpha + 1.124651, bx = beta + 1.214893; - ld x = xfactor * sin(ax), y = xfactor * cos(ax), z = yfactor * sin(bx), t = yfactor * cos(bx); - ld d = acos(t) / sqrt(x*x+y*y+z*z); - r->flat = r->h = hpxyz(x * d, y * d, z * d); + ld ax = alpha + 1.124651, bx = beta + 1.214893; + ld x = xfactor * sin(ax), y = xfactor * cos(ax), z = yfactor * sin(bx), t = yfactor * cos(bx); + + ld d; + ld hxyz = sqrt(x*x+y*y+z*z); + + if(gwhere == gNormal) { + d = hxyz / (1-t) / mx; + d *= .95; + hyperpoint test = hpxy(d, 0); + test = perspective_to_space(test, 1, gcHyperbolic); + d = acosh(test[2]) / hxyz; } - else - r->flat = r->h = modelscale * hpxyz((xfactor+yfactor*cos(beta)) * cos(alpha), (xfactor+yfactor*cos(beta)) * sin(alpha), yfactor*-sin(beta)); + else { + d = (gwhere == gSphere) ? acos(t) / hxyz : modelscale * 3 / (1-t) / mx; + } + + r->flat = r->h = hpxyz(x*d, y*d, z*d); + r->valid = true; static const int X = 100003; // a prime