This commit is contained in:
dingfeng.wong
2025-07-22 00:28:15 +08:00
parent 6b6ae9911a
commit 49a7d3f283
2 changed files with 70 additions and 6 deletions
+63
View File
@@ -0,0 +1,63 @@
// 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();
+7 -6
View File
@@ -63,11 +63,12 @@ module trapezium_with_rectangle_2d(
//translate([30, 0]) rectangle_2d(width = 8, height = 5);
// Combined shape:
rect_height_val = 1.7;
trapezium_with_rectangle_2d(
trap_base_width = 10.3,
trap_top_width = 6.3,
trap_height = 4.3,
trap_base_width = 10.95,
trap_top_width = 5.5,
trap_height = 4.0,
rect_width = 6.3,
rect_height = 1.7,
rect_offset = -0.85 // Half of rectangle height to center it at base edge
);
rect_height = rect_height_val,
rect_offset = -rect_height_val/2 // Half of rectangle height to center it at base edge
);