Advertisement
Guest User

bagel_0101a

a guest
Jun 8th, 2022
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. /**
  2. * based off example from https://openhome.cc/eGossip/OpenSCAD/lib3x-path_extrude.html
  3. **/
  4.  
  5. use <dotSCAD/src/shape_circle.scad>
  6. use <dotSCAD/src/path_extrude.scad>
  7. use <dotSCAD/src/util/degrees.scad>;
  8.  
  9.  
  10. function double_torus_knot(q, rad, dir, phi_step) =
  11. [
  12. for(phi = 0; phi < 6.283185307179586*q[0]; phi = phi + phi_step)
  13. let(
  14. phi_deg = degrees(phi),
  15. l0_deg = -dir[0]*phi_deg,
  16. l1_deg = phi_deg/q[0],
  17. l0_pos_x = rad[0]*cos(l0_deg)-rad[0]*sin(l0_deg),
  18. l0_pos_y = 0,
  19. l0_pos_z = rad[0]*sin(l0_deg)+rad[0]*cos(l0_deg),
  20. l1_pos_x = (l0_pos_x+rad[1])*cos(l1_deg)-l0_pos_y*sin(l1_deg),
  21. l1_pos_y = (l0_pos_x+rad[1])*sin(l1_deg)+l0_pos_y*cos(l1_deg),
  22. l1_pos_z = l0_pos_z
  23. )
  24. [l1_pos_x,
  25. l1_pos_y,
  26. l1_pos_z]
  27. ];
  28.  
  29. function triple_torus_knot(q, rad, dir, phi_step) =
  30. [
  31. for(phi = 0; phi < 6.283185307179586*q[0]*q[1]; phi = phi + phi_step)
  32. let(
  33. phi_deg = degrees(phi),
  34. l0_deg = -dir[0]*phi_deg,
  35. l1_deg = phi_deg/q[0],
  36. l0_pos_x = rad[0]*cos(l0_deg)-rad[0]*sin(l0_deg),
  37. l0_pos_y = 0,
  38. l0_pos_z = rad[0]*sin(l0_deg)+rad[0]*cos(l0_deg),
  39. l1_pos_x = (l0_pos_x+rad[1])*cos(l1_deg)-l0_pos_y*sin(l1_deg),
  40. l1_pos_y = (l0_pos_x+rad[1])*sin(l1_deg)+l0_pos_y*cos(l1_deg),
  41. l1_pos_z = l0_pos_z,
  42. l2_deg = dir[1]*phi_deg/q[0]/q[1],
  43. l2_pos_x = l1_pos_x,
  44. l2_pos_y = (l1_pos_y+rad[2])*cos(l2_deg)-l1_pos_z*sin(l2_deg),
  45. l2_pos_z = (l1_pos_y+rad[2])*sin(l2_deg)+l1_pos_z*cos(l2_deg)
  46. )
  47. [l2_pos_x,
  48. l2_pos_y,
  49. l2_pos_z]
  50. ];
  51.  
  52. function quad_torus_knot(q, rad, dir, phi_step) =
  53. [
  54. for(phi = 0; phi < 6.283185307179586*q[0]*q[1]*q[2]; phi = phi + phi_step)
  55. let(
  56. phi_deg = degrees(phi),
  57. l0_deg = -dir[0]*phi_deg,
  58. l1_deg = phi_deg/q[0],
  59. l0_pos_x = rad[0]*cos(l0_deg)-rad[0]*sin(l0_deg),
  60. l0_pos_y = 0,
  61. l0_pos_z = rad[0]*sin(l0_deg)+rad[0]*cos(l0_deg),
  62. l1_pos_x = (l0_pos_x+rad[1])*cos(l1_deg)-l0_pos_y*sin(l1_deg),
  63. l1_pos_y = (l0_pos_x+rad[1])*sin(l1_deg)+l0_pos_y*cos(l1_deg),
  64. l1_pos_z = l0_pos_z,
  65. l2_deg = dir[1]*phi_deg/q[0]/q[1],
  66. l2_pos_x = l1_pos_x,
  67. l2_pos_y = (l1_pos_y+rad[2])*cos(l2_deg)-l1_pos_z*sin(l2_deg),
  68. l2_pos_z = (l1_pos_y+rad[2])*sin(l2_deg)+l1_pos_z*cos(l2_deg),
  69. l3_deg = -dir[2]*phi_deg/q[0]/q[1]/q[2],
  70. l3_pos_x = l2_pos_x*cos(l3_deg)-(l2_pos_y+rad[3])*sin(l3_deg),
  71. l3_pos_y = l2_pos_x*sin(l3_deg)+(l2_pos_y+rad[3])*cos(l3_deg),
  72. l3_pos_z = l2_pos_z
  73. )
  74. [l3_pos_x,
  75. l3_pos_y,
  76. l3_pos_z]
  77. ];
  78.  
  79.  
  80. /**
  81. * - number of loops per level
  82. * - radius of torus center line per level
  83. * - rotation direction 1 clockwise (right-handed?), -1 counter-clockwise (left-handed?)
  84. * - radian per segment break
  85. **/
  86. //pts_1 = double_torus_knot([8], [1,4], [1], 0.5);
  87. //pts_1 = triple_torus_knot([9,11], [1,4,16], [1,1], 0.5);
  88. //pts_1 = quad_torus_knot([12,24,24], [1,4,16,64], [1,1,1], 0.5);
  89.  
  90. wire_1_cross_section_radius = 0.5;
  91. wire_1_cross_section_pts = shape_circle(wire_1_cross_section_radius,$fn=10);
  92. pts_1 = quad_torus_knot([12,24,24], [1,4,16,64], [1,1,1], 0.5);
  93. path_extrude(
  94. wire_1_cross_section_pts,
  95. [each pts_1],
  96. closed = false,
  97. twist = 0,
  98. method = "AXIS_ANGLE"
  99. );
  100. wire_2_cross_section_radius = 1;
  101. wire_2_cross_section_pts = shape_circle(wire_2_cross_section_radius,$fn=10);
  102. pts_2 = quad_torus_knot([12,24,24], [0,4,16,64], [1,1,1], 0.5);
  103. color([0,0,0])
  104. path_extrude(
  105. wire_2_cross_section_pts,
  106. [each pts_2],
  107. closed = false,
  108. twist = 0,
  109. method = "AXIS_ANGLE"
  110. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement