Advertisement
49xur

bagel_0105f

Sep 22nd, 2022
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.15 KB | None | 0 0
  1. /**
  2. * based off example from https://github.com/JustinSDK/dotSCAD/blob/master/docs/lib3x-torus_knot.md
  3. * using library https://github.com/JustinSDK/dotSCAD (latest master version required 938507d)
  4. **/
  5.  
  6. /*
  7. *
  8. * Version 0102a: First release with usability improvements
  9. * Version 0103a: Fix for level 0 torus radius was calculating incorrectly, also added correct examples for D-4D using the torus center line for rad_p properly.
  10. * Version 0104a: Initial support for generating winding molds
  11. * Version 0105a: Clean-up for generating winding molds.
  12. * Version 0105b: Remove work-around hacks for issue with dotSCAD path extrude (no fixed)
  13. * Version 0105c: Added phase attribute to align model coils with winding props
  14. * Version 0105f: Added a new triple torus winding prop with additional 3rd level grooves, also fixed second order dir on quad torus model which wasn't working properly, finally fixed skew on second level and third level windings which were not scewed in the direction of the second and third parent level windings.
  15. */
  16.  
  17. use <dotSCAD/src/shape_circle.scad>;
  18. use <dotSCAD/src/path_extrude.scad>;
  19. use <dotSCAD/src/util/degrees.scad>;
  20. use <dotSCAD/src/__comm__/__frags.scad>;
  21.  
  22. ovr = 0.5;
  23.  
  24. function shape_circle(radius, start_n, stop_n) =
  25. let(
  26. _frags = __frags(radius),
  27. step_a = 360 / _frags,
  28. from = (is_undef(start_n) || start_n < 0) ? 0: start_n,
  29. to = (is_undef(stop_n) || stop_n > _frags) ? _frags - 1: stop_n - 1
  30. )
  31. [
  32. for(a = [each [from:to]] * step_a)
  33. [radius * cos(a), radius * sin(a)]
  34. ];
  35.  
  36. function length_3d(lt) =
  37. let(end = len(lt) - 1)
  38. end == 0 ? lt[0] :
  39. let(
  40. cum_total = [
  41. for(i = 0, s = 0, is_continue = i < end;
  42. is_continue;
  43. is_continue = i < end, s = is_continue ? s + sqrt((lt[i+1][0]-lt[i][0])^2+(lt[i+1][1]-lt[i][1])^2+(lt[i+1][2]-lt[i][2])^2) : undef, i = i + 1) s]
  44. )
  45. cum_total[end];
  46.  
  47. function single_torus_knot(q, rad, dir, phase, phi_step, min_phi=0, max_phi=-1) =
  48. [
  49. for(phi = min_phi; phi < (max_phi == -1 ? 6.283185307179586 : max_phi) - 0.00001; phi = phi + phi_step)
  50. let(
  51. phi_deg = degrees(phi),
  52. l0_deg = phi_deg+phase[0],
  53. l0_pos_x = rad[0]*cos(l0_deg),
  54. l0_pos_y = 0,
  55. l0_pos_z = rad[0]*sin(l0_deg)
  56. )
  57. [l0_pos_x,
  58. l0_pos_y,
  59. l0_pos_z]
  60. ];
  61.  
  62. function double_torus_knot(q, rad, dir, phase, phi_step, min_phi=0, max_phi=-1) =
  63. [
  64. for(phi = min_phi; phi < (max_phi == -1 ? 6.283185307179586*q[0] : max_phi) - 0.00001; phi = phi + phi_step)
  65. let(
  66. phi_deg = degrees(phi),
  67. l0_deg = -dir[0]*phi_deg+phase[0],
  68. l1_deg = phi_deg/q[0]+phase[1],
  69. l0_pos_x = rad[0]*cos(l0_deg),
  70. l0_pos_y = 0,
  71. l0_pos_z = rad[0]*sin(l0_deg),
  72. l1_pos_x = (l0_pos_x+rad[1])*cos(l1_deg)-l0_pos_y*sin(l1_deg),
  73. l1_pos_y = (l0_pos_x+rad[1])*sin(l1_deg)+l0_pos_y*cos(l1_deg),
  74. l1_pos_z = l0_pos_z
  75. )
  76. [l1_pos_x,
  77. l1_pos_y,
  78. l1_pos_z]
  79. ];
  80.  
  81. function triple_torus_knot(q, rad, dir, phase, phi_step, min_phi=0, max_phi=-1) =
  82. [
  83. for(phi = min_phi; phi < (max_phi == -1 ? 6.283185307179586*q[0]*q[1] : max_phi) - 0.00001; phi = phi + phi_step)
  84. let(
  85. phi_deg = degrees(phi),
  86. l0_deg = -dir[0]*phi_deg+phase[0],
  87. l1_deg = phi_deg/q[0]+phase[1],
  88. l0_ratio_y_to_z = atan2((2*3.14159*rad[1]/q[1]),(2*3.14159*rad[2]/(q[1]*q[0]))),
  89. l0_pos_x = rad[0]*cos(l0_deg),
  90. l0_pos_y = -1*dir[1]*cos(l0_ratio_y_to_z)*rad[0]*sin(l0_deg),
  91. l0_pos_z = sin(l0_ratio_y_to_z)*rad[0]*sin(l0_deg),
  92. l1_pos_x = (l0_pos_x+rad[1])*cos(l1_deg)-l0_pos_y*sin(l1_deg),
  93. l1_pos_y = (l0_pos_x+rad[1])*sin(l1_deg)+l0_pos_y*cos(l1_deg),
  94. l1_pos_z = l0_pos_z,
  95. l2_deg = dir[1]*phi_deg/q[0]/q[1]+phase[2],
  96. l2_pos_x = l1_pos_x,
  97. l2_pos_y = (l1_pos_y+rad[2])*cos(l2_deg)-l1_pos_z*sin(l2_deg),
  98. l2_pos_z = (l1_pos_y+rad[2])*sin(l2_deg)+l1_pos_z*cos(l2_deg)
  99. )
  100. [l2_pos_x,
  101. l2_pos_y,
  102. l2_pos_z]
  103. ];
  104.  
  105. function quad_torus_knot(q, rad, dir, phase, phi_step, min_phi=0, max_phi=-1) =
  106. [
  107. for(phi = min_phi; phi < (max_phi == -1 ? 6.283185307179586*q[0]*q[1]*q[2] : max_phi) - 0.00001; phi = phi + phi_step)
  108. let(
  109. phi_deg = degrees(phi),
  110. l0_deg = -dir[0]*phi_deg+phase[0],
  111. l1_deg = phi_deg/q[0]+phase[1],
  112. l0_ratio_y_to_z = atan2((2*3.14159*rad[1]/q[1]),(2*3.14159*rad[2]/(q[1]*q[0]))),
  113. l0_pos_x = rad[0]*cos(l0_deg),
  114. //l0_pos_y = 0,
  115. l0_pos_y = -1*dir[1]*cos(l0_ratio_y_to_z)*rad[0]*sin(l0_deg),
  116. //l0_pos_z = rad[0]*sin(l0_deg),
  117. l0_pos_z = sin(l0_ratio_y_to_z)*rad[0]*sin(l0_deg),
  118. l1_ratio_x_to_z = atan2((2*3.14159*rad[2]/q[2]),(2*3.14159*rad[3]/(q[2]*q[1]))),
  119. //l1_pos_x = (l0_pos_x+rad[1])*cos(l1_deg)-l0_pos_y*sin(l1_deg),
  120. l1_pos_x = (l0_pos_x+rad[1]*sin(l1_ratio_x_to_z))*cos(l1_deg)-l0_pos_y*sin(l1_deg),
  121. l1_pos_y = (l0_pos_x+rad[1])*sin(l1_deg)+l0_pos_y*cos(l1_deg),
  122. //l1_pos_z = l0_pos_z,
  123. l1_pos_z = l0_pos_z+-1*dir[2]*rad[1]*cos(l1_ratio_x_to_z)*cos(l1_deg),
  124. l2_deg = dir[1]*phi_deg/q[0]/q[1]+phase[2],
  125. l2_pos_x = l1_pos_x,
  126. l2_pos_y = (l1_pos_y+rad[2])*cos(l2_deg)-l1_pos_z*sin(l2_deg),
  127. l2_pos_z = (l1_pos_y+rad[2])*sin(l2_deg)+l1_pos_z*cos(l2_deg),
  128. l3_deg = dir[1]*-dir[2]*phi_deg/q[0]/q[1]/q[2]+phase[3],
  129. l3_pos_x = l2_pos_x*cos(l3_deg)-(l2_pos_y+rad[3])*sin(l3_deg),
  130. l3_pos_y = l2_pos_x*sin(l3_deg)+(l2_pos_y+rad[3])*cos(l3_deg),
  131. l3_pos_z = l2_pos_z
  132. )
  133. [l3_pos_x,
  134. l3_pos_y,
  135. l3_pos_z]
  136. ];
  137.  
  138. module single_torus(q, rad_p, rad_c, dir, phase, show_cores, phi_step, base_seg) {
  139. wire_1_cross_section_radius = rad_c[0];
  140. wire_1_cross_section_pts = shape_circle(wire_1_cross_section_radius,$fn=base_seg*rad_p[0]);
  141. pts_1 = single_torus_knot(q, rad_p, dir, phase, phi_step*rad_p[0]);
  142. length = length_3d(pts_1);
  143. echo("Length Wire", length);
  144. echo("Approx Volume Wire (length*crosssection)", length*3.141592654*rad_c[0]^2);
  145. path_extrude(
  146. wire_1_cross_section_pts,
  147. [each pts_1, pts_1[0]],
  148. closed = true,
  149. twist = 0,
  150. method = "AXIS_ANGLE"
  151. );
  152. }
  153.  
  154.  
  155. module double_torus(q, rad_p, rad_c, dir, phase, show_cores, phi_step, base_seg) {
  156. wire_1_cross_section_radius = rad_c[0];
  157. wire_1_cross_section_pts = shape_circle(wire_1_cross_section_radius,$fn=base_seg*rad_p[0]);
  158. pts_1 = double_torus_knot(q, rad_p, dir, phase, phi_step*rad_p[0]);
  159. length = length_3d(pts_1);
  160. echo("Length Wire", length);
  161. echo("Approx Volume Wire (length*crosssection)", length*3.141592654*rad_c[0]^2);
  162. path_extrude(
  163. wire_1_cross_section_pts,
  164. [each pts_1, pts_1[0]],
  165. closed = true,
  166. twist = 0,
  167. method = "AXIS_ANGLE"
  168. );
  169. if (show_cores > 0) {
  170. wire_2_cross_section_radius = rad_c[1];
  171. wire_2_cross_section_pts = shape_circle(wire_2_cross_section_radius,$fn=base_seg*rad_p[1]);
  172. pts_2 = double_torus_knot(q, [0,rad_p[1]], dir, phase, phi_step*rad_p[1]);
  173. length = length_3d(pts_2);
  174. echo("Length Core 1", length);
  175. echo("Approx Volume Core 1 (length*crosssection)", length*3.141592654*rad_c[1]^2);
  176. color([1,0,0])
  177. path_extrude(
  178. wire_2_cross_section_pts,
  179. [each pts_2, pts_2[0]],
  180. closed = true,
  181. twist = 0,
  182. method = "AXIS_ANGLE"
  183. );
  184. }
  185. }
  186.  
  187.  
  188. module triple_torus(q, rad_p, rad_c, dir, phase, show_cores, phi_step, base_seg) {
  189. wire_1_cross_section_radius = rad_c[0];
  190. wire_1_cross_section_pts = shape_circle(wire_1_cross_section_radius,$fn=base_seg*rad_p[0]);
  191. pts_1 = triple_torus_knot(q, rad_p, dir, phase, phi_step*rad_p[0]);
  192. length = length_3d(pts_1);
  193. echo("Length Wire", length);
  194. echo("Approx Volume Wire (length*crosssection)", length*3.141592654*rad_c[0]^2);
  195. path_extrude(
  196. wire_1_cross_section_pts,
  197. [each pts_1, pts_1[0]],
  198. closed = true,
  199. twist = 0,
  200. method = "AXIS_ANGLE"
  201. );
  202. if (show_cores > 0) {
  203. wire_2_cross_section_radius = rad_c[1];
  204. wire_2_cross_section_pts = shape_circle(wire_2_cross_section_radius,$fn=base_seg*rad_p[1]);
  205. pts_2 = triple_torus_knot(q, [0,rad_p[1],rad_p[2]], dir, phase, phi_step*rad_p[1]);
  206. length = length_3d(pts_2);
  207. echo("Length Core 1", length);
  208. echo("Approx Volume Core 1 (length*crosssection)", length*3.141592654*rad_c[1]^2);
  209. color([1,0,0])
  210. path_extrude(
  211. wire_2_cross_section_pts,
  212. [each pts_2, pts_2[0]],
  213. closed = true,
  214. twist = 0,
  215. method = "AXIS_ANGLE"
  216. );
  217. if (show_cores > 1) {
  218. wire_3_cross_section_radius = rad_c[2];
  219. wire_3_cross_section_pts = shape_circle(wire_3_cross_section_radius,$fn=base_seg*rad_p[2]);
  220. pts_3 = triple_torus_knot(q, [0,0,rad_p[2]], dir, phase, phi_step*rad_p[2]);
  221. length = length_3d(pts_3);
  222. echo("Length Core 2", length);
  223. echo("Approx Volume Core 2 (length*crosssection)", length*3.141592654*rad_c[2]^2);
  224. color([0,1,0])
  225. path_extrude(
  226. wire_3_cross_section_pts,
  227. [each pts_3, pts_3[0]],
  228. closed = true,
  229. twist = 0,
  230. method = "AXIS_ANGLE"
  231. );
  232. }
  233. }
  234. }
  235.  
  236. module quad_torus(q, rad_p, rad_c, dir, phase, show_cores, phi_step, base_seg) {
  237. wire_1_cross_section_radius = rad_c[0];
  238. wire_1_cross_section_pts = shape_circle(wire_1_cross_section_radius,$fn=base_seg*rad_p[0]);
  239. pts_1 = quad_torus_knot(q, rad_p, dir, phase, phi_step*rad_p[0]);
  240. length = length_3d(pts_1);
  241. echo("Length Wire", length);
  242. echo("Approx Volume Wire (length*crosssection)", length*3.141592654*rad_c[0]^2);
  243. path_extrude(
  244. wire_1_cross_section_pts,
  245. [each pts_1, pts_1[0]],
  246. closed = true,
  247. twist = 0,
  248. method = "AXIS_ANGLE"
  249. );
  250. if (show_cores > 0) {
  251. wire_2_cross_section_radius = rad_c[1];
  252. wire_2_cross_section_pts = shape_circle(wire_2_cross_section_radius,$fn=base_seg*rad_p[1]);
  253. pts_2 = quad_torus_knot(q, [0,rad_p[1],rad_p[2],rad_p[3]], dir, phase, phi_step*rad_p[1]);
  254. length = length_3d(pts_2);
  255. echo("Length Core 1", length);
  256. echo("Approx Volume Core 1 (length*crosssection)", length*3.141592654*rad_c[1]^2);
  257. color([1,0,0])
  258. path_extrude(
  259. wire_2_cross_section_pts,
  260. [each pts_2, pts_2[0]],
  261. closed = true,
  262. twist = 0,
  263. method = "AXIS_ANGLE"
  264. );
  265. if (show_cores > 1) {
  266. wire_3_cross_section_radius = rad_c[2];
  267. wire_3_cross_section_pts = shape_circle(wire_3_cross_section_radius,$fn=base_seg*rad_p[2]);
  268. pts_3 = quad_torus_knot(q, [0,0,rad_p[2],rad_p[3]], dir, phase, phi_step*rad_p[2]);
  269. length = length_3d(pts_3);
  270. echo("Length Core 2", length);
  271. echo("Approx Volume Core 2 (length*crosssection)", length*3.141592654*rad_c[2]^2);
  272. color([0,1,0])
  273. path_extrude(
  274. wire_3_cross_section_pts,
  275. [each pts_3, pts_3[0]],
  276. closed = true,
  277. twist = 0,
  278. method = "AXIS_ANGLE"
  279. );
  280. if (show_cores > 2) {
  281. wire_4_cross_section_radius = rad_c[3];
  282. wire_4_cross_section_pts = shape_circle(wire_4_cross_section_radius,$fn=base_seg*rad_p[3]);
  283. pts_4 = quad_torus_knot(q, [0,0,0,rad_p[3]], dir, phase, phi_step*rad_p[3]);
  284. length = length_3d(pts_4);
  285. echo("Length Core 3", length);
  286. echo("Approx Volume Core 3 (length*crosssection)", length*3.141592654*rad_c[3]^2);
  287. color([0,0,1])
  288. path_extrude(
  289. wire_4_cross_section_pts,
  290. [each pts_4, pts_4[0]],
  291. closed = true,
  292. twist = 0,
  293. method = "AXIS_ANGLE"
  294. );
  295. }
  296. }
  297. }
  298. }
  299.  
  300. module triple_torus_winding_prop_sub(q, rad_p, rad_c, dir, phase, phi_step, base_seg, hollow_core) {
  301. wire_2_cross_section_radius = rad_c[1]+2*rad_c[0];
  302. wire_2_cross_section_pts = shape_circle(wire_2_cross_section_radius,$fn=base_seg*rad_p[0]);
  303. pts_2 = double_torus_knot([q[1]], [rad_p[1],rad_p[2]], [dir[1]], [phase[1],phase[2]], phi_step);
  304. wire_3_cross_section_radius = rad_c[2]+1*rad_c[1]+1*rad_c[0]; // use 3*rad_c[0] so we get some grip...
  305. wire_3_cross_section_pts = shape_circle(wire_3_cross_section_radius,$fn=base_seg*rad_p[1]);
  306. hollow_core_cross_section_pts = shape_circle(hollow_core,$fn=base_seg*rad_p[1]);
  307. pts_3 = double_torus_knot([q[1]], [0,rad_p[2]], [dir[1]], [phase[1],phase[2]], phi_step*rad_p[1], max_phi=6.283185307179586*q[1]);
  308. difference() {
  309. union() {
  310. path_extrude(
  311. wire_3_cross_section_pts,
  312. [each pts_3, pts_3[0]],
  313. closed = true,
  314. method = "AXIS_ANGLE"
  315. );
  316. }
  317. union() {
  318. path_extrude(
  319. wire_2_cross_section_pts,
  320. [each pts_2, pts_2[0]],
  321. closed = true,
  322. method = "AXIS_ANGLE"
  323. );
  324. if (hollow_core > 0) {
  325. path_extrude(
  326. hollow_core_cross_section_pts,
  327. [each pts_3, pts_3[0]],
  328. closed = true,
  329. method = "AXIS_ANGLE"
  330. );
  331. }
  332. }
  333. }
  334. }
  335.  
  336. module triple_torus_winding_prop(q, rad_p, rad_c, dir, phase, phi_step, base_seg, split_half=0, split_quarter=0, gap=0, hollow_core=0) {
  337. difference() {
  338. union() {
  339. triple_torus_winding_prop_sub(q, rad_p, rad_c, dir, phase, phi_step, base_seg, hollow_core);
  340. }
  341. union() {
  342. if (gap > 0) {
  343. translate([0,-gap/2,-2*rad_p[2]])
  344. cube([2*rad_p[2],gap,4*rad_p[2]]);
  345. }
  346. if (split_half > 0) {
  347. translate([-2*rad_p[2],-2*rad_p[2],-ovr/2])
  348. cube([4*rad_p[2],4*rad_p[2],ovr]);
  349. }
  350. if (split_quarter > 0) {
  351. translate([-ovr/2,-2*rad_p[2],-2*rad_p[2]])
  352. cube([ovr,4*rad_p[2],4*rad_p[2]]);
  353. translate([-2*rad_p[2],-ovr/2,-2*rad_p[2]])
  354. cube([4*rad_p[2],ovr,4*rad_p[2]]);
  355. }
  356. }
  357. }
  358. }
  359.  
  360. module quad_torus_winding_prop(q, rad_p, rad_c, dir, phase, phi_step, base_seg, key_size_multiplier=1, key_size_tolerance=0.2, segments=1) {
  361. wire_2_cross_section_radius = rad_c[1]+2*rad_c[0];
  362. wire_2_cross_section_pts = shape_circle(wire_2_cross_section_radius,$fn=base_seg*rad_p[0]);
  363. wire_3_cross_section_radius = rad_c[2]+1*rad_c[1]+3*rad_c[0]; // use 3*rad_c[0] so we get some grip...
  364. wire_3_cross_section_pts = shape_circle(wire_3_cross_section_radius,undef,undef,$fn=base_seg*rad_p[1]);
  365. pts_3 = triple_torus_knot([q[1],q[2]], [0,rad_p[2],rad_p[3]], [dir[1],dir[2]], [phase[1],phase[2],phase[3]], phi_step, min_phi=0, max_phi=6.283185307179586*segments*q[1]);
  366. difference() {
  367. union() {
  368. if (q[2] == segments) {
  369. path_extrude(
  370. wire_3_cross_section_pts,
  371. [each pts_3, pts_3[0]],
  372. closed = true,
  373. method = "AXIS_ANGLE"
  374. );
  375. }
  376. else {
  377. path_extrude(
  378. wire_3_cross_section_pts,
  379. [each pts_3],
  380. method = "AXIS_ANGLE"
  381. );
  382. }
  383. if (key_size_multiplier > 0) {
  384. translate([rad_p[2],rad_p[3],0])
  385. rotate([45/q[2]*4,0,0])
  386. cube([2*rad_c[2]/3*key_size_multiplier-key_size_tolerance,4*rad_c[2]/3*key_size_multiplier-key_size_tolerance,2*rad_c[2]/3*key_size_multiplier-key_size_tolerance], center=true);
  387. }
  388. }
  389. union() {
  390. if (q[2] == segments) {
  391. pts_2 = triple_torus_knot([q[1],q[2]], [rad_p[1],rad_p[2],rad_p[3]], [dir[1],dir[2]], [phase[1],phase[2],phase[3]], phi_step, min_phi=0, max_phi=6.283185307179586*segments*q[1]);
  392. path_extrude(
  393. wire_2_cross_section_pts,
  394. [each pts_2, pts_2[0]],
  395. closed = true,
  396. method = "AXIS_ANGLE"
  397. );
  398. }
  399. else {
  400. pts_2 = triple_torus_knot([q[1],q[2]], [rad_p[1],rad_p[2],rad_p[3]], [dir[1],dir[2]], [phase[1],phase[2],phase[3]], phi_step, min_phi=-6.283185307179586, max_phi=6.283185307179586*(segments+0.5)*q[1]);
  401. path_extrude(
  402. wire_2_cross_section_pts,
  403. [each pts_2],
  404. method = "AXIS_ANGLE"
  405. );
  406. }
  407. if (key_size_multiplier > 0) {
  408. rotate([segments*360/q[2],0,0])
  409. translate([rad_p[2],rad_p[3],0])
  410. rotate([45/q[2]*4,0,0])
  411. cube([2*rad_c[2]/3*key_size_multiplier,4*rad_c[2]/3*key_size_multiplier,2*rad_c[2]/3*key_size_multiplier], center=true);
  412. }
  413. }
  414. }
  415. }
  416.  
  417. module quad_torus_winding_prop_v2(q, rad_p, rad_c, dir, phase, phi_step, base_seg, split_half=0, split_quarter=0, gap=0, hollow_core=0) {
  418. wire_2_cross_section_radius = rad_c[1]+3*rad_c[0]; // we enlarge these slightly to accomodate for slop
  419. wire_2_cross_section_pts = shape_circle(wire_2_cross_section_radius,$fn=base_seg*rad_p[0]);
  420. pts_2 = triple_torus_knot([q[1],q[2]], [rad_p[1],rad_p[2],rad_p[3]], [dir[1],dir[2]], [phase[1],phase[2],phase[3]], phi_step*rad_p[0], max_phi=6.283185307179586*q[1]*q[2]);
  421. wire_3_cross_section_radius = rad_c[2]+1.5*rad_c[1]; // if you want full top level grooves (rad_c[2]+2*rad_c[1]) but we want partial secondary groves visible so (rad_c[2]+1.5*rad_c[1])
  422. wire_3_cross_section_pts = shape_circle(wire_3_cross_section_radius,$fn=base_seg*rad_p[1]);
  423. pts_3 = triple_torus_knot([q[1],q[2]], [0,rad_p[2],rad_p[3]], [dir[1],dir[2]], [phase[1],phase[2],phase[3]], phi_step*rad_p[1], max_phi=6.283185307179586*q[1]*q[2]);
  424. wire_4_cross_section_radius = rad_c[3]+1*rad_c[2]+1*rad_c[1]; // use 3*rad_c[1] so we get some grip...
  425. wire_4_cross_section_pts = shape_circle(wire_4_cross_section_radius,$fn=base_seg*rad_p[2]);
  426. hollow_core_cross_section_pts = shape_circle(hollow_core,$fn=base_seg*rad_p[2]);
  427. pts_4 = triple_torus_knot([q[1],q[2]], [0,0,rad_p[3]], [dir[1],dir[2]], [phase[1],phase[2],phase[3]], phi_step*rad_p[2], max_phi=6.283185307179586*q[1]*q[2]);
  428. difference() {
  429. union() {
  430. path_extrude(
  431. wire_4_cross_section_pts,
  432. [each pts_4, pts_4[0]],
  433. closed = true,
  434. method = "AXIS_ANGLE"
  435. );
  436. }
  437. union() {
  438. path_extrude(
  439. wire_3_cross_section_pts,
  440. [each pts_3, pts_3[0]],
  441. closed = true,
  442. method = "AXIS_ANGLE"
  443. );
  444. path_extrude(
  445. wire_2_cross_section_pts,
  446. [each pts_2],
  447. closed = false,
  448. method = "AXIS_ANGLE"
  449. );
  450. if (gap > 0) {
  451. translate([-2*rad_p[3],-gap/2,0])
  452. cube([4*rad_p[3],gap,2*rad_p[3]]);
  453. }
  454. if (split_half > 0) {
  455. translate([-ovr/2,-2*rad_p[3],-2*rad_p[3]])
  456. cube([ovr,4*rad_p[3],4*rad_p[3]]);
  457. }
  458. if (split_quarter > 0) {
  459. translate([-2*rad_p[3],-2*rad_p[3],-ovr/2])
  460. cube([4*rad_p[3],4*rad_p[3],ovr]);
  461. translate([-2*rad_p[3],-ovr/2,-2*rad_p[3]])
  462. cube([4*rad_p[3],ovr,4*rad_p[3]]);
  463. }
  464. if (hollow_core > 0) {
  465. path_extrude(
  466. hollow_core_cross_section_pts,
  467. [each pts_4, pts_4[0]],
  468. closed = true,
  469. method = "AXIS_ANGLE"
  470. );
  471. }
  472. }
  473. }
  474. }
  475.  
  476. /**
  477. * Coil Sample Parameters
  478. * q - number of loops per level
  479. * rad_p - radius of torus center line per level (this is used for positioning of the wire and cores relative to the center of each parent flux loop)
  480. * rad_c - radius of wire/cores (this is used for the wire/core model radius)
  481. * dir - rotation direction 1 clockwise (right-handed?), -1 counter-clockwise (left-handed?)
  482. * phase - the phase angle to start each winding at (default should be 0 for each level) (there is an example below that illustrates how this can be used to align a model coil to a winding prop)
  483. * show_cores - number of cores to show
  484. * phi_step - length of longitudinal wire segment in radians (this is then multiplied by the rad_p radius to reduce data in cores)
  485. * base_seg - segments for wire diameter (this is then multiplied by the rad_p radius to reduce data in cores)
  486. **/
  487.  
  488. // D-4D
  489. //single_torus([], [2-0.5], [0.5], [], [0], 0, 6.283185307179586/20, 40);
  490. //double_torus([12], [2-0.5,8-2], [0.5,1], [1], [0,0], 1, 6.283185307179586/20, 20);
  491. //quad_torus([12,18,24], [2-0.5,8-2,32-8,128-32], [0.5,1,4,16], [1,1,1], [0,0,0,0], 3, 6.283185307179586/20, 10);
  492. //quad_torus([24,24,24], [2-0.5,8-2,32-8,128-32], [0.5,1,4,16], [1,1,1], [0,0,0,0], 3, 6.283185307179586/20, 10);
  493.  
  494. // Other Dimensions
  495. //quad_torus([10,10,10], [1.15,4,10.5,28], [0.5,1,4,16], [1,1,1], [0,0,0,0], 0, 6.283185307179586/20, 10); // this is designed to be printed more affordably in metal
  496. //triple_torus([8,8], [2-0.5,8-2,32-8], [0.5,1,4], [1,1], [0,0,0], 2, 6.283185307179586/20, 20);
  497. //quad_torus([8,8,8], [2-0.5,8-2,32-8,128-32], [0.5,1,4,16], [1,1,1], [0,0,0,0], 3, 6.283185307179586/20, 10);
  498. //quad_torus([8,8,8], [2-0.5,8-2,32-8,128-32], [0.5,1,4,16], [1,1,1], [0,0,0,0], 3, 6.283185307179586/20, 10);
  499.  
  500. /**
  501. * Winding Prop Sample Parameters
  502. * takes the same parameters as coil sample parameters in addition to those specified below
  503. *
  504. * triple_torus_winding_mold
  505. * split_half - split the torus in half so it can be printed without supports and joined later (0 - no split, 1 - split) (default 0)
  506. * split_quarter - split the torus in quarters so it can be printed on printers with small build plates (0 - no split, 1 - split) (default 0)
  507. * gap - the gap to leave through which your wire coil can be fed (0 - no gap, # - gap size) (default 0)
  508. * hollow_core - the radius of hollow core (0 - no hollow core, # - radius size)
  509. *
  510. * quad_torus_winding_prop_v2
  511. * split_half - split the torus in half so it can be printed without supports and joined later (0 - no split, 1 - split) (default 0)
  512. * split_quarter - split the torus in quarters so it can be printed on printers with small build plates (0 - no split, 1 - split) (default 0)
  513. * gap - the gap to leave through which your wire coil can be fed (0 - no gap, # - gap size) (default 0)
  514. * hollow_core - the radius of hollow core (0 - no hollow core, # - radius size)
  515. *
  516. * quad_torus_winding_prop
  517. * key_size_multiplier - a multiplier to control the size of the key used to connect together segments (set to 0 if you don't want any key) (default 1)
  518. * key_size_tolerance - the difference in size between the key hole and key protrusion (default 0.2)
  519. * segments - how many segments to generate in one chunk (the more segments you have in a chunk the more times you need to thread your coiled wire through as you wind it) (default 1)
  520. *
  521. **/
  522.  
  523. // D-4D
  524. //triple_torus_winding_prop([12,18], [2-0.5,8-2,32-8], [0.5,1,4], [1,1], [0,0,0], 6.283185307179586/20, 20, split_half=1, split_quarter=0, gap=6, hollow_core=3);
  525. //quad_torus_winding_prop([12,18,24], [2-0.5,8-2,32-8,128-32], [0.5,1,4,16], [1,1,1], [0,0,0,0], 6.283185307179586/20, 10, key_size_multiplier=1.5, key_size_tolerance=0.2, segments=4);
  526. //quad_torus_winding_prop([24,24,24], [2-0.5,8-2,32-8,128-32], [0.5,1,4,16], [1,1,1], [0,0,0,0], 6.283185307179586/20, 10, key_size_multiplier=1.5, key_size_tolerance=0.2, segments=6);
  527.  
  528. // Other Examples
  529. //quad_torus_winding_prop([24,24,24+1], [2-0.5,8-2,32-8,(128-32)/24*25], [0.5,1,4,16], [1,1,1], [0,0,0,0], 6.283185307179586/20, 10, key_size_multiplier=1.5, key_size_tolerance=0.2, segments=24); // this is the same as the D-4D one but a full ring of 24 segments but then spread by an extra segment (with increased radius so that it is easy to thread the wire through then glue it closed after. This is possible because most filaments are flexible.
  530.  
  531. // Example showing alignment of model coil to winding prop
  532. //quad_torus_winding_prop([12,18,24], [2-0.5,8-2,32-8,128-32], [0.5,1,4,16], [1,1,1], [0,0,0,0], 6.283185307179586/20, 10, key_size_multiplier=1.5, key_size_tolerance=0.2, segments=24); // this is an example showing what happens when you specify parameters that should generated a closed loop with no cut
  533. //rotate([360/(24*4),0,0])rotate([0,-90,0])quad_torus([12,18,24], [2-0.5,8-2,32-8,128-32], [0.5,1,4,16], [1,1,1], [0,-90,0,0], 1, 6.283185307179586/20, 10); // this is the wire coil for the above winding prop
  534.  
  535.  
  536.  
  537.  
  538. // My personal 24(approx)x24x24 build
  539. //triple_torus_winding_prop([24,24], [(18-4.75)/2,(72-18)/2,(288-72)/2], [4.75/2,4.5,18], [1,1], [0,0,0], 6.283185307179586/50, 10, split_half=1, split_quarter=1, gap=6, hollow_core=16);
  540. //quad_torus_winding_prop([24,24,24], [(4.75-1.0)/2,(18-4.75)/2,(72-18)/2,(288-72)/2], [0.5,1,4.5,18], [1,1,1], [0,0,0,0], 6.283185307179586/40, 20, key_size_multiplier=1.5, key_size_tolerance=0.2, segments=4);
  541.  
  542. //triple_torus([24,24], [(18-4.75)/2,(72-18)/2,(288-72)/2], [4.75/2,4.5,18], [1,1], [0,0,0], 1, 6.283185307179586/200, 2);
  543. quad_torus([24,24,24], [(4.75-1.0)/2,(18-4.75)/2,(72-18)/2,(288-72)/2], [0.5,1,4.5,18], [1,1,1], [0,0,0,0], 2, 6.283185307179586/20, 5);
  544.  
  545. // main v2 quad torus prop with holes
  546. /*
  547. difference() {
  548. union() {
  549. // low poly
  550. //quad_torus_winding_prop_v2([24,24,24], [(4.75-1.0)/2,(18-4.75)/2,(72-18)/2,(288-72)/2], [0.5,1,4.5,18], [1,1,1], [0,0,0,0], 6.283185307179586/10, 4, split_half=1, split_quarter=1, gap=0, hollow_core=16);
  551. // medium poly
  552. quad_torus_winding_prop_v2([24,24,24], [(4.75-1.0)/2,(18-4.75)/2,(72-18)/2,(288-72)/2], [0.5,1,4.5,18], [1,1,1], [0,0,0,0], 6.283185307179586/20, 8, split_half=1, split_quarter=1, gap=0, hollow_core=16);
  553. // high poly
  554. //quad_torus_winding_prop_v2([24,24,24], [(4.75-1.0)/2,(18-4.75)/2,(72-18)/2,(288-72)/2], [0.5,1,4.5,18], [1,1,1], [0,0,0,0], 6.283185307179586/80, 20, split_half=1, split_quarter=1, gap=0, hollow_core=16);
  555. }
  556. union() {
  557. water_tube_hole_diameter = 16;
  558. //for (rx = [-1/4*360/24, 3/4*360/24]) {
  559. for (rx = [-5/4*360/24, 3/4*360/24]) {
  560. rotate([rx,0,0])
  561. translate([0,0,(288-72)/2])
  562. cylinder(72,water_tube_hole_diameter/2,water_tube_hole_diameter/2);
  563. }
  564. }
  565. }
  566. //*/
  567. // external tube brace to assist with winding around v2 quad torus prop
  568. /*
  569. difference() {
  570. wire_2a_cross_section_pts = shape_circle(74/2,$fn=32);
  571. wire_2b_cross_section_pts = shape_circle(73.5/2,$fn=32);
  572. pts_2a = triple_torus_knot([24,24], [0,0,(288-72)/2], [1,1], [0,0,0], (6.283185307179586/10)*((4.75-1.0)/2), min_phi=0.01, max_phi=6.283185307179586*24*1.5);
  573. pts_2b = triple_torus_knot([24,24], [0,0,(288-72)/2], [1,1], [0,0,0], (6.283185307179586/10)*((4.75-1.0)/2), min_phi=0, max_phi=6.283185307179586*24*1.5+0.01);
  574. union() {
  575. path_extrude(
  576. wire_2a_cross_section_pts,
  577. [each pts_2a],
  578. closed = false,
  579. method = "AXIS_ANGLE"
  580. );
  581. }
  582. union() {
  583. path_extrude(
  584. wire_2b_cross_section_pts,
  585. [each pts_2b],
  586. closed = false,
  587. method = "AXIS_ANGLE"
  588. );
  589. }
  590. }
  591. //*/
  592.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement