Advertisement
Guest User

Borromean rings

a guest
Jan 18th, 2018
905
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. bez[pts_] := Module[{allpts, fs},
  2. allpts = Join[pts, pts];
  3. fs = (Interpolation[#, InterpolationOrder -> 3] &) /@
  4. Transpose[allpts];
  5.  
  6. Flatten@Table[
  7. Tube[{
  8. Table[fs[[i]][j], {i, Length[fs]}],
  9. Table[fs[[i]][j + 0.1], {i, Length[fs]}]
  10. }, 0.02]
  11. , {j, 0.5 Length[pts], 1.5 Length[pts], 0.1}]
  12. ];
  13. circ[x_, n_, e_] :=
  14. Table[{e Sin[2 Pi i /n] + x, Cos[2 Pi i/n], 0}, {i, n}];
  15. circ2[x_, n_, r_] :=
  16. Table[{Sin[2 Pi i /n] + x, 0, r Cos[2 Pi i/n]}, {i, n}]
  17. circ3[x_, n_, r1_, r2_, \[Alpha]_] :=
  18. Table[{x, r1 Cos [-2 Pi i /n + \[Alpha]],
  19. r2 Sin[-2 Pi i/n + \[Alpha]]}, {i, n}]
  20. c2 = circ2[1.7, 12, 1];
  21. loop = {
  22. {0.9, 0, -0.5},
  23. {0.6, -0.1, -0.5},
  24. {-0.6, -0.5, -0.1},
  25. {-0.9, -0.5, 0},
  26. {-0.6, -0.5, 0.1},
  27. {0.6, -0.1, 0.5},
  28. {0.9, 0, 0.5},
  29. {0.6, 0.1, 0.5},
  30. {-0.6, 0.5, 0.1},
  31. {-0.9, 0.5, 0},
  32. {-0.6, 0.5, -0.1},
  33. {0.6, 0.1, -0.5}
  34. };
  35. frame[t_, i_] := (
  36. Graphics3D[
  37. Rotate[Rotate[
  38. {
  39. bez[
  40. If[t > 5, 6 - t, 1]
  41. (RotationTransform[
  42. Pi Min[t, 1], {0, 1, 0}, {-0.8 + Min[t^2, 1], 0, 0}] /@
  43. circ[-1.7, 12,
  44. 1 + 0.5 Min[t, 1] - If[t > 2, 0.5 (Min[t, 3] - 2), 0]])
  45. + If[t > 5, t - 5, 0] Reverse[circ[-1.7, 12, 1]]
  46. ],
  47. bez[
  48. If[t > 5, 6 - t,
  49. 1] (ScalingTransform[{1, 1,
  50. If[t > 3, 1 - 0.2 (Min[t, 4] - 3)^2, 1]}] /@
  51.  
  52. If[t < 2, c2,
  53.  
  54. TranslationTransform[{2.2 (Min[t, 3] - 2), 0,
  55. 0}] /@ ((3 - Min[t, 3]) c2 +
  56. (Min[t, 3] - 2) RotateLeft[
  57. Join[circ2[1.7, 12, 0.9][[6 ;;]],
  58. Map[(0.85 # + 0.15 {1.7, 0, 0}) &,
  59. Reverse[
  60. circ2[1.7, 12,
  61. 0.9 - If[t > 3, 0.2 (Min[t, 4] - 3),
  62. 0]][[7 ;; -2]]]]], 7])]
  63. If[t > 4, 5 - Min[t, 5], 1]
  64. +
  65. If[t > 4, Min[t, 5] - 4,
  66. 0] TranslationTransform[{3, 0, 0}] /@
  67. RotateLeft[loop, 7])
  68. + If[t > 5, t - 5, 0] RotateLeft[loop, 7]
  69. ],
  70.  
  71. bez[
  72.  
  73. If[t > 5, 6 - t,
  74. 1] RotationTransform[
  75. If[t > 4, -(Min[t, 5] - 4) Pi/2, 0], {0, 0, 1}, {3.7, 0,
  76. 0}] /@
  77.  
  78. TranslationTransform[{0, If[t > 3, 0.7 (Min[t, 4] - 3), 0],
  79. 0}] /@
  80.  
  81. If[t < 1, loop,
  82. loop If[t < 2, (2 - t), 0] +
  83. If[t < 2, (t - 1), 1] circ3[
  84. 1.7 + If[t > 2, 2 (Min[t, 3] - 2), 0], 12,
  85. If[t > 2, 1.2 - (Min[t, 3] - 2)/5, 1.2],
  86. If[t > 2, 0.8 + (Min[t, 3] - 2)/20, 0.8], 5.1145]]
  87. + If[t > 5, t - 5, 0] RotateLeft[c2, 6]
  88. ]
  89. }
  90. , i Pi/2, {1, 0, 0}], i Pi, {0, 1, 0}]
  91. , Boxed -> False, ImageSize -> {500, 500}]);
  92. frames = Join[
  93. Table[frame[t, 0], {t, 0, 6, 6/97}],
  94. Table[frame[t, 1], {t, 0, 6, 6/97}]];
  95. Export["borr.gif", Join[frames]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement