/* [Gear Mesh Parameters] */ // Module of the gear pair (mm) gear_module = 2.0; // [1.0:0.1:5.0] // Tooth count of pinion (Gear 1) teeth_gear1 = 20; // [12:1:35] // Tooth count of wheel (Gear 2) teeth_gear2 = 40; // [20:1:80] // Pressure angle (degrees) pressure_angle = 20; // [14.5, 20, 25] // Face width (gear thickness, mm) face_width = 8.0; // [4:1:30] // Bore diameter for both gears (mm) bore_diameter = 6.0; // [3:0.5:20] // Keyway width (mm) keyway_width = 2.0; // [1:0.5:6] // Keyway depth into hub (mm) keyway_depth = 1.0; // [0.5:0.1:4] // Backlash allowance (mm) backlash = 0.15; // [0.0:0.05:0.6] // Rotation angle to demonstrate meshing (degrees) mesh_rotation = 0; // [0:1:360] /* [Visual & Details] */ // Gear 1 color gear1_color = "RoyalBlue"; // Gear 2 color gear2_color = "DarkOrange"; // Add lightening holes to the larger gear lightening_holes = true; // Number of lightening holes in Gear 2 hole_count = 5; // [3:1:8] // Diameter of lightening holes (mm) hole_diameter = 11.0; // [6:1:20] // Show mounting shafts show_shafts = false; // Show pitch circle lines (wireframe indicators) show_pitch_circles = false; /* [Calculated Geometry] */ pitch_radius_1 = gear_module * teeth_gear1 / 2; // 20 mm pitch_radius_2 = gear_module * teeth_gear2 / 2; // 40 mm center_distance = pitch_radius_1 + pitch_radius_2; // 60 mm // Position gears so the pitch point of contact is at [0, 0, 0] gear1_pos = [-pitch_radius_1, 0, 0]; gear2_pos = [ pitch_radius_2, 0, 0]; // Angular alignment: // Gear 1 has tooth centered along +X (pointing to Gear 2) // Gear 2 has tooth space centered along -X (pointing to Gear 1) -> half-pitch offset = 180 / teeth_gear2 gear1_angle = mesh_rotation; gear2_angle = (180 / teeth_gear2) - mesh_rotation * (teeth_gear1 / teeth_gear2); // Math helper functions function deg2rad(a) = a * PI / 180; function rad2deg(a) = a * 180 / PI; // Involute function: returns involute angle in degrees function inv_deg(alpha) = (tan(alpha) - deg2rad(alpha)) * 180 / PI; // Pressure angle at radius r given base radius rb function alpha_at(r, rb) = acos(max(min(rb / r, 1.0), -1.0)); // Half tooth angular thickness at radius r in degrees function tooth_half_angle(r, rb, rp, N, inv_alpha0, bl, m_val) = let( s_p = (PI * m_val / 2) - (bl / 2), psi_p = (s_p / (2 * rp)) * 180 / PI, inv_r = (r > rb) ? inv_deg(alpha_at(r, rb)) : 0 ) psi_p + inv_alpha0 - inv_r; // 2D rotation helper function rot2d(p, deg) = [ p[0] * cos(deg) - p[1] * sin(deg), p[0] * sin(deg) + p[1] * cos(deg) ]; // Generate 2D boundary polygon for an involute spur gear function spur_gear_2d_points(N, m_val, pa, bl, steps=6) = let( rp = m_val * N / 2, rb = rp * cos(pa), ra = rp + m_val, rf = rp - 1.25 * m_val, r_start = max(rb, rf), inv_a0 = inv_deg(pa), psi_start = tooth_half_angle(r_start, rb, rp, N, inv_a0, bl, m_val), pitch_deg = 360 / N, // Left involute flank: radius goes from r_start up to tip ra left_flank = [ for (i = [0 : steps]) let( r = r_start + i * (ra - r_start) / steps, psi = tooth_half_angle(r, rb, rp, N, inv_a0, bl, m_val) ) [r * cos(-psi), r * sin(-psi)] ], // Tip arc point along centerline tip_arc = [ [ra, 0] ], // Right involute flank: radius goes from tip ra down to r_start right_flank = [ for (i = [steps : -1 : 0]) let( r = r_start + i * (ra - r_start) / steps, psi = tooth_half_angle(r, rb, rp, N, inv_a0, bl, m_val) ) [r * cos(psi), r * sin(psi)] ], // Straight radial root flanks if root circle is below base circle left_root_pt = (rf < rb) ? [ [rf * cos(-psi_start), rf * sin(-psi_start)] ] : [], right_root_pt = (rf < rb) ? [ [rf * cos(psi_start), rf * sin(psi_start)] ] : [], // Root space arc between this tooth and adjacent tooth root_arc = [ for (j = [1 : 3]) let(ang = psi_start + j * (pitch_deg - 2 * psi_start) / 4) [rf * cos(ang), rf * sin(ang)] ], // Full single-pitch contour tooth_contour = concat( left_root_pt, left_flank, tip_arc, right_flank, right_root_pt, root_arc ) ) [ for (k = [0 : N - 1]) for (pt = tooth_contour) rot2d(pt, k * pitch_deg) ]; // Individual spur gear module module spur_gear( teeth, mod_val, pa, width, bore_d, key_w, key_d, bl, has_holes = false, n_holes = 4, hole_d = 10 ) { rp = mod_val * teeth / 2; rf = rp - 1.25 * mod_val; hub_radius = bore_d / 2 + key_d + 3.0; rim_inner_radius = rf - 3.5; hole_placement_radius = (hub_radius + rim_inner_radius) / 2; difference() { // Main gear tooth body linear_extrude(height = width, center = true, convexity = 12) polygon(points = spur_gear_2d_points(teeth, mod_val, pa, bl)); // Center shaft bore cylinder(d = bore_d, h = width + 2, center = true, $fn = 48); // Standard rectangular keyway slot translate([-key_w / 2, 0, -(width + 2) / 2]) cube([key_w, bore_d / 2 + key_d, width + 2]); // Lightening holes (for larger gear) if (has_holes && rim_inner_radius > hub_radius + hole_d) { for (h = [0 : n_holes - 1]) { rotate([0, 0, h * (360 / n_holes)]) translate([hole_placement_radius, 0, 0]) cylinder(d = hole_d, h = width + 2, center = true, $fn = 36); } } } } // Pitch circle reference ring for verification module pitch_circle_ring(r, width) { color("DimGray", 0.4) rotate_extrude($fn = 96) translate([r, 0, 0]) circle(r = 0.3, $fn = 16); } // Assemble the meshing gear pair module gear_assembly() { // Gear 1 (Pinion - 20T) translate(gear1_pos) rotate([0, 0, gear1_angle]) { color(gear1_color) spur_gear( teeth = teeth_gear1, mod_val = gear_module, pa = pressure_angle, width = face_width, bore_d = bore_diameter, key_w = keyway_width, key_d = keyway_depth, bl = backlash, has_holes = false ); if (show_pitch_circles) { pitch_circle_ring(pitch_radius_1, face_width); } } // Gear 2 (Wheel - 40T) translate(gear2_pos) rotate([0, 0, gear2_angle]) { color(gear2_color) spur_gear( teeth = teeth_gear2, mod_val = gear_module, pa = pressure_angle, width = face_width, bore_d = bore_diameter, key_w = keyway_width, key_d = keyway_depth, bl = backlash, has_holes = lightening_holes, n_holes = hole_count, hole_d = hole_diameter ); if (show_pitch_circles) { pitch_circle_ring(pitch_radius_2, face_width); } } // Optional mounting shafts and test base if (show_shafts) { shaft_length = face_width + 12; base_thickness = 4; base_width = center_distance + 35; base_height = max(pitch_radius_1, pitch_radius_2) * 2 + 15; // Baseplate color("SlateGray") translate([gear1_pos[0] + center_distance / 2, 0, -face_width / 2 - base_thickness / 2]) cube([base_width, base_height, base_thickness], center = true); // Shaft 1 color("Silver") translate(gear1_pos) cylinder(d = bore_diameter, h = shaft_length, center = true, $fn = 36); // Shaft 2 color("Silver") translate(gear2_pos) cylinder(d = bore_diameter, h = shaft_length, center = true, $fn = 36); } } // Render the assembly gear_assembly();