Files
3d-printer-models/hex-nespresso-insert/hex-nespresso-insert-variant.scad

120 lines
4.1 KiB
OpenSCAD

/* https://github.com/BelfrySCAD/BOSL2 */
include <BOSL2/std.scad>
$fn = 150;
pattern_width = 375; // Total width of pattern (mm)
pattern_height = 220; // Total height of pattern (mm)
pattern_thickness = 4; // Thickness of the entire pattern (mm)
ring_inner_diameter = 38; // Inner diameter of rings (mm)
ring_width = 2; // Width of ring walls (mm)
line_width = 2; // Width of connecting lines (mm)
perimeter_width = 4; // Width of outer perimeter walls (mm)
hex_spacing = 45; // Distance between hex centers (mm)
ring_outer_radius = (ring_inner_diameter + 2 * ring_width) / 2;
module hex_ring_pattern_2d() {
union() {
// Create outer rectangular perimeter using difference
difference() {
square([pattern_width, pattern_height], center=true);
square([pattern_width - 2*perimeter_width, pattern_height - 2*perimeter_width], center=true);
}
// Get all valid ring positions
positions = get_hex_positions();
// Create rings at all valid positions
for (pos = positions) {
translate(pos) ring(r=ring_inner_diameter/2, ring_width=ring_width);
}
// Create all connections
create_connections(positions);
}
}
// Function to get all valid hexagonal ring positions
function get_hex_positions() = [
for (row = [-8:8])
for (col = [-10:10]) let(
x_pos = col * hex_spacing + (row % 2) * hex_spacing/2,
y_pos = row * hex_spacing * sin(60),
pos = [x_pos, y_pos]
)
if (abs(x_pos) + ring_outer_radius <= pattern_width/2 &&
abs(y_pos) + ring_outer_radius <= pattern_height/2)
pos
];
// Create all connections (hex grid + perimeter)
module create_connections(positions) {
if (len(positions) > 1) {
// Hex grid connections
for (i = [0:len(positions)-2]) {
for (j = [i+1:len(positions)-1]) {
pos1 = positions[i];
pos2 = positions[j];
dist = norm(pos2 - pos1);
// Connect adjacent rings
if (dist > hex_spacing * 0.9 && dist < hex_spacing * 1.1) {
connect_rings(pos1, pos2);
}
}
}
// Perimeter connections
for (pos = positions) {
connect_to_edges(pos);
}
}
}
// Connect two rings with a line
module connect_rings(pos1, pos2) {
angle = atan2(pos2[1] - pos1[1], pos2[0] - pos1[0]);
start_point = pos1 + [cos(angle), sin(angle)] * (ring_inner_diameter/2);
end_point = pos2 - [cos(angle), sin(angle)] * (ring_inner_diameter/2);
move((start_point + end_point)/2)
rot(angle)
square([norm(end_point - start_point), line_width], center=true);
}
// Connect a ring to nearby perimeter edges
module connect_to_edges(pos) {
x = pos[0]; y = pos[1];
half_w = pattern_width/2; half_h = pattern_height/2;
// Connect to edges if ring is within 1.5 spacing units
if (x <= -half_w + hex_spacing * 1.5 && abs(y) <= half_h - perimeter_width) {
start = [x - ring_inner_diameter/2, y];
end = [-half_w, y];
move((start + end)/2) square([norm(end - start), line_width], center=true);
}
if (x >= half_w - hex_spacing * 1.5 && abs(y) <= half_h - perimeter_width) {
start = [x + ring_inner_diameter/2, y];
end = [half_w, y];
move((start + end)/2) square([norm(end - start), line_width], center=true);
}
if (y >= half_h - hex_spacing * 1.5 && abs(x) <= half_w - perimeter_width) {
start = [x, y + ring_inner_diameter/2];
end = [x, half_h];
move((start + end)/2) rot(90) square([norm(end - start), line_width], center=true);
}
if (y <= -half_h + hex_spacing * 1.5 && abs(x) <= half_w - perimeter_width) {
start = [x, y - ring_inner_diameter/2];
end = [x, -half_h];
move((start + end)/2) rot(90) square([norm(end - start), line_width], center=true);
}
}
linear_extrude(pattern_thickness) {
hex_ring_pattern_2d();
}