honey-test.scad 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // Honeycomb
  2. //
  3. // A simple script to easily create different honeycomb structures of varying size, number of cells, and convexity
  4. // R = radius, outer radius of a cicle enclosing the cross-section hexagon
  5. // Radius reaches to the outer vertices of the hexagon
  6. //
  7. // H = height, the height of the honeycomb structure
  8. // t = thickness, the wall thickness
  9. module honeycombCell(R, H, t, fill=false) {
  10. // Length of the inner vertex to the outer vertex
  11. T = t / cos(30);
  12. // Create one cell and orient it
  13. rotate([0,0,90])
  14. difference(){
  15. cylinder(r=R, h=H, center=false, $fn=6);
  16. if (fill==false) {
  17. translate([0,0,-1])
  18. cylinder(r=(R - T), h=(H + 2), center=false, $fn=6);
  19. }
  20. }
  21. }
  22. // R = radius, outer radius of a cicle enclosing the cross-section hexagon
  23. // Radius reaches to the outer vertices of the hexagon
  24. // H = height, the height of the honeycomb structure
  25. // t = thickness, the wall thickne
  26. // X = the number of cells in the X-direction
  27. // Y = the number of cells in the Y-direction
  28. // C = convexity: concave, convex, or stagger
  29. // Center of first cell is centered on origin (0, 0)
  30. // Structure expands in +X direction, then +Y direction
  31. module honeycombStructure(R, H, t, X, Y, C, fill=false) {
  32. // Length of inner vertex to outer vertex
  33. T = t / cos(30);
  34. // Distance to translate cells in the X direction
  35. lx = 2*(R-T/2)*cos(30);
  36. // Distance to translate cells in the Y direction
  37. ly = 3*(R-T/2)*cos(60);
  38. union(){
  39. // Y (# in col direction)
  40. for (i = [0:1:Y-1]) {
  41. // X (# in row direction)
  42. // For Concave, Every odd row has 1 fewer cells (first row is even)
  43. if (C=="concave"){
  44. // Even rows, create X cells
  45. if (i % 2 == 0) {
  46. for (ii = [0:1:X-1]) {
  47. translate([ii*lx, i*ly, 0])
  48. honeycombCell(R, H, t, fill);
  49. }
  50. }
  51. // Odd rows, create X-1 cells
  52. else if (i % 2 == 1) {
  53. for (ii = [0:1:X-2]) {
  54. translate([ii*lx + lx/2, i*ly, 0])
  55. honeycombCell(R, H, t, fill);
  56. }
  57. }
  58. }
  59. // For stagger, every row has the same number of cells, giving a "staggered" look
  60. else if (C=="stagger"){
  61. // Even rows, create X cells
  62. if (i % 2 == 0) {
  63. for (ii = [0:1:X-1]) {
  64. translate([ii*lx, i*ly, 0])
  65. honeycombCell(R, H, t, fill);
  66. }
  67. }
  68. // Odd rows, create X cells
  69. else if (i % 2 == 1) {
  70. for (ii = [0:1:X-1]) {
  71. translate([ii*lx + lx/2, i*ly, 0])
  72. honeycombCell(R, H, t, fill);
  73. }
  74. }
  75. }
  76. // For Convex, every odd row has 1 extra cell to fill both sides (first row is even)
  77. else if (C=="convex"){
  78. // Even rows, create X cells
  79. if (i % 2 == 0) {
  80. for (ii = [0:1:X-1]) {
  81. translate([ii*lx, i*ly, 0])
  82. honeycombCell(R, H, t, fill);
  83. }
  84. }
  85. // Odd rows, create X+1 cells
  86. else if (i % 2 == 1) {
  87. for (ii = [0:1:X]) {
  88. translate([ii*lx-lx/2, i*ly, 0])
  89. honeycombCell(R, H, t, fill);
  90. }
  91. }
  92. }
  93. else {
  94. // ???
  95. }
  96. }
  97. }
  98. }
  99. // Example 1
  100. honeycombStructure(10,10,2,2,3,"convex", fill=true);
  101. // Example 2
  102. translate([60,0,0])
  103. honeycombStructure(20,20,4,5,3,"concave");
  104. // Example 3
  105. translate([0,80,0])
  106. honeycombStructure(5,5,1,3,5,"stagger");