honeycomb.scad 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * Honeycomb library
  3. * License: Creative Commons - Attribution
  4. * Copyright: Gael Lafond 2017
  5. * URL: https://www.thingiverse.com/thing:2484395
  6. *
  7. * Inspired from:
  8. * https://www.thingiverse.com/thing:1763704
  9. */
  10. // parametric honeycomb
  11. module honeycomb(x, y, dia, wall, whole_only=false) {
  12. // Diagram
  13. // ______ ___
  14. // / /\ |
  15. // / dia / \ | smallDia
  16. // / / \ _|_
  17. // \ / ____
  18. // \ / /
  19. // ___ \______/ /
  20. // wall | /
  21. // _|_ ______ \
  22. // / \ \
  23. // / \ \
  24. // |---|
  25. // projWall
  26. //
  27. // a single filled hexagon
  28. module hexagon(xoff, yoff) {
  29. radius = dia / 2;
  30. if (
  31. !whole_only || (
  32. (xoff - radius >= -x/2 && xoff + radius <= x/2)
  33. && (yoff - radius >= -y/2 && yoff + radius <= y/2)
  34. )
  35. ) {
  36. translate([xoff, yoff])
  37. circle(d=dia, $fn=6);
  38. }
  39. }
  40. smallDia = dia * cos(30);
  41. projWall = wall * cos(30);
  42. yStep = smallDia + wall;
  43. xStep = dia*3/2 + projWall*2;
  44. yStepsCount = ceil((y/2) / yStep);
  45. xStepsCount = ceil((x/2) / xStep);
  46. difference() {
  47. square([x, y]);
  48. translate([x/2, y/2])
  49. for (
  50. yOffset = [-yStep * yStepsCount : yStep : yStep * yStepsCount],
  51. xOffset = [-xStep * xStepsCount : xStep : xStep * xStepsCount]
  52. ) {
  53. hexagon(xOffset, yOffset);
  54. hexagon(xOffset + dia*3/4 + projWall, yOffset + (smallDia+wall)/2);
  55. }
  56. }
  57. }