Guest User

Untitled

a guest
Jun 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. settings.render=2;
  2. settings.outformat="pdf";
  3.  
  4. // -----------------------------------------------------------------------------
  5. import three;
  6. import solids;
  7. import animate;
  8.  
  9. // -----------------------------------------------------------------------------
  10. real[] circumsphere(triple p1, triple p2, triple p3, triple p4){
  11. real a = orient(p1,p2,p3,p4);
  12. real q1 = p1.x*p1.x + p1.y*p1.y + p1.z*p1.z;
  13. real q2 = p2.x*p2.x + p2.y*p2.y + p2.z*p2.z;
  14. real q3 = p3.x*p3.x + p3.y*p3.y + p3.z*p3.z;
  15. real q4 = p4.x*p4.x + p4.y*p4.y + p4.z*p4.z;
  16. real Dx = orient((q1,p1.y,p1.z),(q2,p2.y,p2.z),(q3,p3.y,p3.z),(q4,p4.y,p4.z));
  17. real Dy = orient((q1,p1.x,p1.z),(q2,p2.x,p2.z),(q3,p3.x,p3.z),(q4,p4.x,p4.z));
  18. real Dz = orient((q1,p1.x,p1.y),(q2,p2.x,p2.y),(q3,p3.x,p3.y),(q4,p4.x,p4.y));
  19. triple center = 0.5/a * (Dx,-Dy,Dz);
  20. real r = length(p1-center);
  21. real[] out = {center.x,center.y,center.z,r};
  22. return out;
  23. }
  24.  
  25. // -----------------------------------------------------------------------------
  26. triple inversion(triple pnt, real r, triple center){
  27. triple omega = (2*r, 0, 0);
  28. real k = 3*r*r;
  29. triple v = pnt - omega - center;
  30. return omega + center - k/(v.x*v.x+v.y*v.y+v.z*v.z)*v;
  31. }
  32.  
  33. // -----------------------------------------------------------------------------
  34. real[] oneSphere(triple center, real r, real beta){
  35. triple pnt = center + (r*cos(beta)*2/3, r*sin(beta)*2/3, 0);
  36. real thRadius = r/3;
  37. triple p1 = pnt + (thRadius,0,0);
  38. triple p2 = pnt + (0,thRadius,0);
  39. triple p3 = pnt + (-thRadius,0,0);
  40. triple p4 = pnt + (0,0,thRadius);
  41. triple q1 = inversion(p1, r, center);
  42. triple q2 = inversion(p2, r, center);
  43. triple q3 = inversion(p3, r, center);
  44. triple q4 = inversion(p4, r, center);
  45. real[] cs = circumsphere(q1,q2,q3,q4);
  46. cs[0] = cs[0] - 4*r;
  47. return cs;
  48. }
  49.  
  50. // -----------------------------------------------------------------------------
  51. real[][] hexlet(triple center, real r, int k, bool clockwise){
  52. real xi = k*pi/90;
  53. if(clockwise){
  54. xi = -xi;
  55. }
  56. real[][] out = new real[6][4];
  57. for(int i=0; i<6; ++i){
  58. real[] s = oneSphere(center, r, i*pi/3+xi);
  59. for(int j=0; j<4; ++j){
  60. out[i][j] = s[j];
  61. }
  62. }
  63. return out;
  64. }
  65.  
  66. real[][] hexlet2(int n, int k, bool clockwise){
  67. if(n==1){
  68. return hexlet((0,0,0), 1, k, clockwise);
  69. }
  70. real[][] hx = hexlet2(n-1, k, !clockwise);
  71. real[][] out = new real [0][4];
  72. for(int i=0; i<6^(n-1); ++i){
  73. real s[] = hx[i];
  74. real[][] hxnew = hexlet((s[0],s[1],s[2]), s[3], k, !clockwise);
  75. out.append(hxnew);
  76. }
  77. return out;
  78. }
  79.  
  80. // -----------------------------------------------------------------------------
  81. currentprojection=orthographic(0,0,6);
  82. viewportmargin=(10,10);
  83. size(10cm);
  84. currentlight=((0,0,100));
  85.  
  86. animation anim;
  87.  
  88. int n = 2;
  89. for(int k=0; k<30; ++k){
  90. erase();
  91. real[][] hx = hexlet2(n, k, true);
  92. for(int i=0; i<6^n; ++i){
  93. real[] s = hx[i];
  94. draw(surface(sphere((s[0],s[1],s[2]), s[3])), red);
  95. }
  96. anim.add();
  97. }
  98.  
  99. anim.movie();
Add Comment
Please, Sign In to add comment