From 0d7835f7094ec08ba808b49b557b23d8865f42ee Mon Sep 17 00:00:00 2001 From: Matthew Baggett Date: Sun, 26 Sep 2021 18:08:35 +0200 Subject: [PATCH] Added hex grid generation code --- hexgrid.scad | 20 ++++++++++++++++++++ mattlib.scad | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 hexgrid.scad diff --git a/hexgrid.scad b/hexgrid.scad new file mode 100644 index 0000000..3df8e2c --- /dev/null +++ b/hexgrid.scad @@ -0,0 +1,20 @@ +module hexGrid(fillRatio=0.5, gridSize=10, height=1, center=false, rows=3, columns=4) { + colMulti = 0.752; + rowMulti = 0.86; + offset = [ + (gridSize*colMulti)*((columns-1)/2), + (gridSize*rowMulti)*((rows-.5)/2), + 0] * -1; + translate(offset){ + for(row= [0:rows-1]){ + translate([0,gridSize*row*rowMulti,0]) + for(col=[0:columns-1]){ + translate([gridSize*col*colMulti,col%2?(gridSize*rowMulti)/2:0,0]) + cylinder(h=height,d=gridSize*fillRatio, $fn=6, center=center); + } + + } + } +} + +hexGrid(fillRatio=0.8, gridSize=10, height=10, center=false); \ No newline at end of file diff --git a/mattlib.scad b/mattlib.scad index 2565d75..d841753 100644 --- a/mattlib.scad +++ b/mattlib.scad @@ -4,4 +4,5 @@ include <../Lib/mirrorcopy.scad>; include <../Lib/extrusion.scad>; include <../Lib/pcd.scad>; include <../Lib/metric_bolts.scad>; -include <../Lib/corner_radiuser.scad>; \ No newline at end of file +include <../Lib/corner_radiuser.scad>; +include <../Lib/hexgrid.scad>; \ No newline at end of file