// Hexagon Module Library // Various hexagon creation functions for OpenSCAD // === M3 Nut Hexagon Parameters === m3_nut_width = 5.5; // Distance across flats (M3 nut standard) m3_nut_height = 2.4; // Standard M3 nut thickness m3_nut_diameter = 6.35; // Distance across corners (calculated from width) // Hexagon module - creates a 2D hexagon // Parameters: // width: distance across flats (flat-to-flat width) // method: "circle" or "polygon" - different drawing methods module hexagon_2d(width, method = "circle") { if (method == "circle") { // Method 1: Using circle with 6 sides // The radius needed for flat-to-flat distance radius = width / (2 * cos(30)); circle(r = radius, $fn = 6); } else { // Method 2: Using polygon with calculated points radius = width / (2 * cos(30)); points = [ for (i = [0:5]) [radius * cos(i * 60), radius * sin(i * 60)] ]; polygon(points); } } // 3D Hexagon module (extruded) // Parameters: // width: distance across flats // height: extrusion height // method: "circle" or "polygon" module hexagon_3d(width, height, method = "circle") { linear_extrude(height = height) hexagon_2d(width, method); } // M3 Nut specific modules module m3_nut_2d() { hexagon_2d(m3_nut_width); } module m3_nut_3d() { hexagon_3d(m3_nut_width, m3_nut_height); } // M3 Nut with hole (complete nut) module m3_nut_with_hole() { difference() { hexagon_3d(m3_nut_width, m3_nut_height); // M3 hole (3mm diameter, slightly larger for clearance) translate([0, 0, -0.1]) cylinder(h = m3_nut_height + 0.2, d = 3.2, $fn = 32); } } // Example usage (uncomment to test): //hexagon_2d(m3_nut_width); //translate([10, 0]) m3_nut_2d(); //translate([0, 0, 5]) m3_nut_3d(); //translate([10, 0, 5]) m3_nut_with_hole();