$fn = 64; // --- Parameters --- rail_length = 800; rail_height = 40; rail_depth = 15; // Dovetail dimensions dovetail_front_width = 15; dovetail_back_width = 25; dovetail_depth = 8; // Mounting hole dimensions num_holes = 5; hole_margin = 50; screw_dia = 5; head_dia = 10; module dovetail_rail() { difference() { // Main rail body with dovetail profile rotate([0, 90, 0]) linear_extrude(height = rail_length) polygon(points=[ [0, 0], [0, rail_height], [-rail_depth, rail_height], [-rail_depth, (rail_height + dovetail_front_width)/2], [-(rail_depth - dovetail_depth), (rail_height + dovetail_back_width)/2], [-(rail_depth - dovetail_depth), (rail_height - dovetail_back_width)/2], [-rail_depth, (rail_height - dovetail_front_width)/2], [-rail_depth, 0] ]); // Countersunk mounting holes hole_interval = (num_holes > 1) ? (rail_length - 2 * hole_margin) / (num_holes - 1) : 0; for(i = [0 : num_holes - 1]) { x_pos = hole_margin + i * hole_interval; y_pos = rail_height / 2; z_dovetail_bottom = rail_depth - dovetail_depth; cs_height = (head_dia - screw_dia) / 2; translate([x_pos, y_pos, 0]) { // Screw shaft translate([0, 0, -1]) cylinder(d=screw_dia, h=rail_depth + 2); // Countersink translate([0, 0, z_dovetail_bottom - cs_height]) cylinder(d1=screw_dia, d2=head_dia, h=cs_height + 0.01); // Clearance for screw head above countersink translate([0, 0, z_dovetail_bottom]) cylinder(d=head_dia, h=rail_depth); } } } } // Render the model dovetail_rail();