1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867
|
// Hyperbolic Rogue -- surfaces of constant negative curvature
// Copyright (C) 2011-2018 Zeno Rogue, see 'hyper.cpp' for details
/** \file surface.cpp
* \brief surfaces of constant negative curvature
*
* See http://webmath2.unito.it/paginepersonali/sergio.console/CurveSuperfici/AG15.pdf for a nice reference
*/
#include "hyper.h"
namespace hr {
#if CAP_SURFACE
EX namespace surface {
ld sech(ld d) { return 1 / cosh(d); }
#if HDR
enum eShape { dsNone, dsTractricoid, dsDini, dsKuen, dsHyperlike, dsHyperboloid, dsHemisphere, dsCrystal };
#endif
string shape_name[] = { "hypersian rug", "tractricoid", "Dini's surface", "Kuen surface", "concave barrel",
"hyperboloid", "hemisphere", "crystal" };
EX eShape sh;
hyperpoint unit_vector[3] = {point3(1,0,0), point3(0,1,0), point3(0,0,1)};
ld last_int_of = 0, last_int = 0;
EX ld dini_b = .15;
EX ld hyper_b = 1;
ld f(ld x) {
return sqrt(1 - pow(hyper_b * sinh(x), 2));
}
int kuen_branch(ld v, ld u);
ld integral(ld x) {
if(x == 0) {
last_int = last_int_of = 0;
}
else {
last_int += (x - last_int) * f((x + last_int)/2);
last_int_of = x;
}
return last_int;
}
hyperpoint coord(hyperpoint h) {
// return { cos(u)*sin(v), cos(u)*cos(v), sin(u) };
/*
ld t = h[0];
ld v = h[1];
ld r = 1 / cosh(t);
ld x = t - tanh(t);
return { x + v * .1, r * sin(v), r * cos(v) };
*/
switch(sh) {
case dsTractricoid: {
ld t = h[0];
ld v = h[1];
ld r = 1 / cosh(t);
ld x = t - tanh(t);
return point31( r * sin(v), r * cos(v), x );
break;
}
case dsDini: {
ld t = h[0];
ld v = h[1];
ld a = sqrt(1-dini_b*dini_b);
return point31( a * sin(v) * sin(t), a * cos(v) * sin(t), a * (cos(t) + log(tan(t/2))) + dini_b * v );
break;
}
case dsKuen: {
ld v = h[0];
ld u = h[1];
ld deno = 1 / (1 + u * u * sin(v) * sin(v));
return point31(
2 * (cos(u) + u * sin(u)) * sin(v) * deno,
2 * (sin(u) - u * cos(u)) * sin(v) * deno,
log(tan(v/2)) + 2 * cos(v) * deno
);
}
case dsHyperlike: {
ld u = h[0];
ld v = h[1];
ld phi = hyper_b * cosh(v);
ld psi = integral(v);
return point31( phi * cos(u), phi * sin(u), psi );
}
default:
return h;
}
}
ld det(hyperpoint h1, hyperpoint h2, hyperpoint h3) {
return det(build_matrix(h1, h2, h3,C03));
}
ld epsd = 1e-5;
hyperpoint coord_derivative(hyperpoint h, int cc) {
switch(sh) {
case dsHyperlike: {
ld u = h[0];
ld v = h[1];
if(cc == 0) {
ld phi = hyper_b * cosh(v);
return point3( phi * -sin(u), phi * cos(u), 0 );
}
else {
return point3( hyper_b * sinh(v) * cos(u), hyper_b * sinh(v) * sin(u), f(v) );
}
}
case dsKuen: {
ld v = h[0];
ld u = h[1];
ld denom = pow(sin(v),2)*(u*u)+1;
ld denom2 = denom * denom;
if(cc == 1)
return point3(
2*sin(v)/denom*u*cos(u)+-4*(sin(u)*u+cos(u))*pow(sin(v),3)/denom2*u,
-4*pow(sin(v),3)*(sin(u)-u*cos(u))/denom2*u+2*sin(u)*sin(v)/denom*u,
-4*pow(sin(v),2)/denom2*u*cos(v)
);
else return point3(
2*(sin(u)*u+cos(u))/denom*cos(v)+-4*(sin(u)*u+cos(u))*pow(sin(v),2)/denom2*(u*u)*cos(v),
2*(sin(u)-u*cos(u))/denom*cos(v)+-4*pow(sin(v),2)*(sin(u)-u*cos(u))/denom2*(u*u)*cos(v),
-4*sin(v)/denom2*(u*u)*pow(cos(v),2)+1/tan(v/2)*(pow(tan(v/2),2)+1)/2+-2*sin(v)/denom
);
break;
}
default:
// too lazy do differentiate
return (coord(h + unit_vector[cc] * epsd) - coord(h)) / epsd;
}
}
ld compute_curvature(hyperpoint at) {
hyperpoint xu = coord_derivative(at, 0);
hyperpoint xv = coord_derivative(at, 1);
hyperpoint xuu = (coord_derivative(at + unit_vector[0] * epsd, 0) - xu) / epsd;
hyperpoint xuv = (coord_derivative(at + unit_vector[1] * epsd, 0) - xu) / epsd;
hyperpoint xvv = (coord_derivative(at + unit_vector[1] * epsd, 1) - xv) / epsd;
return
(det(xuu, xu, xv) * det(xvv, xu, xv) - pow(det(xuv, xu, xv), 2)) /
pow((xu|xu) * (xv|xv) - pow((xu|xv), 2), 2);
}
hyperpoint shape_origin() {
switch(sh) {
case dsDini:
return point31(A_PI * .82, 0, 0);
case dsTractricoid:
return point31(1, 0, 0);
case dsKuen:
return point31(90._deg * 1.000001, M_PI, 0);
case dsHyperlike:
return point31(0,0,0);
default:
return Hypc;
}
}
ld hyperlike_bound() { return asinh(1 / hyper_b); }
bool flag_clamp_min(ld& coord, ld minv) {
if(coord < minv) { coord = minv; return false; }
return true;
}
bool flag_clamp_max(ld& coord, ld maxv) {
if(coord > maxv) { coord = maxv; return false; }
return true;
}
bool flag_clamp(ld& coord, ld minv, ld maxv) {
return flag_clamp_min(coord, minv) && flag_clamp_max(coord, maxv);
}
bool flag_clamp_sym(ld& coord, ld v) {
return flag_clamp(coord, -v, v);
}
int surface_branch(hyperpoint p) {
if(sh == dsKuen) return kuen_branch(p[0], p[1]);
return 0;
}
bool inbound(ld& x, ld& y) {
switch(sh) {
case dsDini:
return flag_clamp(x, 90._deg, M_PI);
case dsTractricoid:
return flag_clamp_min(x, 0) && flag_clamp_sym(y, M_PI);
case dsKuen:
return flag_clamp(x, 0, M_PI) && flag_clamp(y, 0, TAU);
case dsHyperlike:
return flag_clamp_sym(x, M_PI) && flag_clamp_sym(y, hyperlike_bound());
default:
return true;
}
}
bool is_inbound(hyperpoint h) {
return inbound(h[0], h[1]);
}
int precision = 100;
using rug::dexp_data;
struct dexp_origin {
transmatrix H; // isometry of H2 moving zero to C0
transmatrix M; // local coordinates on H2 to local coordinates on surface
hyperpoint zero; // parameters of the zero point
};
dexp_data dexp(hyperpoint p, hyperpoint t) {
ld eps = 1. / precision;
int b = surface_branch(p);
for(ld u=0; u<1; u += eps) {
transmatrix T = build_matrix(coord_derivative(p, 0), coord_derivative(p, 1), Hypc, C03);
p += t * eps;
if(!is_inbound(p) || surface_branch(p) != b)
return { p - t * eps, t, hypot_d(3, t) * (1-u) / precision };
auto v0 = coord_derivative(p, 0);
auto v1 = coord_derivative(p, 1);
transmatrix T2 = build_matrix(v0, v1, v0 ^ v1, C03);
t = inverse(T2) * T * t;
t[2] = 0;
}
return { p, t, 0 };
}
dexp_data map_to_surface(hyperpoint p, const dexp_origin& dor) {
hyperpoint h = dor.H * p;
ld rad = hypot_d(2, h);
if(rad == 0) rad = 1;
ld d = hdist0(h);
hyperpoint direction;
direction[0] = d * h[0] / rad;
direction[1] = d * h[1] / rad;
direction[2] = 0;
#if MAXMDIM == 4
direction[3] = 0;
#endif
return dexp(dor.zero, dor.M * direction);
}
transmatrix create_M_matrix(hyperpoint zero, hyperpoint v1) {
hyperpoint Te0 = coord_derivative(zero, 0);
hyperpoint Te1 = coord_derivative(zero, 1);
transmatrix T = build_matrix(Te0, Te1, Hypc, C03);
v1 = v1 / hypot_d(3, T*v1);
hyperpoint v2 = point3(1e-3, 1e-4, 0);
v2 = v2 - v1 * ((T*v1) | (T*v2)) / hypot_d(3, T*v1);
v2 = v2 / hypot_d(3, T*v2);
if((((T*v1) ^ (T*v2)) | ((T*unit_vector[0]) ^ (T*unit_vector[1]))) < 0)
v2 = v2 * -1;
transmatrix M = build_matrix(v1, v2, Hypc, C03);
println(hlog, M);
println(hlog, "M matrix test: ",
make_tuple(hypot_d(3, T*M*unit_vector[0]), hypot_d(3, T*M*unit_vector[1]), hypot_d(3, T*M*(unit_vector[0]+unit_vector[1])),
((T*M*unit_vector[0]) | (T*M*unit_vector[1]))));
return M;
}
dexp_origin at_zero(hyperpoint zero, transmatrix start) {
println(hlog, "zero = ", zero);
println(hlog, "curvature at zero = ", compute_curvature(zero));
println(hlog, "curvature at X1 = ", compute_curvature(zero + point3(.3, 0, 0)));
println(hlog, "curvature at X2 = ", compute_curvature(zero + point3(0, .3, 0)));
println(hlog, "curvature at X3 = ", compute_curvature(zero + point3(.4, .3, 0)));
return {start, create_M_matrix(zero, unit_vector[0]), zero};
}
dexp_origin at_other(dexp_origin& o1, hyperpoint h) {
println(hlog, "\n\nmapping ", h, "...");
println(hlog, o1.H, o1.M);
auto dd = map_to_surface(h, o1);
hyperpoint newzero = dd.params;
println(hlog, "error = ", dd.remaining_distance);
transmatrix Spin = spintox(o1.H * h);
transmatrix T = pushxto0(Spin * o1.H * h) * Spin;
println(hlog, "h is = ", h);
println(hlog, "T*c0 is = ", T * C0);
println(hlog, "T*h is = ", T * o1.H * h);
return {T * o1.H, create_M_matrix(newzero, dd.cont), newzero};
}
void addTriangleV(rug::rugpoint *t1, rug::rugpoint *t2, rug::rugpoint *t3, ld len = 1) {
if(t1 && t2 && t3)
rug::addTriangle(t1, t2, t3, len);
}
hyperpoint kuen_cross(ld v, ld u) {
auto du = coord_derivative(point3(v,u,0), 0);
auto dv = coord_derivative(point3(v,u,0), 1);
return du^dv;
}
ld kuen_hypot(ld v, ld u) {
auto du = coord_derivative(point3(v,u,0), 0);
auto dv = coord_derivative(point3(v,u,0), 1);
auto n = hypot_d(3, du^dv);
return n;
}
int kuen_branch(ld v, ld u) {
if(v > 90._deg)
return kuen_cross(v, u)[2] > 0 ? 1 : 2;
else
return kuen_cross(v, u)[2] < 0 ? 1 : 2;
}
int dexp_colors[16] = {
0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00 };
int dexp_comb_colors[16] = {
0x000000, 0x0000FF, 0x00FF00, 0x00FFFF,
0xFF0000, 0xFF00FF, 0xFFFF00, 0xFFFFFF,
0xFFD500,
0x123456, 0x123456, 0x123456, 0x123456, 0x123456, 0x123456, 0x123456
};
int coverage_style;
EX vector<pair<hyperpoint, int> > coverage;
#if CAP_KUEN_MAP
void draw_kuen_map() {
SDL_Surface *kuen_map = SDL_CreateRGBSurface(SDL_SWSURFACE,512,512,32,0,0,0,0);
ld nmax = 0;
for(int i=0; i<2; i++) {
for(int r=0; r<512; r++)
for(int h=0; h<512; h++) {
ld v = M_PI * (r+.5) / 512;
ld u = TAU * (h+.5) / 512;
auto du = coord_derivative(point3(v,u,0), 0);
auto dv = coord_derivative(point3(v,u,0), 1);
auto n = hypot_d(3, du^dv);
if(n > nmax) nmax = n;
if(i == 1) {
auto vv = kuen_cross(v, u);
auto& px = qpixel(kuen_map, r, h);
px |= 0xFF000000;
for(int k=0; k<3; k++)
part(px, k) = (vv[k] > 0 ? 0xFF : 0);
px = 0xFF000000 + (((int)(n*255/nmax)) * (kuen_branch(v,u) == 1 ? 0x10101 : 0x10001));
}
}
println(hlog, "nmax = ", nmax);
}
for(auto p: rug::points) {
auto hp = p->surface_point.params;
int x = int(512 * hp[0] / M_PI);
int y = int(512 * hp[1] / TAU);
qpixel(kuen_map, x, y) = 0xFF000000 | dexp_colors[p->dexp_id];
}
IMAGESAVE(kuen_map, "kuen.png");
}
#endif
void full_mesh() {
rug::clear_model();
rug::buildRug();
rug::qvalid = 0;
for(auto p: rug::points) p->valid = true, rug::qvalid++;
while(rug::subdivide_further()) rug::subdivide();
rug::sort_rug_points();
for(auto p: rug::points) p->valid = false;
rug::good_shape = true;
}
char rchar(int id) {
return 33 + id % 94;
}
void run_hyperlike() {
if(!rug::rugged) rug::reopen();
rug::clear_model();
int lim = (int) sqrt(rug::vertex_limit);
for(int r=0; r<lim; r++)
for(int h=0; h<lim; h++)
rug::addRugpoint(shiftless(xpush(TAU * hyper_b * (2*r-lim) / lim) * ypush(hyperlike_bound() * (2*h-lim) / lim) * C0), -1);
for(int r=0; r<lim-1; r++)
for(int h=0; h<lim-1; h++) {
addTriangle(rug::points[lim*r+h], rug::points[lim*r+h+1], rug::points[lim*r+h+lim]);
addTriangle(rug::points[lim*r+h+lim+1], rug::points[lim*r+h+lim], rug::points[lim*r+h+1]);
}
vector<ld> integral_table;
for(int i=0; i<=precision; i++)
integral_table.push_back(integral(hyperlike_bound() * i / precision));
int id = 0;
for(auto p: rug::points) {
auto h = unshift(p->h);
coverage.emplace_back(h, rchar(id++) + 7 * 256);
ld y = asinh(h[1]);
ld x = asinh(h[0] / cosh(y)) / hyper_b;
p->surface_point.remaining_distance = !inbound(x, y);
p->surface_point.params = hpxyz(x, y, 0);
int sgn = y > 0 ? 1 : -1;
ld phi = hyper_b * cosh(y);
int pt = y * precision * sgn / hyperlike_bound();
USING_NATIVE_GEOMETRY;
p->native = point31(phi * cos(x), phi * sin(x), sgn * integral_table[pt]);
p->valid = true;
}
}
void run_kuen() {
full_mesh();
auto H = Id;
auto Hi = inverse(H);
auto frontal_map = at_zero(hpxyz(90._deg * 1.000001, M_PI * 1, 0), Id);
auto back0 = at_zero(hpxyz(90._deg * 1.000001, .67, 0), H);
auto back1 = at_other(back0, Hi * spin(-90._deg) * hpxy(0.511, -0.5323));
auto back2 = at_other(back0, Hi * spin(-90._deg) * hpxy(0.511, 0.5323));
frontal_map.H = frontal_map.H * ypush(2.6);
back0.H = back0.H * ypush(.4);
back1.H = back1.H * ypush(.4);
back2.H = back2.H * ypush(.4);
int it = 0;
for(auto p: rug::points) p->dexp_id = it++;
vector<rug::rugpoint*> mesh = std::move(rug::points);
vector<rug::triangle> old_triangles = std::move(rug::triangles);
rug::clear_model();
int part = 0;
vector<int> coverages(isize(mesh), 0);
for(auto& m: { frontal_map, back0, back1, back2 } ) {
part++;
int pid[5] = {0, 8, 1, 2, 4};
string captions[5] = {"", "the upper component", "the lower center", "the lower left", "the lower right"};
vector<rug::rugpoint*> newmesh(isize(mesh), nullptr);
for(auto p: mesh) {
auto px = map_to_surface(unshift(p->h), m);
p->surface_point = px;
history::progress(XLAT("solving the geodesics on: %1, %2/%3", XLAT(captions[part]), its(p->dexp_id), its(isize(mesh))));
}
for(auto p: mesh) {
// make it a bit nicer by including the edges where only one endpoint is valid
auto& px = p->surface_point;
p->valid = px.remaining_distance == 0;
for(auto e: p->edges) if(e.target->surface_point.remaining_distance == 0)
p->valid = true;
if(p->valid) {
rug::rugpoint *np = new rug::rugpoint;
newmesh[p->dexp_id] = np;
rug::points.push_back(np);
np->x1 = p->x1;
np->y1 = p->y1;
np->valid = true;
np->inqueue = false;
np->dist = 0;
np->h = p->h;
USING_NATIVE_GEOMETRY;
np->native = coord(px.params);
np->surface_point = px;
np->dexp_id = p->dexp_id;
coverages[p->dexp_id] |= pid[part];
}
}
for(auto& t: old_triangles) {
rug::rugpoint* r[3];
for(int i=0; i<3; i++)
r[i] = newmesh[t.m[i]->dexp_id];
bool looks_good = true;
for(int i=0; i<3; i++)
if(!r[i]) looks_good = false;
if(!looks_good) continue;
for(int i=0; i<3; i++) {
USING_NATIVE_GEOMETRY;
if(hypot_d(3, r[i]->native - r[(i+1)%3]->native) > .2)
looks_good = false;
}
if(looks_good)
addTriangleV(r[0], r[1], r[2]);
}
}
for(auto t: mesh) {
int c = coverages[t->dexp_id];
coverage.emplace_back(unshift(t->h), rchar(t->dexp_id) + 256 * c);
}
// delete the old mesh
for(auto t: mesh) delete t;
#if CAP_KUEN_MAP
draw_kuen_map();
#endif
}
template<class T> void run_function(T f) {
full_mesh();
for(auto p: rug::points) {
USING_NATIVE_GEOMETRY;
p->native = f(unshift(p->h)),
p->valid = true;
}
}
void run_other() {
full_mesh();
auto dp = at_zero(shape_origin(), spin(90._deg));
int it = 0;
for(auto p: rug::points) {
it++;
auto h = unshift(p->h);
p->surface_point = map_to_surface(h, dp);
if(1) {
USING_NATIVE_GEOMETRY;
p->native = coord(p->surface_point.params);
}
history::progress(XLAT("solving the geodesics on: %1, %2/%3", XLAT(shape_name[sh]), its(it), its(isize(rug::points))));
if(p->surface_point.remaining_distance == 0)
coverage.emplace_back(h, rchar(it) + 256 * 7);
}
clearMessages();
for(auto p: rug::points) {
// make it a bit nicer by including the edges where only one endpoint is valid
p->valid = p->surface_point.remaining_distance == 0;
if(sh != dsKuen) {
for(auto e: p->edges) if(e.target->surface_point.remaining_distance == 0)
p->valid = true;
}
}
}
EX void run_shape(eShape s) {
coverage.clear();
need_mouseh = true;
sh = s;
if(rug::rugged) rug::close();
rug::gwhere = rug::rgEuclid;
rug::init();
// if(!rug::rugged) rug::reopen();
pushScreen(history::progress_screen);
if(sh != dsNone) rug::good_shape = true;
switch(sh) {
case dsNone:
break;
case dsKuen:
run_kuen();
break;
case dsHyperlike:
run_hyperlike();
break;
default:
run_other();
break;
case dsHyperboloid:
run_function([] (hyperpoint h) { return h; });
break;
case dsHemisphere:
run_function([] (hyperpoint h) { h = h / h[2]; h[2] = sqrt(1 - sqhypot_d(2, h)); return h; });
break;
}
if(sh != dsNone) rug::good_shape = true;
rug::qvalid = 0;
popScreen();
if(sh != dsHyperboloid && sh != dsHemisphere && sh != dsNone) {
ld minx = 1e9, maxx = -1e9;
for(auto p: rug::points) if(p->valid) {
minx = min(p->native[2], minx);
maxx = max(p->native[2], maxx);
rug::qvalid++;
}
println(hlog, "minx = ", minx, " maxx = ", maxx);
ld shift = -(minx + maxx) / 2;
for(auto p: rug::points) if(p->valid)
p->native[2] += shift;
}
}
void cancel_shape() {
if(sh) {
sh = dsNone;
rug::good_shape = false;
rug::qvalid = 0;
for(auto p: rug::points)
p->valid = p->surface_point.remaining_distance == 0;
for(auto p: rug::points)
if(p->valid)
rug::qvalid++, rug::enqueue(p);
}
}
cell *coverage_center;
transmatrix coverage_matrix;
EX void show_surfaces() {
cmode = sm::SIDE;
gamescreen();
dialog::init(XLAT("constant curvature surfaces"), iinf[itPalace].color, 150, 0);
bool b = rug::rugged || coverage_style;
dialog::addBoolItem(XLAT("tractricoid"), b && sh == dsTractricoid, '1');
dialog::addBoolItem(XLAT("concave barrel"), b && sh == dsHyperlike, '2');
dialog::addSelItem(" " + XLAT("parameter"), fts(hyper_b), '@');
dialog::addBoolItem(XLAT("Dini's surface"), b && sh == dsDini, '3');
dialog::addSelItem(" " + XLAT("parameter") + " ", fts(dini_b), '#');
dialog::addBoolItem(XLAT("Kuen surface"), b && sh == dsKuen, '4');
dialog::addBreak(50);
dialog::addTitle(XLAT("other 3D models"), iinf[itPalace].color, 150);
dialog::addBoolItem(XLAT("Hypersian Rug"), b && sh == dsNone, '5');
dialog::addBoolItem(XLAT("Minkowski hyperboloid"), b && sh == dsHyperboloid, '6');
dialog::addBoolItem(XLAT("hemisphere"), b && sh == dsHemisphere, '7');
dialog::addBreak(100);
dialog::addSelItem(XLAT("precision"), its(precision), 'p');
string cstyles[4] = { "OFF", "on surface", "on H² (static)", "on H² (dynamic)" };
if((rug::rugged && sh && sh != dsHyperboloid && sh != dsHemisphere) || coverage_style)
dialog::addSelItem(XLAT("display coverage"), cstyles[coverage_style], 'c');
else dialog::addBreak(100);
#if CAP_FILES
if(rug::rugged)
dialog::addItem(XLAT("save the current embedding"), 's');
else
dialog::addItem(XLAT("load a saved embedding"), 's');
#endif
dialog::addHelp();
dialog::addBack();
dialog::display();
keyhandler = [] (int sym, int uni) {
dialog::handleNavigation(sym, uni);
if(uni == 'h' || uni == SDLK_F1)
gotoHelp(XLAT(
"In this menu you can choose from several known smooth surfaces of constant negative curvature. "
"Since the curvature of hyperbolic plane is also constant negative, these surfaces "
"are great to draw hyperbolic tesselations on. While they look great, only a small part "
"of the hyperbolic plane can be visibly represented in this way, so they are not "
"good for playing HyperRogue; however, the coverage extends far away in specific directions, "
"so first increasing sight range in graphics config and texture size in hypersian rug settings may improve the effect. "
"For convenience, you can also choose other 3D models from this menu."
));
#if CAP_FILES
else if(uni == 's') {
static string rugname = "saved.rug";
if(rug::rugged)
dialog::openFileDialog(rugname, XLAT("save embedding to:"), ".rug", [] () { rug::rug_save(rugname); return true; });
else
dialog::openFileDialog(rugname, XLAT("load embedding from:"), ".rug", [] () { rug::init(); rug::rug_load(rugname); return true; });
}
#endif
else if(uni == '1')
run_shape(dsTractricoid);
else if(uni == '2')
run_shape(dsHyperlike);
else if(uni == '3')
run_shape(dsDini);
else if(uni == '4')
run_shape(dsKuen);
else if(uni == '5')
run_shape(dsNone);
else if(uni == '6')
run_shape(dsHyperboloid);
else if(uni == '7')
run_shape(dsHemisphere);
else if(uni == '@') {
dialog::editNumber(hyper_b, -1, 1, .05, 1, XLAT("parameter"),
XLAT("Controls the inner radius.")
);
dialog::reaction = [] () {
if(sh == dsHyperlike) run_shape(sh);
};
}
else if(uni == 'x')
for(auto p: rug::points)
p->native = p->surface_point.params;
else if(uni == '#')
dialog::editNumber(dini_b, -1, 1, .05, .15, XLAT("parameter"),
XLAT("The larger the number, the more twisted it is.")
);
else if(uni == 'p') {
dialog::editNumber(precision, 1, 10000, 0, 100, XLAT("precision"),
XLAT("Computing these models involves integrals and differential equations, which are currently solved numerically. This controls the precision.")
);
dialog::ne.step = .1;
dialog::scaleLog();
}
else if(uni == 'c') {
coverage_style = (1 + coverage_style) % 4;
if(coverage_style == 0) {
rug::reopen();
}
if(coverage_style == 2) {
if(rug::rugged) rug::close();
}
coverage_matrix = inverse(unshift(ggmatrix(coverage_center = cwt.at)));
}
else if(rug::handlekeys(sym, uni)) ;
else if(doexiton(sym, uni)) popScreen();
};
}
#if CAP_COMMANDLINE
int surface_args() {
using namespace arg;
if(0) ;
else if(argis("-kuen")) {
PHASE(3);
calcparam();
run_shape(dsKuen);
}
else if(argis("-dini")) {
PHASE(3);
calcparam();
shift();
dini_b = argf();
run_shape(dsDini);
}
else if(argis("-barrel")) {
PHASE(3);
calcparam();
shift();
hyper_b = argf();
run_shape(dsHyperlike);
}
else if(argis("-tractricoid")) {
PHASE(3);
calcparam();
run_shape(dsTractricoid);
}
else if(argis("-hemi")) {
PHASE(3);
calcparam();
run_shape(dsHemisphere);
}
else if(argis("-hyperb")) {
PHASE(3);
calcparam();
run_shape(dsHyperboloid);
}
else if(argis("-d:surface"))
launch_dialog(show_surfaces);
else return 1;
return 0;
}
#endif
#if CAP_COMMANDLINE
auto surface_hook = addHook(hooks_args, 100, surface_args);
#endif
void display_coverage() {
shiftmatrix M =
coverage_style == 3 ? ggmatrix(coverage_center) * coverage_matrix
: shiftless(Id);
if(coverage_style)
for(auto p : coverage)
queuestr(M * p.first, 10, s0+char(p.second), dexp_comb_colors[(p.second >> 8) & 15]);
/* if(p->valid && p->surface_point.remaining_distance == 0)
queuestr(p->h, 10, "x", dexp_colors[p->dexp_id]); */
}
auto surface_hook2 = addHook(hooks_frame, 0, display_coverage);
EX }
#endif
}
|