Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Parameters
- radi = 37 / 2;
- thickness = 4; // Thickness of the frame posts
- radius = radi + thickness ; // Distance from center to a vertex - divided by 2 cause spud
- radialfix = radius / 2; // yeah I should have used diameter...
- height = 33; // Height of each prism
- base_plate_thickness = .5; // ?? Thickness of the optional base plate fill
- stack_height = 3; // Number of hexagons in the vertical stack
- inner_hole_radius = radius / 1.5; // Radius of the hexagon hole in the base - divided by 2 cause spud
- slant_deg = 500; // Slant in degrees
- slant_rad = slant_deg * PI / 180;
- slant_test= 20 / PI * 180;
- additional_stack_offset = radialfix + radius;
- offsetpile = stack_height;
- // Base module flag
- add_base_fill = true; // Set to true to add filled base hexagons
- cut_height = height; // Height at which to cut the base hexagons
- // X-Axis Cut parameters
- perform_x_cut = true; // Set to true to perform the X-axis cut
- x_cut_width = radius * 6; // Width of the central cut
- x_cut_depth = height * 3; // Depth of the cut
- x_cut_position = radius; // Position of the cut center
- // Function to generate hexagon vertices with optional slant
- function hexagon_vertices(r, z, slant = 0, h = 0) =
- let(slant_y = tan(slant) * h)
- [
- for (angle = [0:60:300])
- z == 0 ?
- [r * cos(angle), r * sin(angle), z] :
- [r * cos(angle), r * sin(angle) + slant_y, z ]
- ];
- // Create a connecting post between two points
- module frame_post(p1, p2, d) {
- hull() {
- translate(p1) cube(d/1.5);
- translate(p2) cube(d/1.5);
- }
- }
- module frame_post_l(p1, p2, d, faces = 3) {
- hull() {
- // First cylinder at position p1 (align it to the corner of the square)
- translate([p1[0] + d/3, p1[1] + d/3, p1[2]]) // Shift in the XY plane to align with the corner
- cylinder(h = d/1.5, r = d/2, $fn = faces, center = false);
- // Second cylinder at position p2 (align it to the corner of the square)
- translate([p2[0] + d/3, p2[1] + d/3, p2[2]]) // Shift in the XY plane to align with the corner
- cylinder(h = d/1.5, r = d/2, $fn = faces, center = false);
- }
- }
- // Solid hexagonal prism - used for base fill
- module solid_hex_prism(r, h, slant = 0) {
- top_verts = hexagon_vertices(r, h, slant, h);
- bottom_verts = hexagon_vertices(r, 0);
- // Create faces using polyhedron
- faces = [
- // Bottom face
- [0, 1, 2, 3, 4, 5],
- // Top face
- [11, 10, 9, 8, 7, 6],
- // Side faces
- [0, 6, 7, 1],
- [1, 7, 8, 2],
- [2, 8, 9, 3],
- [3, 9, 10, 4],
- [4, 10, 11, 5],
- [5, 11, 6, 0]
- ];
- points = concat(bottom_verts, top_verts);
- polyhedron(points = points, faces = faces, convexity = 10);
- }
- // Hexagonal frame with optional base plate fill
- module hexagonal_prism_frame(r, h, d, slant = 0, fill_base=false, inner_hole_r=4, plate_thickness=2) {
- top_verts = hexagon_vertices(r, h, slant, h); // slanted top
- bottom_verts = hexagon_vertices(r, 0); // flat base
- // Connect vertical edges
- for (i = [0:5]) {
- frame_post_l(top_verts[i], bottom_verts[i], d);
- }
- // Connect top and bottom hexagon edges
- for (i = [0:5]) {
- frame_post(top_verts[i], top_verts[(i+1)%6], d);
- frame_post(bottom_verts[i], bottom_verts[(i+1)%6], d);
- }
- // Optional base fill
- if (fill_base) {
- translate([0, 0, 0])
- base_hex_plate(r, inner_hole_r, plate_thickness);
- }
- }
- // Flat hexagonal base with central hexagonal hole, level with bottom verts
- module base_hex_plate(outer_radius, inner_radius, plate_thickness) {
- translate([0, thickness / 2, 0]) // Top aligns with z = 0
- difference() {
- // Outer solid hexagon
- linear_extrude(height = base_plate_thickness)
- polygon(points = [
- for (angle = [0:60:300])
- [outer_radius * cos(angle), outer_radius * sin(angle)]
- ]);
- // Inner hole (hexagon)
- translate([0, 0, -0.1]) // Slight offset for clean cut
- linear_extrude(height = plate_thickness + 0.2)
- polygon(points = [
- for (angle = [0:60:300])
- [inner_radius * cos(angle), inner_radius * sin(angle)]
- ]);
- }
- }
- module vertical_stack(r, h, d, n, x_offset, y_offset, slant = 0, fill_base=false, plate_thickness=2, is_first_row=false, stack_index=0) {
- spacing_y = 2 * r - d; // Y distance between prism centers so posts align
- // Generate prism frames
- for (i = [0:n-1]) {
- y_pos = y_offset + i * spacing_y;
- translate([x_offset, y_pos, 0])
- hexagonal_prism_frame(r, h, d, slant, fill_base, inner_hole_radius, plate_thickness);
- }
- // --- Base fill behavior split ---
- if (add_base_fill) {
- // Fill current stack only if its index is odd (1, 3, 5...)
- if (stack_index % 2 == 1) {
- translate([x_offset, y_offset, thickness / 2]) {
- difference() {
- solid_hex_prism(r, h, slant);
- translate([-r*2, -r*2, cut_height])
- cube([r*4, r*4, h]);
- }
- }
- }
- // Always backfill staggered row behind
- if (!is_first_row) {
- translate([x_offset, y_offset - spacing_y + thickness / 2, thickness / 2]) {
- difference() {
- solid_hex_prism(r, h, slant);
- translate([-r*2, -r*2, cut_height])
- cube([r*4, r*4, h]);
- }
- }
- }
- }
- }
- // Stack multiple vertical stacks in alternating honeycomb pattern
- module multi_stack(num_stacks, r, h, d, n, slant = 0, fill_base = false, plate_thickness = 2) {
- x_spacing = r + r / 2; // Horizontal offset between columns
- y_offset_shift = r - d / 2; // Vertical offset for staggered rows
- echo ("y-offset:")
- echo (y_offset_shift)
- // Create the entire honeycomb structure
- difference() {
- union() {
- for (i = [0:num_stacks - 1]) {
- x_off = i * x_spacing;
- // ?? Reversed: stack 0 now gets Y offset (i.e., is a 'half')
- y_off = (i % 2 == 1) ? 0 : y_offset_shift;
- // ?? Flip is_first_row logic to match
- vertical_stack(r, h, d, n, x_off, y_off, slant, fill_base, plate_thickness, i % 2 == 1, i);
- }
- }
- // X-cut stays the same
- if (perform_x_cut) {
- cut_box_width = num_stacks * x_spacing + r * 2;
- middle_stack = floor(num_stacks / 2);
- middle_x = middle_stack * x_spacing;
- translate([middle_x - r * 5, -r * 2, -0.1])
- cube([x_cut_width * 20, r * 1.35, x_cut_depth + 0.2]);
- }
- }
- }
- // --- Render the scene ---
- multi_stack(5, radius, height, thickness, stack_height, slant_rad, true, base_plate_thickness);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement