splited.scad 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. include <../config/splited.scad>
  2. module splited_object() {
  3. width = splited_width;
  4. height = splited_height;
  5. depth = splited_depth;
  6. thickness = splited_thickness;
  7. hole_top_diameter = splited_hole_top_diameter;
  8. hole_bottom_diameter = splited_hole_bottom_diameter;
  9. holes_top_count = splited_holes_top_count;
  10. holes_bottom_count = splited_holes_bottom_count;
  11. module splited_cross_section(full = true) {
  12. module points(top = false) {
  13. radius = thickness / 2;
  14. move_x = depth / 2 - radius;
  15. move_y = height / 2 - radius;
  16. module point(x = 0, y = 0) {
  17. translate([x, y]) {
  18. circle(r = radius);
  19. }
  20. }
  21. hull() {
  22. if (top) {
  23. point(move_x, move_y);
  24. point(-move_x, move_y);
  25. } else {
  26. point(-move_x, -move_y);
  27. point(-move_x, move_y);
  28. }
  29. }
  30. }
  31. if (full) {
  32. hull() {
  33. points(top = true);
  34. points(top = false);
  35. }
  36. } else {
  37. points(top = true);
  38. points(top = false);
  39. }
  40. }
  41. module center_section() {
  42. linear_extrude(height = thickness, center = true) {
  43. splited_cross_section(full = true);
  44. }
  45. }
  46. module rest_section() {
  47. linear_extrude(height = width, center = true) {
  48. splited_cross_section(full = false);
  49. }
  50. }
  51. module holes(size, height, count, top = false) {
  52. move = size / count;
  53. for (count = [-size / 2 : move : size / 2 - move / 2]) {
  54. translate([count + move / 2, 0]) {
  55. linear_extrude(height = height, center = true) {
  56. if (top) {
  57. circle(d = hole_top_diameter);
  58. } else {
  59. circle(d = hole_bottom_diameter);
  60. }
  61. }
  62. }
  63. }
  64. }
  65. module holes_height() {
  66. module single() {
  67. rotate([90, 0, 90]) {
  68. holes(
  69. size = height - thickness * 2,
  70. height = depth,
  71. count = holes_bottom_count,
  72. top = false
  73. );
  74. }
  75. }
  76. move = (width + thickness) / 4;
  77. translate([0, 0, move]) {
  78. single();
  79. }
  80. translate([0, 0, -move]) {
  81. single();
  82. }
  83. }
  84. module holes_depth() {
  85. module single() {
  86. rotate([90, 0, 0]) {
  87. holes(
  88. size = depth - thickness * 2,
  89. height = depth,
  90. count = holes_top_count,
  91. top = true
  92. );
  93. }
  94. }
  95. move = (width + thickness) / 4;
  96. translate([0, 0, move]) {
  97. single();
  98. }
  99. translate([0, 0, -move]) {
  100. single();
  101. }
  102. }
  103. module final() {
  104. render() {
  105. difference() {
  106. union() {
  107. center_section();
  108. rest_section();
  109. }
  110. holes_height();
  111. holes_depth();
  112. }
  113. }
  114. }
  115. color("#404040") {
  116. final();
  117. }
  118. }